amphp/byte-stream
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
amphp/amp | v3.0.2 | - | MIT | prod | |
amphp/parser | v1.1.1 | - | MIT | prod | |
amphp/pipeline | v1.2.0 | - | MIT | prod | |
amphp/serialization | v1.0.0 | 5.98 kB | MIT | prod | |
amphp/sync | v2.2.0 | - | MIT | prod | |
revolt/event-loop | v1.0.6 | 35.61 kB | MIT | prod |
The amphp/byte-stream is an event-driven library designed with PHP concurrency and the fiber feature in mind, used for simplifying work with non-blocking I/O operations. The package specifically provides a stream abstraction, allowing an easy interface to work with multiple byte streams.
The amphp/byte-stream can be utilized by installing it as a Composer dependency. After installation, the package offers two fundamental interfaces: ReadableStream
and WritableStream
which are abstractions over ordered sequences of bytes.
For example, if you want to use a ReadableStream
, you can consume it as below:
$stream = ...; // the stream to be consumed
$buffer = "";
while (($chunk = $stream->read()) !== null) {
$buffer .= $chunk;
}
// use the $buffer variable for whatever you want
And when you want to use a WritableStream
:
$readableStream = ...; // the stream to be read from
$writableStream = ...; // the stream to write to
$buffer = "";
while (($chunk = $readableStream->read()) !== null) {
$writableStream->write($chunk);
}
$writableStream->end();
This package offers some basic implementations, and you can also find more in other libraries like amphp/socket
.
For detailed documentation and additional examples, users can refer to the readme content on the GitHub repository available at https://github.com/amphp/byte-stream.git. For specific examples on different implementations and usages, users can refer to the "./examples" directory present in the package's GitHub repository. It's also important to note that amphp/byte-stream follows the semver semantic versioning specification just like all other amphp packages.