\Omega\Filesystem\Stream InMemoryBuffer

Class InMemoryBuffer.

Implements a stream interface that allows reading from and writing to an in-memory buffer, providing temporary storage for file content managed by a Filesystem instance. It handles synchronization with the underlying filesystem and manages read/write positions.

Summary

Methods
Properties
Constants
__construct
open
read
write
close
seek
tell
flush
eof
stat
cast
unlink
No public properties found
No public constants found
hasNewContentAtFurtherPosition
writeContent
No protected properties found
No protected constants found
No private methods found
mode
content
numBytes
position
synchronized
filesystem
key
No private constants found

Properties

$mode

$mode : \Omega\Filesystem\Stream\StreamMode

The mode of the stream (read/write).

Type

StreamMode — Holds the mode of the stream (read/write).

$content

$content : string

The content of the stream as a string.

Type

string — Holds the content of the stream as a string.

$numBytes

$numBytes : int

Total number of bytes in the buffer.

Type

int — Holds total number of bytes in the buffer.

$position

$position : int

Current read/write position in the buffer.

Type

int — Holds the current read/write position in the buffer.

$synchronized

$synchronized : bool

Indicates if the buffer content is synchronized with the filesystem.

Type

bool — Indicates if the buffer content is synchronized with the filesystem.

$filesystem

$filesystem : \Omega\Filesystem\Filesystem

Type

Filesystem

$key

$key : string

Type

string

Methods

__construct()

__construct(\Omega\Filesystem\Filesystem  $filesystem, string  $key) : void

InMemoryBuffer constructor.

Parameters

\Omega\Filesystem\Filesystem $filesystem

The filesystem managing the file to stream

string $key

The file key

Returns

void —

open()

open(\Omega\Filesystem\Stream\StreamMode  $mode) : bool

Opens the stream in the specified mode.

Parameters

\Omega\Filesystem\Stream\StreamMode $mode

The mode in which to open the stream.

Returns

bool —

TRUE on success, or FALSE on failure.

read()

read(int  $count) : string

Reads a specified number of bytes from the current position in the buffer.

Parameters

int $count

The number of bytes to read

Throws

\LogicException

If the stream does not allow reading

Returns

string —

The data read from the stream

write()

write(string  $data) : int

Writes data to the stream at the current position.

Parameters

string $data

The data to write to the stream

Throws

\LogicException

If the stream does not allow writing

Returns

int —

The number of bytes written

close()

close() : false

Closes the stream and flushes unsynchronized changes.

Returns

false —

Always returns false to indicate closure

seek()

seek(int  $offset, int  $whence = SEEK_SET) : bool

Moves the read/write position to a new location in the buffer.

Parameters

int $offset

The offset to move the position

int $whence

The reference point for the offset (SEEK_SET, SEEK_CUR, SEEK_END)

Returns

bool —

True if the seek was successful, false otherwise

tell()

tell() : int

Returns the current read/write position in the buffer.

Returns

int —

The current position

flush()

flush() : bool

Flushes unsynchronized content from the buffer to the filesystem.

Returns

bool —

True if the flush was successful, false otherwise

eof()

eof() : bool

Checks if the end of the stream has been reached.

Returns

bool —

True if the end of the stream has been reached, false otherwise

stat()

stat() : array|false

Gathers statistics about the stream.

Returns

array|false —

An associative array of stream statistics, or FALSE on failure.

cast()

cast(int  $castAs) : mixed

Retrieves the underlying resource associated with the stream.

Parameters

int $castAs

An optional parameter to cast the resource as a specific type.

Returns

mixed —

The underlying resource or FALSE on failure.

unlink()

unlink() : bool

Deletes the file associated with the stream.

Returns

bool —

TRUE on success, or FALSE otherwise.

hasNewContentAtFurtherPosition()

hasNewContentAtFurtherPosition() : bool

Checks if new content exists at a position beyond the current one.

Returns

bool —

True if there is new content at a further position, false otherwise

writeContent()

writeContent(string  $content = '', bool  $overwrite = true) : string

Writes content to the filesystem.

Parameters

string $content

The content to write (empty string by default)

bool $overwrite

Indicates whether to overwrite existing content (true by default)

Returns

string —

The content that was written