class FileDataStream

Inherits: DataStream

Data stream for handling data from standard streams.

Public

Constructors

FileDataStream

FileDataStream(const Path &filePath, AccessMode accessMode = READ)

Constructs a file stream.

filePath
Path of the file to open.
accessMode
Determines should the file be opened in read, write or read/write mode.

Methods

~FileDataStream

~FileDataStream() noexcept override

Open

bool Open()

Opens the file stream.

Must be called before any actions on the stream. Returns false if not successful.

IsFile

bool IsFile() const override

Checks whether the stream reads/writes from a file system.

Read

size_t Read(void *data, size_t byteCount) const override

Read the requisite number of bytes from the stream, stopping at the end of the file.

Advances the read pointer.

data
Pre-allocated buffer to read the data into.
byteCount
Number of bytes to read.

Returns: Number of bytes actually read.

Write

size_t Write(const void *data, size_t byteCount) override

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.

Skip

size_t Skip(size_t count) override

Skip a defined number of bytes.

Returns the actual number of bytes skipped.

Seek

size_t Seek(size_t pos) override

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

size_t Tell() const override

Returns the current cursor byte offset from beginning.

Eof

bool Eof() const override

Returns true if the stream has reached the end.

Clone

SPtr<DataStream> Clone(bool copyData = true) const override

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

bool Flush() override

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.

Close

bool Close() override

Closes the stream.

This makes further operations invalid. Executes a Flush() before closing, and passes the return value from Flush().

GetPath

const Path &GetPath() const

Returns the path of the file opened by the stream.

Protected

Fields

mPath

Path mPath

mFileStream

std::fstream mFileStream