fyre/stream

A stream library.

Installs: 33

Dependents: 2

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/fyre/stream

v4.0.1 2025-11-02 10:20 UTC

This package is auto-updated.

Last update: 2025-11-02 10:21:09 UTC


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\Http\Stream;

Basic Usage

  • $resource is a resource.
$stream = new Stream($resource);

Create 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::createFromFile($filePath, $mode);

Create From String

  • $string is a string representing the stream content.
$stream = Stream::createFromString($string);

Methods

Close

Close the resource.

$stream->close();

Detach

Detach the resource from the stream.

$stream->detach();

Eof

Determine whether the stream has ended.

$ended = $stream->eof();

Get Contents

Get the contents of the stream.

$contents = $stream->getContents();

Get Metadata

Get the stream meta data.

  • $key is a string representing the meta data key.
$value = $stream->getMetadata($key);

If the $key argument is omitted, this method will return an array containing all values.

$data = $stream->getMetadata();

Get Size

Get the size of the stream.

$size = $stream->getSize();

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);

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);