[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

newbie:: issue while downloading binary from HTTP

mataal

8/2/2006 5:33:00 AM

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

2 Answers

Daniel Harple

8/2/2006 5:46:00 AM

0

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


mataal

8/2/2006 5:53:00 AM

0

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

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