Reading a structured binary file?

Justin Whear justin at economicmodeling.com
Fri Aug 2 10:56:22 PDT 2013


On Fri, 02 Aug 2013 19:49:54 +0200, Gary Willoughby wrote:

> What library commands do i use to read from a structured binary file? I
> want to read the byte stream 1, 2 maybe 4 bytes at a time and cast these
> to bytes, shorts and ints respectively. I can't seem to find anything
> like readByte().

You can use File.rawRead:

ushort[1] myShort;
file.rawRead(myShort);

Or if you have structures in the file:

struct Foo
{
    align(1):
    int bar;
    short k;
    char[7] str;
}
Foo[1] foo;
file.rawRead(foo);


More information about the Digitalmars-d-learn mailing list