tags:

views:

1347

answers:

5

My code:

require 'rio'
rio('nice.jpg') < rio('http://farm4.static.flickr.com/3134/3160515898_59354c9733.jpg?v=0')

But the image downloaded is currupted. Whtat is wrong with this solution?

+1  A: 

It works for me. Are you on windows? It might be because the file isn't being opened with the binary flag.

pjb3
Yes, I am on Vista. It looks like 'rio' converted all LF (0x0A) into CRLF (0x0D 0x0A). Also, I noticied it does this in case of simple files: rio('unix.txt') > rio('win.txt'). Are you on Linux?
alex2k8
+1  A: 

pjb3 is correct. You must call binmode on the left-hand term:

rio('nice.jpg').binmode < rio('http://...')

If this still does not work (notably, it may happen for large jpeg files, i.e. rio uses an intermediate temp file when retrieving from the URL you have provided), then apply the binmode modifier to both terms:

rio('nice.jpg').binmode < rio('http://...').binmode
vladr
I tryed both, but still get equally corruped images. All 0x0A replaced with 0x0D 0x0A. May be a bug?
alex2k8
A: 

I tried above code on WinXP, it did not work either, any suggestion? Thanks

A: 

I had similar problems downloading images on Linux, I found that this worked for me:

rio(source_url).binmode > rio(filename)

simianarmy
A: 

I guess this is a bug. On windows all 0x0A replaced with 0x0D 0x0A. And as so, it makes sence that properly used (with .binmode) it works on Linux.

alex2k8