spiral/streams
spatial/streams is a lightweight PHP stream utility for working with data as readable/writable streams. It provides simple abstractions to compose, transform, and pipe stream content, useful for file handling, IO workflows, and integrating stream-based APIs.
This package provides PSR-7-compliant stream wrapper implementations for PHP—specifically, it supplies lightweight, reusable stream classes (Stream, BufferedStream, TemporaryStream, etc.) that implement Psr\Http\Message\StreamInterface. Since it's a subtree split of the Spiral Framework’s Streams component and is now archived/readonly, it's primarily useful in legacy Spiral applications or projects requiring minimal PSR-7 stream dependencies.
To begin:
composer require spiral/streamsStreamInterface usage wherever streams are needed (e.g., HTTP clients, middleware, file processing)Spiral\Streams\Stream::create($resourceOrString) to instantiate streams from strings or resourcesThe most common first use case is as a dependency for PSR-17/PSR-15/PSR-7 tooling—e.g., creating response bodies or request payloads in middleware.
Stream::create() instead of manually instantiating—this handles resource detection and proper initialization.BufferedStream for streams that require repeated reads without seeking or copying.TemporaryStream provides safe temp file handling.Typical workflow:
$stream = Spiral\Streams\Stream::create(fopen('php://temp', 'r+'));
$stream->write(json_encode($payload));
$response = new Response($stream, 200, ['Content-Type' => 'application/json']);
symfony/http-foundation’s StreamedResponse, nyholm/psr7, or guzzlehttp/psr7 for new projects—these have broader ecosystem support and active maintenance.StreamDecoratorTrait or advanced adapters). Only core stream classes are present.fopen()-returned resources—ensure they’re binary-safe ('rb' or 'r+b') to avoid line-ending translation issues on Windows.$stream->detach() to retrieve the underlying resource for logging or third-party tools (e.g., stream_get_contents()).Stream class—e.g., wrap it in a decorator to add encryption or compression. Avoid subclassing unless needed; composition is safer and more testable."spiral/streams": "^1.0"How can I help you explore Laravel packages today?