Consume binary files

Bogdan olar.bogdan.dev at gmail.com
Sat Mar 10 18:26:43 UTC 2018


I'm working on a pet project which involves reading various 
structure types, or just multi-byte values (uin32_t, uint16_t, 
etc) from files, or just from ubyte arrays.

Here's how I've been dealing with some of these situations so far:

```
     /// Helper structure used to read each of the file 
descriptors in a HOG file
     struct HogFileDescriptor
     {
     align(1):
         char[13] fileName;
         int fileSize;
     }

     ubyte[HogFileDescriptor.sizeof] buffer;

     File f = File(filename, "r");

     // while bytes left in file
         f.rawRead(buffer);
         hfd = cast(HogFileDescriptor*) buffer.ptr;



More information about the Digitalmars-d-learn mailing list