mirror of
https://github.com/danog/byte-stream.git
synced 2024-11-27 04:14:49 +01:00
36 lines
756 B
PHP
36 lines
756 B
PHP
|
<?php
|
||
|
|
||
|
namespace Amp\ByteStream;
|
||
|
|
||
|
use Amp\Promise;
|
||
|
|
||
|
/**
|
||
|
* An `InputStream` allows reading byte streams in chunks.
|
||
|
*
|
||
|
* **Example**
|
||
|
*
|
||
|
* ```php
|
||
|
* function readAll(InputStream $in): Promise {
|
||
|
* return Amp\call(function () use ($in) {
|
||
|
* $buffer = "";
|
||
|
*
|
||
|
* while (($chunk = yield $in->read()) !== null) {
|
||
|
* $buffer .= $chunk;
|
||
|
* }
|
||
|
*
|
||
|
* return $buffer;
|
||
|
* });
|
||
|
* }
|
||
|
* ```
|
||
|
*/
|
||
|
interface InputStream {
|
||
|
/**
|
||
|
* Reads data from the stream.
|
||
|
*
|
||
|
* @return Promise Resolves with a string when new data is available or `null` if the stream has closed.
|
||
|
*
|
||
|
* @throws PendingReadException Thrown if another read operation is still pending.
|
||
|
*/
|
||
|
public function read(): Promise;
|
||
|
}
|