From: danielcavanagh@... Date: 2008-12-22T10:29:16+09:00 Subject: [ruby-core:20772] Re: Working with binary strings in Ruby 1.9? > On Sun, 21 Dec 2008 06:43:32 +1100, James Gray > wrote: > >> On Dec 20, 2008, at 12:49 PM, Hadmut Danisch wrote: >>> The code I am working on is parsing files with binary content (such as pictures, machine code, etc.). With 1.8, I could easily use >>> * File.open{|f| f.read} to read the contents, >> In 1.9 use: >> File.binread(���) > > Alternatively you can specify 'encoding: "BINARY"' eg: > > File.open(, encoding: "BINARY") {|f| f.read} > or shorter > File.read(, encoding: "BINARY") > > This will return the enire contents of the file in a "BINARY" (ASCII-8BIT) > string which can be accessed as in 1.8. and should be as efficient. The only difference (as already mentioned) is that a single index (eg: data[10]) now returns a single byte string, not a number. and a nicer way of getting the byte value of this single character string is data[10].ord