P
Patrick Plattes
Hello people
,
i have a question about downloading files. I want to download a file and
print out how many bytes are downloaded. That's important to me, because
i want to have a progress bar later.
The problem is that it looks like my code downloads the whole file and
after that it executes the while loop - this behavior is useless for me.
does anyone know how to fix it or knows a better solution?
Thanks,
Patrick
A working example:
require 'open-uri'
FILE_BUFFER_SIZE = 65536
filename = "dailysourcecode-39523-11-30-2006.mp3"
url =
"http://m-uk.podshow.com/media/21/episodes/39523/dailysourcecode-39523-11-30-2006.mp3"
open(url, "r") do |input|
open(filename, "w") do |output|
bytes_downloaded = 0
while (buffer = input.read(FILE_BUFFER_SIZE))
output.write(buffer)
bytes_downloaded += FILE_BUFFER_SIZE
puts bytes_downloaded
end
end
end
i have a question about downloading files. I want to download a file and
print out how many bytes are downloaded. That's important to me, because
i want to have a progress bar later.
The problem is that it looks like my code downloads the whole file and
after that it executes the while loop - this behavior is useless for me.
does anyone know how to fix it or knows a better solution?
Thanks,
Patrick
A working example:
require 'open-uri'
FILE_BUFFER_SIZE = 65536
filename = "dailysourcecode-39523-11-30-2006.mp3"
url =
"http://m-uk.podshow.com/media/21/episodes/39523/dailysourcecode-39523-11-30-2006.mp3"
open(url, "r") do |input|
open(filename, "w") do |output|
bytes_downloaded = 0
while (buffer = input.read(FILE_BUFFER_SIZE))
output.write(buffer)
bytes_downloaded += FILE_BUFFER_SIZE
puts bytes_downloaded
end
end
end