From: mathew Date: 2011-09-13T09:22:57+09:00 Subject: [ruby-core:39494] Re: File::BINARY does not behave as advertised On Mon, Sep 12, 2011 at 18:19, Cameron Pope wrote: > It took me a few minutes to twist my brain around what you're saying, > but that makes sense. In my mind I was equating 'Binary' with 'not > transforming any data when writing'. Yeah, the documentation could probably use clarification there, with respect to who the "binary" option is an instruction to (the OS or Ruby or both). > What seems to be happening is that the file's encoding is marked to > the external encoding if both the internal and external encodings are > set. Otherwise it will use the default internal encoding. That makes sense. If the user has expressed an explicit external encoding preference use that; else use the internal encoding preference; else ... >> ...so I think this is the buggy behavior. It looks as if 'w+b' always >> results in ASCII-8BIT external encoding, whatever the value of >> Encoding.default_external. > > I'm not sure that's buggy - it's at least consistent with what the > documentation for IO says: > > ��Binary file mode (may appear with any of the key letters listed above). > �� �� �� | ��Suppresses EOL <-> CRLF conversion on Windows. And > �� �� �� | ��sets external encoding to ASCII-8BIT unless explicitly > �� �� �� | ��specified. OK, if that's the documented behavior (I confess that I didn't look) then it's behaving as documented, so I don't think there's a bug. Presumably that's the intended behavior for back-compatibility reasons. mathew --