From: Phrogz Date: 2007-10-05T00:35:03+09:00 Subject: Re: Binary data, command output, and Ruby On Oct 4, 8:03 am, Phrogz wrote: > > > good = File.open( 'gkhead.jpg', 'rb' ){ |f| f.read } > > > test = `curl -shttp://phrogz.net/tmp/gkhead.jpg` > > > I would hazard a guess that if you took that 'b' off of the File.open, > > you'd get the same bytes `` is returning? > > I doubt it, but will try when I get into work. My understanding was > that (on Windows) opening a file without 'b' "helpfully" converts \n > bytes to \r\n pairs; the 'b' is needed to say "Hey, don't be munging > my data!". > > But like I said, I'll give it a shot. OK, so this has nothing to do with reading files from disk. The crazy thing is that it isn't even deterministic! See the following: C:\>type put_bytes.rb print (0..12000).map{ |i| ((i % 255) + 1).chr }.join $stdout.flush sleep 1 $stdout.flush C:\>type get_bytes.rb p `ruby put_bytes.rb`.length C:\>type multiget.bat @echo off ruby get_bytes.rb ruby get_bytes.rb ruby get_bytes.rb ruby get_bytes.rb ruby get_bytes.rb ruby get_bytes.rb ruby get_bytes.rb ruby get_bytes.rb ruby get_bytes.rb ruby get_bytes.rb ruby get_bytes.rb ruby get_bytes.rb ruby get_bytes.rb ruby get_bytes.rb ruby get_bytes.rb ruby get_bytes.rb ruby get_bytes.rb ruby get_bytes.rb ruby get_bytes.rb ruby get_bytes.rb C:\>multiget.bat 944 696 944 1192 944 919 1192 1192 944 944 1192 1192 944 1167 1192 1192 944 1192 1192 1192 Note that it also does the above with or without the sleep, and with or without the $stdout.flush calls. What is going on here?!