Newbie:: issue while downloading binary from HTTP

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

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

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

-- Daniel

···

On Aug 2, 2006, at 1:35 AM, mataal@gmail.com wrote:

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

Hi Daniel,

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

Had missed out the binary modifier when reading the docs... :frowning:

Regards,
Ashish

Daniel Harple wrote:

···

On Aug 2, 2006, at 1:35 AM, mataal@gmail.com wrote:

> 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