From: Michael Selig Date: 2008-12-21T10:03:14+09:00 Subject: [ruby-core:20740] 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. Cheers Mike