constructor
Reads a stream from file. if successful, seek and maxSize are set to 0;
Reads a data type T from current seek. **Do not use this for reading arrays**
Reads an array.
Reads at a seek without changing seek. **Does not work for dynamic arrays**
Reads a slice from the stream into buffer. Will read number of bytes so as to fill buffer
Writes this stream to a file
Writes data at seek. **Do not use this for arrays**
Writes an array at seek.
Writes (overwriting existing) data at a seek, without changing seek.
Writes an array without its size.
if the stream is allowed to grow in size while writing
maximum size stream is allowed to grow to, 0 for no limit.
Seek position (i.e: next read/write index)
Size, in bytes, of stream
Size, setter. if new size is >maxSize, size is set to maxSize
The stream
ByteStream stream = new ByteStream(); ubyte[] buffer; uint[] uintArray = [12_345, 123_456, 1_234_567, 12_345_678, 123_456_789]; stream.write(1024, 8); // 1024 as ulong stream.seek = 0; assert(stream.read!uint(8) == 1024); assert(stream.seek == 8, stream.seek.to!string); stream.writeRaw(uintArray); stream.seek = 8; buffer.length = 50; stream.readRaw(buffer); assert((cast(uint*)buffer.ptr)[0 .. 5] == uintArray); stream.seek = 0; stream.writeArray(uintArray, 6); assert(stream.seek == (uintArray.length * 4) + 6); stream.seek = 0; uintArray = stream.readArray!(uint)(6); assert (uintArray == [12_345, 123_456, 1_234_567, 12_345_678, 123_456_789], uintArray.to!string); stream.seek = 0; stream.writeRaw(uintArray); stream.writeAt(0, cast(uint)50); buffer.length = uintArray.length * uint.sizeof; stream.seek = 0; assert(stream.readRaw(buffer) == buffer.length); uintArray = (cast(uint*)buffer.ptr)[0 .. uintArray.length]; assert(uintArray[0] == 50 && uintArray[1 .. $] == [123_456, 1_234_567, 12_345_678, 123_456_789]); assert(stream.readAt!uint(4) == 123_456);
TODO: do something about this For reading large files which otherwise, would take too much memory
Aside from reading, it can also write to files. TODO make it ready For reading/writing sequentially to a ubyte[]
be careful using maxSize and grow, they're not tested