class
DataStream
General purpose class used for encapsulating the reading and writing of data from and to various sources using a common interface.
Public
Constructors
DataStream
Creates an unnamed stream.
DataStream
Creates a named stream.
Methods
~DataStream
GetName
GetAccessMode
IsReadable
IsWriteable
IsFile
Checks whether the stream reads/writes from a file system.
Read
Read the requisite number of bytes from the stream, stopping at the end of the file.
Advances the read pointer.
- outData
- Pre-allocated buffer to read the data into.
- byteCount
- Number of bytes to read.
Returns: Number of bytes actually read.
Write
Write the requisite number of bytes to the stream and advance the write pointer.
- data
- Buffer containing bytes to write.
- byteCount
- Number of bytes to write.
Returns: Number of bytes actually written.
ReadBits
Reads bits from the stream into the provided buffer from the current cursor location and advances the cursor.
If the stream doesn't support per-bit reads, data size will be rounded up to nearest byte.
- outData
- Buffer to read the data from. Must have enough capacity to store bits.
- count
- Number of bits to read.
Returns: Number of bits actually read.
WriteBits
Writes bits from the provided buffer into the stream at the current cursor location and advances the cursor.
If the stream doesn't support per-bit writes, data size will be rounded up to nearest byte.
- data
- Buffer to write the data from. Must have enough capacity to store bits.
- count
- Number of bits to write.
Returns: Number of bits actually written.
WriteString
Writes the provided narrow string to the steam.
String is convered to the required encoding before being written.
- string
- String containing narrow characters to write, encoded as UTF8.
- encoding
- Encoding to convert the string to before writing.
WriteString
Writes the provided wide string to the steam.
String is convered to the required encoding before being written.
- string
- String containing wide characters to write, encoded as specified by platform for wide characters.
- encoding
- Encoding to convert the string to before writing.
GetAsString
Returns a string containing the entire stream.
Returns: String data encoded as UTF-8.
GetAsWString
Returns a wide string containing the entire stream.
Returns: Wide string encoded as specified by current platform.
Skip
Skip a defined number of bytes.
Returns the actual number of bytes skipped.
Seek
Repositions the read or write cursor to the specified byte.
Returns the actual byte the cursor has been placed at, in case end has been reached earlier
Tell
Returns the current cursor byte offset from beginning.
Align
Aligns the read/write cursor to a byte boundary. determines the alignment in bytes.
Note the requested alignment might not be achieved if count > 1 and it would move the cursor past the capacity of the buffer, as the cursor will be clamped to buffer end regardless of alignment.
Eof
Returns true if the stream has reached the end.
Size
Returns the total size of the data to be read from the stream, or 0 if this is indeterminate for this stream.
Clone
Creates a copy of this stream.
- copyData
- If true the internal stream data will be copied as well, otherwise it will just reference the data from the original stream (in which case the caller must ensure the original stream outlives the clone). This is not relevant for file streams.
Flush
Flushes the stream, writing any buffer data to the destination.
Returns false if some error occurred and data was not written correctly. Does not need to be called if stream was just read from.