utils/curl: support disabling partial downloads in curl_download
This commit is contained in:
parent
2970d2e4f9
commit
997ba42a4b
@ -54,10 +54,11 @@ def curl(*args, secrets: [], **options)
|
|||||||
secrets: secrets
|
secrets: secrets
|
||||||
end
|
end
|
||||||
|
|
||||||
def curl_download(*args, to: nil, **options)
|
def curl_download(*args, to: nil, partial: true, **options)
|
||||||
destination = Pathname(to)
|
destination = Pathname(to)
|
||||||
destination.dirname.mkpath
|
destination.dirname.mkpath
|
||||||
|
|
||||||
|
if partial
|
||||||
range_stdout = curl_output("--location", "--range", "0-1",
|
range_stdout = curl_output("--location", "--range", "0-1",
|
||||||
"--dump-header", "-",
|
"--dump-header", "-",
|
||||||
"--write-out", "%\{http_code}",
|
"--write-out", "%\{http_code}",
|
||||||
@ -70,6 +71,9 @@ def curl_download(*args, to: nil, **options)
|
|||||||
destination.size == %r{^.*Content-Range: bytes \d+-\d+/(\d+)\r\n.*$}m.match(headers)&.[](1)&.to_i
|
destination.size == %r{^.*Content-Range: bytes \d+-\d+/(\d+)\r\n.*$}m.match(headers)&.[](1)&.to_i
|
||||||
return # We've already downloaded all the bytes
|
return # We've already downloaded all the bytes
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
supports_partial_download = false
|
||||||
|
end
|
||||||
|
|
||||||
continue_at = if destination.exist? && supports_partial_download
|
continue_at = if destination.exist? && supports_partial_download
|
||||||
"-"
|
"-"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user