[phobos] std.stdio: text and binary modes on Windows

Shin Fujishiro rsinfu at gmail.com
Thu May 27 14:08:42 PDT 2010


Should File.rawWrite() write data to file in binary mode?  Or should it
just transparently call fwrite() as documented?

I saw a D user who had trouble writing binary data to stdout on Windows.
Every occurrence of 0x0A was translated to 0x0D 0x0A even he used
stdout.rawWrite() -- because stdout was opened in text mode.

Try this:
--------------------
import std.stdio;
void main()
{
    ubyte[] data = [ 0x9, 0xA, 0xB ];
    stdout.rawWrite(data);
}
--------------------
On Windows, this program writes [ 0x9, 0xD, 0xA, 0xB ].

I think File.rawWrite() should always write data in binary mode
regardless of which mode is set.

What do you think?


Shin


More information about the phobos mailing list