From: James Gray Date: 2008-09-19T11:47:11+09:00 Subject: [ruby-core:18717] Re: Request: File.binread (Or File.read_binary) On Sep 18, 2008, at 6:56 PM, Eric Hodel wrote: > On Sep 17, 2008, at 09:48 AM, Gregory Brown wrote: >> On Wed, Sep 17, 2008 at 12:35 PM, Yukihiro Matsumoto > > wrote: >>> |class File >>> | def self.read_binary(file_name) >>> | File.open(file_name, "rb:BINARY") { |f| f.read } >>> | end >>> |end >>> >>> Defines a exact behavior. Does it take length or offset option, as >>> File.read does? >> >> Oh, sorry for not being specific: So long as it makes sense to do so, >> this should behave as close to how File.read does as possible, so it >> should be able to take those options. > > I have a method in RubyGems to do the same (Gem.read_binary) and I > only use it for reading whole files (no length, offset options). That's a good idea. Reading by a byte count less than the full amount is pretty dangerous if you have any kind of m17n support. I'm still struggling with this issue in the CSV code. I read ahead to find your line endings, but when I do it can cause error. The reason is that, with some encodings, I may read a partial character. Then if I later hit that String with a Regexp, Ruby blows up on the malformed data. James Edward Gray II