What is best way to read and interpret binary files?

welkam wwwelkam at gmail.com
Mon Nov 19 21:30:36 UTC 2018


So my question is in subject/title. I want to parse binary file 
into D structs and cant really find any good way of doing it. 
What I try to do now is something like this

byte[4] fake_integer;
auto fd = File("binary.data", "r");
fd.rawRead(fake_integer);
int real_integer = *(cast(int*)  fake_integer.ptr);

What I ideally want is to have some kind of c style array and 
just cast it into struct or take existing struct and populate 
fields one by one with data from file. Is there a D way of doing 
it or should I call core.stdc.stdio functions instead?


More information about the Digitalmars-d-learn mailing list