# Newbie:: issue while downloading binary from HTTP

**URL:** <https://www.ruby-forum.com/t/newbie-issue-while-downloading-binary-from-http/101060>\
**Category:** Ruby\
**Created:** [August 3, 2006, 12:05pm UTC](https://www.ruby-forum.com/t/newbie-issue-while-downloading-binary-from-http/101060 "2006-08-03T12:05:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [August 3, 2006, 12:05pm UTC](https://www.ruby-forum.com/t/newbie-issue-while-downloading-binary-from-http/101060/1 "2006-08-03T12:05:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [August 3, 2006, 12:06pm UTC](https://www.ruby-forum.com/t/newbie-issue-while-downloading-binary-from-http/101060/2 "2006-08-03T12:06:08Z")

</div>

On Aug 2, 2006, at 1:35 AM, removed\_email\_address@domain.invalid 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

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [August 3, 2006, 12:06pm UTC](https://www.ruby-forum.com/t/newbie-issue-while-downloading-binary-from-http/101060/3 "2006-08-03T12:06:29Z")

</div>

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
