elephox / stream
Elephox Stream library.
v0.7.0
2022-07-02 22:54 UTC
Requires
- php: ^8.1 <8.3
- jetbrains/phpstorm-attributes: ^1.0
- dev-develop
- 0.9.0.x-dev
- 0.8.0.x-dev
- v0.7.0
- v0.6.0
- v0.5.0
- v0.4.3
- v0.4.0
- 0.4.0-alpha5
- 0.4.0-alpha4
- 0.4.0-alpha3
- 0.4.0-alpha2
- 0.4.0-alpha1
- 0.3.27
- v0.3.25
- v0.3.24
- v0.3.23
- v0.3.22
- v0.3.21
- v0.3.20
- v0.3.18
- v0.3.17
- v0.3.16
- v0.3.15
- v0.3.14
- v0.3.13
- v0.3.12
- v0.3.11
- v0.3.10
- v0.3.9
- v0.3.8
- v0.3.7
- v0.3.6
- v0.3.5
- v0.3.4
- dev-release/0.9
- dev-release/0.8
- dev-16-psr-20-clock
- dev-18-make-servicecollection-more-extensible
- dev-release/0.6
- dev-release/0.7
- dev-release/0.5
- dev-release/0.4
- dev-release/0.3
This package is auto-updated.
Last update: 2024-11-30 02:16:36 UTC
README
This module is used by Elephox to ease the work with streams.
Examples
<?php use Elephox\Stream\StringStream; use Elephox\Stream\AppendStream; use Elephox\Stream\ResourceStream; use Elephox\Stream\EmptyStream; use Elephox\Stream\LazyStream; $stream = new StringStream('Hello World!'); $stream->eof(); // false $stream->read(5); // 'Hello' $stream->readByte(); // 32 (space) $stream->readLine(); // 'World!' (reads to eof or "\r\n") $stream->eof(); // true $stream->rewind(); // rewinds to the beginning $stream->getContents(); // 'Hello World!' $moreStreams = new AppendStream($stream, new StringStream(' And welcome to Elephox!')); $moreStreams->rewind(); $moreStreams->readAllLines(eol: " "); // ['Hello', 'World!', 'And', 'welcome', 'to', 'Elephox!'] $moreStreams->rewind(); $moreStreams->read(15); // 'Hello World! An' $moreStreams->seek(8, SEEK_END); // moves relative from end of streams $moreStreams->read(8); // 'Elephox!' // there are more stream types: // wraps stream resources $resourceStream = new ResourceStream(fopen('/etc/passwd', 'r')); // not readable, not writeable, not seekable, always empty $emptyStream = new EmptyStream(); // only executes the closure if needed $lazyStream = new LazyStream(function() { return new StringStream('Hello World!'); }); // and they are all combinable via the AppendStream: $megaStream = new AppendStream( $moreStreams, new AppendStream( $lazyStream, $resourceStream, ), ); $megaStream->getContents(); // 'Hello World! And welcome to Elephox!Hello World!' + </etc/passwd contents> $megaStream->close(); // closes all streams and releases the resources