PHPackages                             stream-interop/impl - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. stream-interop/impl

ActiveLibrary[PSR &amp; Standards](/categories/psr-standards)

stream-interop/impl
===================

Reference implementations for the stream-interop/interface package.

1.0.1(11mo ago)121MITPHPPHP &gt;=8.4CI passing

Since Jan 21Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/stream-interop/impl)[ Packagist](https://packagist.org/packages/stream-interop/impl)[ Docs](https://github.com/stream-interop/impl)[ RSS](/packages/stream-interop-impl/feed)WikiDiscussions 1.x Synced 1mo ago

READMEChangelog (5)Dependencies (5)Versions (7)Used By (0)

Stream-Interop Implementation Package
=====================================

[](#stream-interop-implementation-package)

Reference implementations of [stream-interop/interface](https://packagist.org/packages/stream-interop/interface).

Installation
------------

[](#installation)

Install this package via [Composer](https://getcomposer.org):

```
$ composer require stream-interop/impl

```

Implementations
---------------

[](#implementations)

### File Streams

[](#file-streams)

#### *ConsumableFileStream*

[](#consumablefilestream)

A unidirectional readable stream; does not afford seeking or writing.

```
$stream = new \StreamInterop\Impl\ConsumableFileStream(fopen('/path/to/file', 'rb'));

$stream->read(2);       // reads the first 2 bytes
$stream->read(4);       // reads the next 4 bytes
$stream->getContents(); // reads all remaining bytes
$stream->eof();         // true
```

#### *ReadableFileStream*

[](#readablefilestream)

A readable stream that affords seeking and stringability.

```
$stream = new \StreamInterop\Impl\ReadableFileStream(fopen('/path/to/file', 'rb'));

$stream->read(2);       // reads the first 2 bytes
$stream->read(4);       // reads the next 4 bytes
$stream->getContents(); // reads all remaining bytes
$stream->eof();         // true
$stream->__toString();  // rewinds and reads the entire file

$stream->rewind();      // rewinds the pointer
$stream->seek(7);       // moves to byte 7
$stream->read(3);       // reads the next 3 bytes
```

#### *ReadonlyFileStream*

[](#readonlyfilestream)

Identical to the *ReadableFileStream*, but it makes a copy of the original resource to enforce readonly constraints. If the original resource is modified, the *ReadonlyFileStream* will not reflect those changes.

```
// create the origin file
$file = '/path/to/file';
file_put_contents($file, 'foo bar');

// initialize a readonly stream from the file;
// the readonly stream reads the file into memory.
$stream = new \StreamInterop\Impl\ReadonlyFileStream($file);
assert((string) $stream === file_get_contents($file));

// change the origin file
file_put_contents($file, 'baz dib');

// the stream does not reflect the changes
assert((string) $stream !== file_get_contents($file));
```

#### *ReadWriteFileStream*

[](#readwritefilestream)

A fully read+write stream that affords seeking, appending, and stringability.

```
$stream = new \StreamInterop\Impl\ReadWriteFileStream(fopen('/path/to/file', 'wb+'));

$stream->write('Hello ');
$stream->rewind();
$stream->append('World!');
$stream->rewind();
$stream->read(2);           // reads "He"
$stream->read(4);           // reads "llo "
$stream->getContents();     // reads "World!"
$stream->eof();             // true
$stream->__toString();      // reads "Hello World!"
```

#### *WritableFileStream*

[](#writablefilestream)

A unidirectional writable stream; does not afford seeking or reading.

```
$stream = new \StreamInterop\Impl\WritableFileStream(fopen('/path/to/file', 'wb'));

$stream->write('Hello World!');
```

### Lazy Ghost File Objects

[](#lazy-ghost-file-objects)

These streams open a resource themselves on a specified filename.

#### *ReadableFile*

[](#readablefile)

A readable lazy-opening stream that affords seeking and stringability.

```
// construct with a file name, not an open resource
$stream = new \StreamInterop\Impl\ReadableFile('/path/to/file');

$stream->read(2);           // reads the first 2 bytes
$stream->read(4);           // reads the next 4 bytes
$stream->getContents();     // reads all remaining bytes
$stream->eof();             // true
$stream->__toString();      // rewinds and reads the entire file

$stream->rewind();          // rewinds the pointer
$stream->seek(7);           // moves to byte 7
$stream->read(3);           // reads the next 3 bytes
```

#### *ReadWriteFile*

[](#readwritefile)

A fully read+write lazy-opening stream that affords seeking and stringability.

```
// construct with a file name, not an open resource
$stream = new \StreamInterop\Impl\ReadWriteFile('/path/to/file');

$stream->write('Hello World!');
$stream->rewind();
$stream->read(2);           // reads "He"
$stream->read(4);           // reads "llo "
$stream->getContents();     // reads "World!"
$stream->eof();             // true
$stream->__toString();      // reads "Hello World!"
```

### Non-Resource Streams

[](#non-resource-streams)

#### *StringStream*

[](#stringstream)

A fully read+write stream that affords seeking and stringability, backed by a string instead of a resource.

```
// construct with string data, not a resource of file name
$stream = new \StreamInterop\Impl\StringStream('Hello');

$stream->read(2);           // reads 'He'
$stream->getContents();     // reads 'llo'
$stream->write(' World!');

$stream->rewind();
$stream->getContents();     // reads 'Hello World!'
```

---

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance50

Moderate activity, may be stable

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 88.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~22 days

Recently: every ~15 days

Total

6

Last Release

357d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/25754?v=4)[Paul M. Jones](/maintainers/pmjones)[@pmjones](https://github.com/pmjones)

---

Top Contributors

[![pmjones](https://avatars.githubusercontent.com/u/25754?v=4)](https://github.com/pmjones "pmjones (37 commits)")[![nbish11](https://avatars.githubusercontent.com/u/1518821?v=4)](https://github.com/nbish11 "nbish11 (5 commits)")

---

Tags

streamresourceinterop

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/stream-interop-impl/health.svg)

```
[![Health](https://phpackages.com/badges/stream-interop-impl/health.svg)](https://phpackages.com/packages/stream-interop-impl)
```

###  Alternatives

[sandrokeil/interop-config

Provides interfaces and a concrete implementation to create instances depending on configuration via factory classes and ensures a valid config structure. It can also be used to auto discover factories and to create configuration files.

58446.7k34](/packages/sandrokeil-interop-config)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
