newbie:: issue while downloading binary from HTTP

M

mataal

Hi,

I was writing a small script to download a binary file from a http
site....

require 'net/http'
http = Net::HTTP.new("www.cs.sunysb.edu/~dipanjan", 80,'proxy',8080)
local = File.new("prithibi.mp3", 'w')
http.request_get("/prithibi.mp3") do |response|
response.read_body do |chunk|
#print "writing chunk"
local.write(chunk)
end
end
local.close

Now, the file downloaded by this is different from the original (which
I managed to download using a download accelerator program). Size was
different and on opening it in a binary editor, immediately visible
was an extra byte (0D) at the 734th position.

Any ideas where these extra bytes are coming from? Do it need to
'chomp' my response chunks?

Regards,
Ashish
 
D

Daniel Harple

Any ideas where these extra bytes are coming from? Do it need to
'chomp' my response chunks?

Are you on Windows? You may need to write the file in binary mode:

File.open(..., 'wb') do |f|
...
end

-- Daniel
 
W

warlokk

Hi Daniel,

thanks :)
Was in windows. You got the nail on the head.

Had missed out the binary modifier when reading the docs... :-(

Regards,
Ashish
 

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
474,209
Messages
2,571,088
Members
47,686
Latest member
scamivo

Latest Threads

Top