PHPackages                             digitalcz/streams - 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. [File &amp; Storage](/categories/file-storage)
4. /
5. digitalcz/streams

ActiveLibrary[File &amp; Storage](/categories/file-storage)

digitalcz/streams
=================

Opinionated abstraction around PHP streams implementing PSR-7 StreamInterface

v1.1.1(2w ago)112.9k—5.1%1MITPHPPHP ^8.1CI passing

Since Feb 17Pushed 1w ago2 watchersCompare

[ Source](https://github.com/digitalcz/streams)[ Packagist](https://packagist.org/packages/digitalcz/streams)[ Docs](https://github.com/digitalcz/streams)[ RSS](/packages/digitalcz-streams/feed)WikiDiscussions 1.x Synced yesterday

READMEChangelog (10)Dependencies (24)Versions (15)Used By (1)

Streams
=======

[](#streams)

[![Latest Stable Version](https://camo.githubusercontent.com/05b711b457848c5b8be1b6e07e83d458a400b157a0228c641569fb1bb44d99ef/687474703a2f2f706f7365722e707567782e6f72672f6469676974616c637a2f73747265616d732f76)](https://packagist.org/packages/digitalcz/streams)[![Total Downloads](https://camo.githubusercontent.com/85ec2932842c43be5fc1dd033bed142dc860e817ecfe7a43599b3fd2e5da2972/687474703a2f2f706f7365722e707567782e6f72672f6469676974616c637a2f73747265616d732f646f776e6c6f616473)](https://packagist.org/packages/digitalcz/streams)[![Latest Unstable Version](https://camo.githubusercontent.com/cc0f36a56897bb86a6f1e178aff3f99fca02a5143687af7bd8f807200146c5da/687474703a2f2f706f7365722e707567782e6f72672f6469676974616c637a2f73747265616d732f762f756e737461626c65)](https://packagist.org/packages/digitalcz/streams)[![License](https://camo.githubusercontent.com/2db779b518eb7af2bde0624338f69ff609a38ebe1ca8e5f4c117f6bc8af3b365/687474703a2f2f706f7365722e707567782e6f72672f6469676974616c637a2f73747265616d732f6c6963656e7365)](https://packagist.org/packages/digitalcz/streams)[![PHP Version Require](https://camo.githubusercontent.com/807f45d3940dc085e7dd37a111360b3b1db32ee1aa592de3b1617d674ae1692d/687474703a2f2f706f7365722e707567782e6f72672f6469676974616c637a2f73747265616d732f726571756972652f706870)](https://packagist.org/packages/digitalcz/streams)[![CI](https://github.com/digitalcz/streams/workflows/CI/badge.svg)](https://github.com/digitalcz/streams/actions)[![codecov](https://camo.githubusercontent.com/eb2f0463e1ad02af96db61c6abab68de38fda697282656dce721e7be5e94f14f/68747470733a2f2f636f6465636f762e696f2f67682f6469676974616c637a2f73747265616d732f6272616e63682f312e782f67726170682f62616467652e7376673f746f6b656e3d517a5a35694d4e6b6733)](https://codecov.io/gh/digitalcz/streams)

Opinionated abstraction around PHP streams implementing PSR-7 StreamInterface. It aims to improve working with files or remote streams in unified way.

Heavily inspired by guzzle/psr7.

Install
-------

[](#install)

Via [Composer](https://getcomposer.org/)

```
$ composer require digitalcz/streams
```

Usage
-----

[](#usage)

All streams implement `DigitalCz\Streams\StreamInterface`, which extends PSR-7 `Psr\Http\Message\StreamInterface` and adds a few convenience methods (`copy()`, void-returning `close()`/`seek()`, …).

### Stream

[](#stream)

A wrapper around any PHP stream resource. Use `Stream::from()` to build one from a string, a resource or another PSR-7 stream — the data is held in `php://temp`.

```
use DigitalCz\Streams\Stream;

// From a string
$stream = Stream::from('Hello world');
echo $stream->getContents();        // "Hello world"

// From an existing resource
$stream = Stream::from(fopen('php://memory', 'rb+'));

// From another PSR-7 stream
$stream = Stream::from($psrStream);

// Wrapping a resource directly (optionally with a known size)
$stream = new Stream(fopen('data.bin', 'rb'));

// Copy another stream into this one (returns bytes written)
$bytes = $stream->copy($otherStream);
```

### File

[](#file)

A stream backed by a real file on disk. Adds `getPath()` and `delete()`.

```
use DigitalCz\Streams\File;

$file = new File('/path/to/file.txt');      // opened with mode "rb+" by default
echo $file->getPath();

// Build a file from a string / resource / PSR-7 stream.
// A string that is an existing path opens that file, otherwise it is the content.
$file = File::from('contents written to a temp file');

$temp = File::temp();                        // empty file in the system temp dir
$file->delete();                             // close and unlink
```

### TempFile

[](#tempfile)

Like `File`, but backed by `tmpfile()` — the underlying file is removed automatically once the stream handle is closed.

```
use DigitalCz\Streams\TempFile;

$temp = TempFile::from('temporary content');
echo $temp->getPath();
$temp->close();                              // file is deleted on close
```

### BufferedStream

[](#bufferedstream)

Wraps a non-seekable / one-shot source stream and buffers what it reads into `php://temp`, so the source can be re-read and seeked. It is read-only.

```
use DigitalCz\Streams\BufferedStream;

$buffered = new BufferedStream($nonSeekableSource);
$head = $buffered->read(1024);
$buffered->rewind();                         // works even if the source could not seek
$all = $buffered->getContents();
```

### StreamWrapper

[](#streamwrapper)

Turns a `StreamInterface` back into a native PHP stream resource, usable with any function that expects one (`fread`, `fgets`, `stream_copy_to_stream`, …).

```
use DigitalCz\Streams\StreamWrapper;

$resource = StreamWrapper::from($stream);
$line = fgets($resource);
```

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Testing
-------

[](#testing)

```
$ composer csfix    # fix codestyle
$ composer checks   # run all checks

# or separately
$ composer tests    # run phpunit
$ composer phpstan  # run phpstan
$ composer cs       # run codesniffer
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Digital Solutions s.r.o.](https://github.com/digitalcz)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

53

—

FairBetter than 96% of packages

Maintenance97

Actively maintained with recent releases

Popularity27

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 76.9% 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 ~111 days

Recently: every ~101 days

Total

12

Last Release

9d ago

Major Versions

0.x-dev → v1.0.02025-05-15

### Community

Maintainers

![](https://www.gravatar.com/avatar/3cdd1a59b82ee65304942a9e50a35ed1628b43db456088c334e73f8e80db9237?d=identicon)[spajxo](/maintainers/spajxo)

![](https://avatars.githubusercontent.com/u/19805238?v=4)[DigitalCz](/maintainers/digitalcz)[@digitalcz](https://github.com/digitalcz)

---

Top Contributors

[![spajxo](https://avatars.githubusercontent.com/u/12384486?v=4)](https://github.com/spajxo "spajxo (70 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (13 commits)")[![Copilot](https://avatars.githubusercontent.com/in/1143301?v=4)](https://github.com/Copilot "Copilot (8 commits)")

---

Tags

fileStreams

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/digitalcz-streams/health.svg)

```
[![Health](https://phpackages.com/badges/digitalcz-streams/health.svg)](https://phpackages.com/packages/digitalcz-streams)
```

###  Alternatives

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.3k543.5M2.6k](/packages/aws-aws-sdk-php)[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

8.0k1.1B4.0k](/packages/guzzlehttp-psr7)[google/cloud

Google Cloud Client Library

1.2k16.7M57](/packages/google-cloud)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k656.1k38](/packages/neuron-core-neuron-ai)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[sonata-project/media-bundle

Symfony SonataMediaBundle

4625.6M73](/packages/sonata-project-media-bundle)

PHPackages © 2026

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