ArrayStream

An InputStream that encapsulates contents of an array

Constructors

this
this()

Constructor. Initializes stream as empty

this
this(ubyte[] data, size_t size)

Constructor. Initializes stream with an array of bytes. size delimits maximum read size

this
this(ubyte[] data)

Constructor. Initializes stream with an array of bytes

Members

Functions

close
void close()
Undocumented in source. Be warned that the author may not have intended to support it.
getPosition
StreamPos getPosition()
Undocumented in source. Be warned that the author may not have intended to support it.
readBytes
size_t readBytes(void* buffer, size_t count)
Undocumented in source. Be warned that the author may not have intended to support it.
readable
bool readable()
Undocumented in source. Be warned that the author may not have intended to support it.
seekable
bool seekable()
Undocumented in source. Be warned that the author may not have intended to support it.
setPosition
bool setPosition(StreamPos pos)
Undocumented in source. Be warned that the author may not have intended to support it.
size
StreamSize size()
Undocumented in source. Be warned that the author may not have intended to support it.

Inherited Members

From InputStream

readable
bool readable()

Returns true if there are any data to read. false means end of the stream.

readBytes
size_t readBytes(void* buffer, size_t count)

Attempts to read count bytes from stream and stores them in memory pointing by buffer. Returns number of bytes actually read

fillArray
bool fillArray(T[] array)

Attempts to fill an array with raw data from stream. Returns true if the array was filled, false otherwise

readLE
bool readLE(T* value)

Reads little-endian integer, converts to native-endian and stores in value

readBE
bool readBE(T* value)

Reads big-endian integer, converts to native-endian and stores in value

Examples

ubyte[] arr = [23,13,42,71,0,1,1,2,3,5,8];

auto stream = new ArrayStream(arr);
assert(stream.size() == arr.length);

ubyte[4] buf;
assert(stream.readBytes(buf.ptr, buf.length) == buf.length);
assert(buf == [23,13,42,71]);
assert(stream.getPosition() == buf.length);

assert(stream.setPosition(6));
assert(stream.getPosition == 6);
assert(stream.readBytes(buf.ptr, buf.length) == buf.length);
assert(buf == [1,2,3,5]);

assert(stream.readBytes(buf.ptr, buf.length) == 1);
assert(buf[0] == 8);
assert(!stream.readable);

stream.setPosition(1);
assert(stream.readable);
stream.seek(4);
assert(stream.readBytes(buf.ptr, buf.length) == buf.length);
assert(buf == [1,1,2,3]);

assert(stream.setPosition(arr.length));
assert(!stream.setPosition(arr.length+1));

stream.close();
assert(!stream.readable);

Meta