Download resume with NET::HTTP

A

Alex Dj

I'm wondering is there any way to do interrupt file download and then
resume it from the same spot?
The way I download file:

Net::HTTP.start("server.com") { |http|
response = http.request_get('/some/path') {|response|
file_length = response['Content-Length']
File.open('video.avi', 'w') {|f|
response.read_body do |str| # read body now
puts str.length
f.write str
end
}
}
}

I'm not using open-url as I found that open() method first downloads
whole file and then starts to write it. Not for me....

Cheers Alex
 
M

Marcelo

Net::HTTP.start("server.com") { |http|
response = http.request_get('/some/path') {|response|

create your request by hand:

req = Net::HTTP::Get.new(path)
req.range = ...

In HTTP 1.1 range has the form "[lower]-[upper]", so "[lower]-" is
valid. I'm not sure what range= takes, you get to try it :)

Marcelo
 
A

Alex Dj

Thanks Marcelo,
In HTTP 1.1 range has the form "[lower]-[upper]", so "[lower]-" is
valid. I'm not sure what range= takes, you get to try it :)

I found that its "Range: bytes=10000-", something like this. I wonder if
I can use this header to download the same file from different mirrors
i.e. have several
req = Net::HTTP::Get.new(path)
but with different ranges and write them to the same file with random
access. Would it be a right technique for this idea?

Thanks Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top