From: Carl Youngblood Date: 2003-12-18T10:31:55+09:00 Subject: Re: Binary-safe file IO Is this only applicable to Windows then? I happened to be on Windows at the time, but I'm developing this application cross-platform and testing it on Windows, linux and OS X. Will this code still work on other platforms? Thanks, Carl Hal Fulton wrote: > Carl Youngblood wrote: > >> Hi, I'm trying to embed a binary file inside a ruby script but I'm >> having trouble. To test it out, I wrote a simple script that will >> take a binary file and encode it to base64 and then decode it again >> and write out the result. Here it is: >> >> require 'base64' >> bindata = File.open('oldbinfile').read >> File.open('newbinfile', 'w') do |f| >> f.write decode64(encode64(bindata)) >> end >> >> When I run this, newbinfile is not identical to oldbinfile anymore. >> Anyone know what I'm doing wrong? I'm assuming that the File IO >> functions are not binary safe, but what should I use instead? > > > Are you on Windows? If so, 'wb' as a mode might help (binary mode). > > Hal > > >