std.file read with start position

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Tue Jun 24 10:46:10 PDT 2014


On Tue, Jun 24, 2014 at 01:07:42PM -0400, Etienne via Digitalmars-d wrote:
> On 2014-06-24 12:56 PM, H. S. Teoh via Digitalmars-d wrote:
> >On Tue, Jun 24, 2014 at 12:23:08PM -0400, Etienne via Digitalmars-d wrote:
> >>I'm currently brainstorming a persistent database scheme and it
> >>surprised me that random-access reading/writing isn't implemented in
> >>std.file. With SSDs becoming more commonplace, this practice is just
> >>fine. Any other reason for this?
> >
> >std.file? Shouldn't you be looking at std.stdio?
> >
> >
> >T
> >
> 
> I did, couldn't find a way to read a specific length (serialized data)
> so std.file seemed more of a fit for that.

Easy:

	auto f = File(myDataFile, "r");
	f.seek(someOffset);
	ubyte[] buf;
	buf.length = sizeOfData;
	ubyte[] dataRead = f.rawRead(buf);
	if (dataRead.length != sizeOfData)
		throw new Exception("Unexpected truncated data");
	// do whatever you want with dataRead

Hope this helps.

And yes, the documentation should use some improvement. A lot of
improvement even. :P  Please feel free to submit a pull request, or at
least file a bug against the docs.


T

-- 
In theory, there is no difference between theory and practice.


More information about the Digitalmars-d mailing list