fyre / stream
A stream library.
v2.0.11
2024-10-30 10:57 UTC
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.59
- fyre/php-cs-fixer-config: ^1.0
- phpunit/phpunit: ^11
README
FyreStream is a free, open-source stream library for PHP.
Table Of Contents
Installation
Using Composer
composer require fyre/stream
In PHP:
use Fyre\Stream\Stream;
Basic Usage
$resource
is a resource.
$stream = new Stream($resource);
From File
$filePath
is a string representing the file path.$mode
is a string representing the file access mode, and will default to "r".
$stream = Stream::fromFile($filePath, $mode);
Methods
Close
Close the resource.
$stream->close();
Contents
Get the contents of the stream.
$contents = $stream->contents();
Ended
Determine whether the stream has ended.
$ended = $stream->ended();
Is Readable
Determine whether the stream is readable.
$isReadable = $stream->isReadable();
Is Seekable
Determine whether the stream is seekable.
$isSeekable = $stream->isSeekable();
Is Writable
Determine whether the stream is writable.
$isWritable = $stream->isWritable();
Read
Read data from the stream.
$length
is a number representing the number of bytes to read.
$data = $stream->read($length);
Rewind
Rewind the stream.
$stream->rewind();
Seek
Move the pointer in the stream.
$offset
is a number representing the offset.$whence
is a number representing the offset origin, and will default to SEEK_SET.
$stream->seek($offset, $whence);
Size
Get the size of the stream.
$size = $stream->size();
Tell
Get the offset of the pointer.
$offset = $stream->tell();
Write
Write data to the stream.
$data
is a string representing the data to write.
$written = $stream->write($data);