[phobos] std.stdio: text and binary modes on Windows
Andrei Alexandrescu
andrei at erdani.com
Thu Aug 26 22:00:56 PDT 2010
Hi Shin, all,
I picked the message below from my email backlog. Was a solution found
to this? My understanding is that the mode text/binary of a file is
selected during opening, so there's little you can do about it.
We could detect whether the file is incapable of binary data by calling
isatty() and refusing to print binary data if that is true. This is what
e.g. gzip does on some Linuxen.
Andrei
On 5/27/10 14:08 PDT, Shin Fujishiro wrote:
> 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
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
More information about the phobos
mailing list