If filename is not null, attempts to load file into memory
Clears the stream, resets the stream
loads file into memory, throws exception if fails
reads and returns size number of bytes from file starting from seek-position If not enough bytes are left, the array returned will be smaller than size Returns null if the seek-position is at end, or if there are no bytes to be read
Reads and returns bytes starting from seek till terminate byte, or if EOF is reached
Removes a number of bytes starting from the seek-position
Writes the stream to a file, throws exception if fails
Writes an array at the seek-position, and moves seek to end of the written data
Writes a byte at the seek-position, and moves seek to end of the written data
The seek position, from where the next char(s) will be read, or written to
The seek position, from where the next char(s) will be read, or written to
The size of file in bytes, read-only
unittests for FileReader
// file loading/ saving not tested FileReader stream = new FileReader(); assert(stream.seek == 0); // write & read stream.write(cast(ubyte[])"ABCE"); assert(stream.seek == 4); assert(stream.size == 4); stream.seek = 3; stream.write(cast(ubyte)'D'); assert(stream.size == 5); assert(stream.seek == 4); stream.seek = 0; assert(stream.read(stream.size) == cast(ubyte[])"ABCDE"); stream.seek = 0; assert(stream.read(cast(ubyte)'C') == cast(ubyte[])"ABC"); stream.seek = 0; assert(stream.read(cast(ubyte)'Z') == cast(ubyte[])"ABCDE"); // clear stream.clear; assert(stream.size == 0); assert(stream.seek == 0); // remove stream.write(cast(ubyte[])"ABCDE"); stream.seek = 3; assert(stream.remove(99) == true); stream.seek = 0; assert(stream.read(cast(ubyte)'Z') == cast(ubyte[])"AB"); stream.write(cast(ubyte[])"CDE"); stream.seek = 1; assert(stream.remove(2) == true); stream.seek = 0; assert(stream.read(cast(ubyte)'Z') == "DE");
For reading files. Can also be used for writing