Skip to content

dlib.core.stream

Timur Gafarov edited this page Apr 26, 2017 · 8 revisions

dlib.core.stream

Binary I/O stream interfaces.

Type aliases

  • StreamPos - an alias to std.stdint.uint64_t.
  • StreamSize - an alias to std.stdint.uint64_t.
  • StreamOffset - an alias to std.stdint.int64_t.

class SeekException: Exception

An exception which is throwed on stream errors.

interface Seekable

Represents a stream container that knows the size of a stream and allows to change byte position within the stream.

  • StreamPos getPosition() - returns current position.
  • bool setPosition(StreamPos pos) - attempts to set current position to pos. Returns true on success, false on failure.
  • StreamSize size() - returns the size of a stream in bytes.
  • final StreamPos position(StreamPos pos) - attempts to set current position to pos and returns it. Throws SeekException on failure.
  • final StreamPos position() - returns current position.
  • final StreamPos seek(StreamOffset amount) - relatively changes position. amount defines an offset from the current position (can be negative). Throws SeekException on failure.

interface Stream: Seekable

A parent interface for all stream types.

  • void close() - closes the stream. Closed stream cannot be read or written any more.
  • bool seekable() - returns true if it is legal to use Seekable functionality on this stream.

interface InputStream: Stream

A stream that allows to read data from it. Reading any data implies position advance by corresponding number of bytes.

  • bool readable() - returns true if there are any data to read. false means end of the stream.
  • 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.
  • final bool fillArray(T)(T[] array) - attempts to fill an array with raw data from stream. Returns true if the array was filled, false otherwise.
  • final bool readLE(T)(T* value) - reads little-endian integer, converts to native-endian and stores in value.
  • final bool readBE(T)(T* value) - reads big-endian integer, converts to native-endian and stores in value.

interface OutputStream: Stream

A stream that allows to write data into it.

  • void flush() - implementation-specific method. Usually it writes any unwritten data from output buffer.
  • bool writeable() - returns true if stream can be written to.
  • size_t writeBytes(const void* buffer, size_t count) - attempts to write count bytes from the memory pointed by buffer. Returns number of bytes actually written.
  • final bool writeArray(T)(const T[] array) - attempts to write an array. Returns true if all elements were written, false otherwise.
  • final bool writeStringz(string text) - attempts to write a string as zero-terminated. Returns true if entire string was written, false otherwise.
  • final bool writeLE(T)(const T value) - writes an integer in little-endian encoding.
  • final bool writeBE(T)(const T value) - writes an integer in big-endian encoding.

interface IOStream: InputStream, OutputStream

A stream that allows both reading and writing data.

class ArrayStream: InputStream

A stream that encapsulates contents of an array.

  • this() - initializes stream as empty.
  • this(ubyte[] data, size_t size) - initializes stream with an array of bytes and size of size.
  • this(ubyte[] data) - initializes stream with an array of bytes and size of data.length.

Free functions

  • StreamSize copyFromTo(InputStream input, OutputStream output) - while input is readable, reads data from input and writes it to output. Returns number of bytes read.