fyre/stream

A stream library.

v2.0.8 2024-06-29 06:31 UTC

This package is auto-updated.

Last update: 2024-08-29 06:48:26 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\Stream\Stream;

Stream Creation

  • $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 if the stream has ended.

$ended = $stream->ended();

Is Readable

Determine if the stream is readable.

$isReadable = $stream->isReadable();

Is Seekable

Determine if the stream is seekable.

$isSeekable = $stream->isSeekable();

Is Writable

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