\Omega\Filesystem\Stream StreamInterface

Interface StreamInterface.

This interface defines the contract for file stream operations, providing methods to manipulate and interact with file streams. Implementations of this interface should handle opening, reading, writing, closing, and managing the state of a stream, allowing for flexible and efficient file handling in the filesystem.

Summary

Methods
Constants
open()
read()
write()
close()
flush()
seek()
tell()
eof()
stat()
cast()
unlink()
No public constants found

Methods

open()

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

Opens the stream in the specified mode.

This method should initialize the stream for reading or writing based on the provided mode. If the stream is already open, it may need to be closed first.

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|false

Reads the specified number of bytes from the current position.

If the current position is at the end-of-file, this method must return an empty string.

Parameters

int $count

The number of bytes to read from the stream.

Returns

string|false —

The read bytes as a string, or FALSE on failure.

write()

write(string  $data) : int|false

Writes the specified data to the stream.

This method should update the current position of the stream by the number of bytes that were successfully written. If an error occurs during writing, it should return FALSE.

Parameters

string $data

The data to write to the stream.

Returns

int|false —

The number of bytes that were successfully written, or FALSE on failure.

close()

close() : bool

Closes the stream.

This method must free all resources associated with the stream. If there is any buffered data, it should be flushed to the underlying storage before closing.

Returns

bool —

TRUE on success, or FALSE on failure.

flush()

flush() : bool

Flushes the output buffer.

If there is any cached data that has not yet been written to the underlying storage, this method should perform that operation.

Returns

bool —

TRUE on success, or FALSE on failure.

seek()

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

Seeks to the specified offset within the stream.

This method should change the current position of the stream to the specified offset according to the whence parameter.

Parameters

int $offset

The offset to seek to.

int $whence

The reference point for the offset (default is SEEK_SET).

Returns

bool —

TRUE on success, or FALSE on failure.

tell()

tell() : int|false

Returns the current position of the stream.

Returns

int|false —

The current position as an integer, or FALSE on failure.

eof()

eof() : bool

Indicates whether the current position is at the end-of-file.

Returns

bool —

TRUE if at end-of-file, FALSE otherwise.

stat()

stat() : array|false

Gathers statistics about the stream.

This method returns an array containing various statistics about the stream. If the statistics cannot be gathered, it should return FALSE.

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.

This method attempts to remove the file from the filesystem.

Returns

bool —

TRUE on success, or FALSE otherwise.