Skip to content

Commit

Permalink
Correct multipart download
Browse files Browse the repository at this point in the history
  • Loading branch information
gbraad committed Jan 22, 2025
1 parent 93d7ecc commit 7c6d6bf
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions zsh/.zshrc.d/machine.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,35 @@ download() {
final_output_file=$2

# Check if the input contains a range pattern
if [[ $input =~ \[([0-9]+)-([0-9]+)\] ]]; then
# Extract the base URL and the range
base_url="${input%%_part*}"
start_part=${BASH_REMATCH[1]}
end_part=${BASH_REMATCH[2]}
if [[ $input == *\[*\]* ]]; then
base_url="${input%\[*}"
range="${input##*\[}"
range="${range%\]*}"
start_part="${range%-*}"
end_part="${range#*-}"

if [[ -z "$start_part" || -z "$end_part" ]]; then
echo "Invalid range start or end"
return 1
fi

# Remove any existing final output file to avoid appending to old data
rm -f "$final_output_file"

# Loop through the range and download each part, appending to the final file
for i in $(seq $start_part $end_part); do
part_url="${base_url}_part${i}"
part_url="${base_url}${i}"
echo "Downloading $part_url and appending to $final_output_file..."
curl -s -L "$part_url" -o - >> $final_output_file
curl -s -L "$part_url" -o - >> "$final_output_file"
if [[ $? -ne 0 ]]; then
echo "Error downloading $part_url. Exiting."
return 1
fi
done
echo "Download completed and concatenated into $final_output_file."
else

echo "nope"

# Direct download
url=$input
echo "Downloading $url to $final_output_file..."
Expand Down

0 comments on commit 7c6d6bf

Please sign in to comment.