[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

HTTPClient download binary file

Aa Aa

5/2/2008 8:22:00 PM

Hi,

I'm writing a simple program which downloads a resource from the
internet. When I save a file to disk, it always ends up a few bytes
larger than it should be and is thus recognized as a damaged file.

The code I'm using:

require 'httpclient'
client = HTTPClient.new(nil)
my_file = File.new("x:\\temp\\logo2.gif", "w")
puts
my_file.write(client.get_content("http://www.google.com/intl/en_ALL/images/logo...))

puts actually prints the correct size 8558, but when I check the size on
disk it is 8617 bytes.
I've also downloaded the file with firefox to check if the increased
file size is due to the filesystem i'm using. When downloaded which
firefox the file is 8558 bytes on disk, so something must be wrong in my
code.

Regards,
DarnDao
--
Posted via http://www.ruby-....

2 Answers

Heesob Park

5/3/2008 12:31:00 AM

0

Hi,

Aa Aa wrote:
> Hi,
>
> I'm writing a simple program which downloads a resource from the
> internet. When I save a file to disk, it always ends up a few bytes
> larger than it should be and is thus recognized as a damaged file.
>
> The code I'm using:
>
> require 'httpclient'
> client = HTTPClient.new(nil)
> my_file = File.new("x:\\temp\\logo2.gif", "w")
try with:
my_file = File.new("x:\\temp\\logo2.gif", "wb")

> puts
> my_file.write(client.get_content("http://www.google.com/intl/en_ALL/images/logo...))
>
> puts actually prints the correct size 8558, but when I check the size on
> disk it is 8617 bytes.
> I've also downloaded the file with firefox to check if the increased
> file size is due to the filesystem i'm using. When downloaded which
> firefox the file is 8558 bytes on disk, so something must be wrong in my
> code.
>
> Regards,
> DarnDao

Regards,
Park Heesob
--
Posted via http://www.ruby-....

Aa Aa

5/3/2008 1:20:00 AM

0

Thanks works ok now. Since the b parameter is DOS\Windows only, would
that throw an exception on a non windows OS?

Heesob Park wrote:
> Hi,
>
> Aa Aa wrote:
>> Hi,
>>
>> I'm writing a simple program which downloads a resource from the
>> internet. When I save a file to disk, it always ends up a few bytes
>> larger than it should be and is thus recognized as a damaged file.
>>
>> The code I'm using:
>>
>> require 'httpclient'
>> client = HTTPClient.new(nil)
>> my_file = File.new("x:\\temp\\logo2.gif", "w")
> try with:
> my_file = File.new("x:\\temp\\logo2.gif", "wb")
--
Posted via http://www.ruby-....