net/http and binary files

  • Thread starter Constantin Gavrilescu
  • Start date
C

Constantin Gavrilescu

I'm using the code from the example
http://www.ruby-doc.org/stdlib/libdoc/net/http/rdoc/index.html for the
http/net library:

File.open('result.txt', 'w') {|f|
http.get('/~foo/') do |str|
f.write str
end
}


This works fine for html files. But for binary files the result is a
corrupted file.
I've run this in the console:et('/crocodil2/adrian.mp3') {|str|f.write str}}}
=> #<Net::HTTPOK 200 OK readbody=true>

The mp3 files is corrupted. It does not seem to be base64 encoded...
help please.
 
C

Clifford Heath

Constantin said:
I'm using the code from the example
http://www.ruby-doc.org/stdlib/libdoc/net/http/rdoc/index.html
This works fine for html files. But for binary files the result is a
corrupted file.
I've run this in the console:
et('/crocodil2/adrian.mp3') {|str|f.write str}}}
=> #<Net::HTTPOK 200 OK readbody=true>
The mp3 files is corrupted. It does not seem to be base64 encoded...
help please.

The example works on *nix systems, but on Windoze, you must write the
file in binary mode: File.open('result.mp3', 'wb')

Clifford Heath.
 
C

Constantin Gavrilescu

Clifford said:
The example works on *nix systems, but on Windoze, you must write the
file in binary mode: File.open('result.mp3', 'wb')


Wonderful. Forgot about that... Thank you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top