FileStream class
#include <IO/FileStream.h>
Allows streaming from/to a file on a local filesystem.
If a file is opened with FileAccess::
Reads and writes are buffered in blocks of bufferSize bytes. Specifying zero (or less) disables the buffering entirely, so every call is passed directly to the underlying file — this is preferable if the caller already accumulates the data in a buffer of its own.
The class is not thread-safe, an instance must not be used by more than one thread at a time.
Base classes
- class Stream
- Provides a generic view of a sequence of bytes.
Constructors, destructors, conversion operators
-
FileStream(Containers::
StringView path, FileAccess mode, std:: int32_t bufferSize = DefaultBufferSize) -
FileStream(Containers::
String&& path, FileAccess mode, std:: int32_t bufferSize = DefaultBufferSize) - ~FileStream() override
- FileStream(const FileStream&) deleted
Public functions
- auto operator=(const FileStream&) -> FileStream& deleted
- void Dispose() override
- Closes the stream and releases all assigned resources.
-
auto Seek(std::
int64_t offset, SeekOrigin origin) -> std:: int64_t override - Seeks in an opened stream.
-
auto GetPosition() const -> std::
int64_t override - Tells the seek position of an opened stream.
-
auto Read(void* destination,
std::
int64_t bytesToRead) -> std:: int64_t override - Reads a certain amount of bytes from the stream to a buffer.
-
auto Write(const void* source,
std::
int64_t bytesToWrite) -> std:: int64_t override - Writes a certain amount of bytes from a buffer to the stream.
- auto Flush() -> bool override
- Clears all buffers for this stream and causes any buffered data to be written to the underlying device.
- auto IsValid() -> bool override
- Returns
trueif the stream has been sucessfully opened. -
auto GetSize() const -> std::
int64_t override - Returns stream size in bytes.
-
auto SetSize(std::
int64_t size) -> std:: int64_t override - Sets stream size in bytes.
-
auto GetPath() const -> Containers::
StringView - Returns file path.
-
auto GetBufferSize() const -> std::
int32_t - Returns the size of the I/O buffer, 0 for unbuffered access.
-
auto SetBufferSize(std::
int32_t bufferSize) -> bool - Changes the size of the I/O buffer, releasing the current buffer.
-
auto GetFileDescriptor() const -> std::
int32_t - Returns native file descriptor.
Constants
-
static std::
int32_t DefaultBufferSize constexpr - Default buffer size for file access.
Function documentation
bool Death:: IO:: FileStream:: SetBufferSize(std:: int32_t bufferSize)
Changes the size of the I/O buffer, releasing the current buffer.
Anything buffered is flushed first, so the position stays where the caller sees it. The new buffer is allocated by the next read or write. Used by FileStreamPool to let a reused stream take the size its next user asked for; returns false only if pending writes could not be flushed.