Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Binary IO on stdin/out/err

Moderators: larsivi kris

Posted: 08/31/07 19:16:59 Modified: 08/31/07 19:21:40

Hello!

What's the preferred way of doing binary IO (using byte or ubyte, not char & utf-8) with tango? AFAIK Cout and Stdout don't provide methods to output binary data. Is there any facility which allows to open unix file descriptors? (DeviceConduit?.reopen looks like such a thing, but is protected)

Author Message

Posted: 08/31/07 19:37:58

Binary IO is performed via a Conduit, InputStream?, and OutputStream?, using write(void[]) and read(void[])

Because opening a file-descriptor is somewhat OS-specific, Tango does not expose that via the IO system. However, you can write your own Conduit implementation to do it, or just use tango.stdc functions instead?

Posted: 08/31/07 21:02:58

Ok, overriding DeviceConduit? seems to be enough, to be able to open unix fds (or I could use Console.Conduit).

class FdConduit : DeviceConduit
{
    this (int fd)
    {    
        reopen(cast(Handle)fd);
    }    
}

However, after browsing the sources, I found out about Cout.stream et al. In most cases, this eliminates the need for something like the FdConduit? class above. I know that this is documented, but I'm apparently not yet confident enough with Tango's documentation style.

Posted: 09/01/07 23:50:10 -- Modified: 09/01/07 23:50:32 by
kris

That looks right :)

Note that it's perhaps unwise to subclass the Console for this kind of thing, since it does (or may do) UTF conversion on the content passing through. Tango.io.console is intended to be UTF8 IO only ...