Forum: Ruby MP3 download

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Xiaofeng Q. (Guest)
on 2006-04-20 05:06
(Received via mailing list)
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
Logan C. (Guest)
on 2006-04-20 05:15
(Received via mailing list)
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
Guillaume Benny (Guest)
on 2006-04-20 05:18
(Received via mailing list)
> 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
Xiaofeng Q. (Guest)
on 2006-04-20 05:46
(Received via mailing list)
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
Gregory B. (Guest)
on 2006-04-20 07:05
(Received via mailing list)
On 4/19/06, Xiaofeng Q. <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! :)
This topic is locked and can not be replied to.