Reading a structured binary file?

John Colvin john.loughran.colvin at gmail.com
Sat Aug 3 14:10:12 PDT 2013


On Saturday, 3 August 2013 at 18:23:58 UTC, Gary Willoughby wrote:
> On Saturday, 3 August 2013 at 18:14:47 UTC, Gary Willoughby 
> wrote:
>> This sounds a great idea but once the file has been opened as 
>> a MmFile how to i convert this to a ubyte[] so the 
>> std.bitmanip functions work with it?
>
> I'm currently doing this:
>
> 	auto file = new MmFile("file.dat");
> 	ubyte[] buffer = cast(ubyte[])file[];
> 	buffer.read!uint(); //etc.
>
> Is this how you would recommend?

That defeats the object of memory mapping, as the [] at the end 
of cast(ubyte[])file[] implies copying the whole file in to 
memory.

3 options I can think of:
1) copy read from std.bitmanip and modify it to work nicely with 
MmFile
2) write a wrapper for MmFile to let it work nicely with read
3) rewrite/modify MmFile

I would love to do 3) at some point, but I'm too busy at the 
moment.


More information about the Digitalmars-d-learn mailing list