Consume binary files

Jonathan M Davis newsgroup.d at jmdavisprog.com
Sat Mar 10 18:49:48 UTC 2018


On Saturday, March 10, 2018 18:31:23 Bogdan via Digitalmars-d-learn wrote:
> ... I accidentally posted that before it was complete because I
> kept pressing TAB in order to indent ...
>
> Anyway, I'd like to know if there exists such a thing as
>
> ```
>      int a = stream.ReadInt32();
> ```

Check out

https://dlang.org/phobos/std_bitmanip.html#peek
https://dlang.org/phobos/std_bitmanip.html#read

They can be used to read integral values from a range of ubytes. You can use
either std.file.read or std.stdio.File to read from the file and than those
functions from std.bitmanip to convert the ubytes to integrals.
std.file.read would be the easiest to use, since it just gives you a single
dynamic array to deal with, but it does mean reading in the entire file at
once.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list