# MP3 download

**URL:** <https://www.ruby-forum.com/t/mp3-download/94081>\
**Category:** Ruby\
**Created:** [April 20, 2006, 3:06am UTC](https://www.ruby-forum.com/t/mp3-download/94081 "2006-04-20T03:06:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xiaofeng\_Q](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/ba8739/32.png) [@Xiaofeng\_Q](https://www.ruby-forum.com/u/Xiaofeng_Q)\
**Post date:** [April 20, 2006, 3:06am UTC](https://www.ruby-forum.com/t/mp3-download/94081/1 "2006-04-20T03:06:33Z")

</div>

i tried on my first ruby program, downloading a MP3 file:

require ‘net/http’  
req,body = Net::HTTP::get\_response(’_._.net’,’/…/1.mp3’)  
f = File.new(“1.mp3”, “w”)  
f.write body

it does work !  
but the file size is 5479K about 30K more than downloading by IE.  
And  
it sounds terrible when i replay the MP3.  
Does any one kown the reason?

xiaofeng

---

<div class="post-metadata">

**Author:** ![Xiaofeng\_Q](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/ba8739/32.png) [@Xiaofeng\_Q](https://www.ruby-forum.com/u/Xiaofeng_Q)\
**Post date:** [April 20, 2006, 3:15am UTC](https://www.ruby-forum.com/t/mp3-download/94081/2 "2006-04-20T03:15:44Z")

</div>

On Apr 19, 2006, at 9:04 PM, Xiaofeng Q. wrote:

> require ‘net/http’  
> req,body = Net::HTTP::get\_response(’_._.net’,’/…/1.mp3’)  
> f = File.new(“1.mp3”, “w”)  
> f.write body

Judging by the fact you mentioned windows, I’m going to suggest you  
try this:

f = File.new(“1.mp3”, “wb”) # Open file in binary mode

---

<div class="post-metadata">

**Author:** ![Xiaofeng\_Q](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/ba8739/32.png) [@Xiaofeng\_Q](https://www.ruby-forum.com/u/Xiaofeng_Q)\
**Post date:** [April 20, 2006, 3:18am UTC](https://www.ruby-forum.com/t/mp3-download/94081/3 "2006-04-20T03:18:49Z")

</div>

> but the file size is 5479K about 30K more than downloading by IE.  
> And  
> it sounds terrible when i replay the MP3.  
> Does any one kown the reason?
> 
> xiaofeng

Hi,

If you are under windows, you should try the “binary” mode:

f = File.new(“1.mp3”, “wb”)

or else the file might be corrupted: \n will turn into \r\n (or \n\r, I  
can  
never remember).

Hope this helps,

Guillaume

---

<div class="post-metadata">

**Author:** ![Xiaofeng\_Q](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/ba8739/32.png) [@Xiaofeng\_Q](https://www.ruby-forum.com/u/Xiaofeng_Q)\
**Post date:** [April 20, 2006, 3:46am UTC](https://www.ruby-forum.com/t/mp3-download/94081/4 "2006-04-20T03:46:07Z")

</div>

Hiï¼?

oh, yes, File.new(“1.mp3”,“wb”), it’s OK now.  
thanks.  
i like ruby and the ruby community. Ruby maks programing easy and fun.

xiaofeng

---

<div class="post-metadata">

**Author:** ![Xiaofeng\_Q](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/ba8739/32.png) [@Xiaofeng\_Q](https://www.ruby-forum.com/u/Xiaofeng_Q)\
**Post date:** [April 20, 2006, 5:05am UTC](https://www.ruby-forum.com/t/mp3-download/94081/5 "2006-04-20T05:05:24Z")

</div>

On 4/19/06, Xiaofeng Q. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> i like ruby and the ruby community. Ruby maks programing easy and fun.

That is always something good to hear! 🙂
