PHPackages                             drewlabs/psr7-stream - 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. drewlabs/psr7-stream

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

drewlabs/psr7-stream
====================

Provides utility classes and implementations for the PSR7 stream interface

v2.0.2(2y ago)082122MITPHPPHP &gt;=7.2

Since Nov 17Pushed 2y ago1 watchersCompare

[ Source](https://github.com/azandrew-sidoine/drewlabs-psr7-stream)[ Packagist](https://packagist.org/packages/drewlabs/psr7-stream)[ RSS](/packages/drewlabs-psr7-stream/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (9)Used By (2)

drewlabs-psr7-stream
====================

[](#drewlabs-psr7-stream)

Provides an implementation of the PSR7 Stream and StreamFactory interfaces

Usage
-----

[](#usage)

- Creating a Psr7 Stream

```
// ...
use Drewlabs\Psr7Stream\Stream;

// ...

// Creates PHP built-in streams such as php://memory and php://temp
$stream = Stream::new('', 'wb+');
```

- Stream Factory

- Creating a Psr7 Stream from a PHP resource

```
// ...
use Drewlabs\Psr7Stream\StreamFactory;

// ...

// Create a PSR7 stream factory instance
$factory = new StreamFactory();

// Creates stream from resources
$stream = $factory->createStreamFromResource(fopen(__DIR__ . '/../../examples/test.txt', 'rb'));
```

- Creating a Psr7 Stream from file path

```
// ...
use Drewlabs\Psr7Stream\StreamFactory;

// ...

// Create a PSR7 stream factory instance
$factory = new StreamFactory();

// Creates stream from path
$stream = $factory->createStreamFromFile(__DIR__ . '/../../examples/test.txt');
```

### +v1.2x

[](#v12x)

From v1.2.x releases a stacked stream implemenation and a lazy stream implementations has been added.

- Stacked Streams

Stacked stream is an abstraction of the stream interface that creates a stack of `StreamInterface` instances using contiguous memory (Array) and provides same stream interface API for working with the group as whole. For operations like `close()`, `detach()`, `read()`, `getSize()`, etc... every item is visited in the order they are inserted.

To create a Stacked stream:

```
use Drewlabs\Psr7Stream\StreamFactory as Factory;

$stream = Factory::stack();

// TO initialize the instance at contruction time
// The stream instance is initialized with 2 chunks
$stream = Factory::stack(Stream::new(''), Stream::new(__DIR__ . '/vendor/autoload.php'))
```

**Note**The stacked stream provide 2 additional methods for adding and removing element.

To add a new stream to the stack:

```
use Drewlabs\Psr7Stream\StreamFactory as Factory;

$stream = Factory::stack();

// Add a new stream instance
$stream->push(Stream::new('/path/to/resource'));
```

To remove the last inserted stack:

```
use Drewlabs\Psr7Stream\StreamFactory as Factory;

$stream = Factory::stack();

// Pop the last stream from the stack and return it
$s = $stream->pop();
```

**Warning**Be careful when using the `pop()` method as it reset the internal pointer of the stream to avoid data corrumption.

- Lazy Stream

Lazy stream is simply an abstraction arround a stream object which resolve the stream only when the developper is ready to operate on it like `read()`, `write()`, etc... It provides a lazy creating implementation of an instance psr7 `StreamInterface`.

Lazy stream can be created passing a callable to the contructor method:

```
use Drewlabs\Psr7Stream\StreamFactory as Factory;
use Drewlabs\Psr7Stream\Stream;
use Drewlabs\Psr7Stream\LazyStream;
//

$stream_source = 'Hello world...';

$stream = Factory::lazy(function() use (&$stream_source) {
    return Stream::new($stream_source);
});

// Or using constructor

$stream = new LazyStream(function() use (&$stream_source) {
    return Stream::new($stream_source);
});
```

or using an instance of `CreatesStream` interface, with offer an object oriented way to create a new stream:

```
use Drewlabs\Psr7Stream\CreatesStream;
use Drewlabs\Psr7Stream\Stream;

// CreateTextStream.php
class CreateTextStream implements CreatesStream
{
    /**
     *
     * @var string
     * */
    private $source;

    public function __construct($source)
    {
        $this->source = $source;
    }

    public function createStream()
    {
        return Stream::new($this->source);
    }
}

// main.php
$stream = new LazyStream(new CreateTextStream('/path/to/resource'));

// Or using factory function
$stream = Factory::lazy(new CreateTextStream('/path/to/resource'));
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~45 days

Recently: every ~78 days

Total

8

Last Release

953d ago

Major Versions

v1.2.4 → v2.02023-09-27

PHP version history (2 changes)v1.1.0PHP &gt;=7.0

v2.0PHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/48c4973d500c7f4233d5ceacab51a57208d5fb60b0f95ae60264cf92380d0534?d=identicon)[azandrew-sidoine](/maintainers/azandrew-sidoine)

---

Top Contributors

[![azandrew-sidoine](https://avatars.githubusercontent.com/u/23530515?v=4)](https://github.com/azandrew-sidoine "azandrew-sidoine (32 commits)")

---

Tags

psrstream

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/drewlabs-psr7-stream/health.svg)

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

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

8.0k1.0B3.1k](/packages/guzzlehttp-psr7)[art4/requests-psr18-adapter

Use WordPress/Requests as a PSR-18 HTTP client

153.3k](/packages/art4-requests-psr18-adapter)

PHPackages © 2026

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