iqb / substream
PHP stream wrapper for using only a portion of a stream.
Installs: 294
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 1
pkg:composer/iqb/substream
Requires
- php: >=7.2
Requires (Dev)
- phpunit/phpunit: ^8
This package is auto-updated.
Last update: 2025-12-19 19:47:25 UTC
README
Issues/pull requests
This repository is a subtree split of the iqb/Morgue repository so it can be required as a standalone package via composer. To open an issues or pull request, please go to the iqb/Morgue repository.
Installation
Via composer:
composer require iqb/substream
Usage
The stream wrapper is registered for the iqb.substream:// protocol.
To use as substream, just open a new like that:
use const iqb\stream\SUBSTREAM_SCHEME; $originalStream = fopen('filename', 'r'); $offset = 25; $length = 100; // Provide the stream via a stream context $context = stream_context_create([SUBSTREAM_SCHEME => ['stream' => $originalStream]]); $substream = fopen(SUBSTREAM_SCHEME . "://$offset:$length", "r", false, $context); // Alternatively, you can just put the stream into the URL $substream = fopen(SUBSTREAM_SCHEME . "://$offset:$length/$originalStream", "r"); fseek($orignalStream, 50); fseek($substream, 25); // Will not fail assert(fread($originalStream, 50) === fread($substream, 50));