On Tue, 09 Sep 2008 13:13:00 +1000, Tanaka Akira <akr / fsij.org> wrote:

> In article <9888DBB2-0FE8-4C5C-8EF0-02D7C30157FA / pragprog.com>,
>   Dave Thomas <dave / pragprog.com> writes:
>
>> But we also quite often want to work the the whole file. I believe
>> Matz uses the example of something like
>>
>> data = File.open("dave.gif", "b:ASCII-8BIT").read
>> fail unless data =~ /^GIF/
>
> "rb:ASCII-8BIT"?  It works.
>
> Just "rb" also works for /^GIF/.
"rb" by itself only works if your default encoding is ascii compatible I  
believe. Otherwise you'll get an error from ruby saying "incomptible  
encoding".
The point is that when reading a binary file format, you probably mean to  
use 8 bit bytes when you process it, not whatever your default encoding  
happens to be, which may very well give obscure errors complaining about  
invalid encoding.

Mike