1
0
mirror of https://github.com/danog/byte-stream.git synced 2024-11-26 11:54:54 +01:00

Make BufferedReader implement ReadableStream

This commit is contained in:
Daniil Gentili 2023-08-30 14:31:15 +02:00
parent 2406ec614c
commit ffbb65abd7
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7

View File

@ -6,8 +6,9 @@ use Amp\Cancellation;
use Amp\ForbidCloning;
use Amp\ForbidSerialization;
final class BufferedReader
final class BufferedReader implements ReadableStream, \IteratorAggregate
{
use ReadableStreamIteratorAggregate;
use ForbidCloning;
use ForbidSerialization;
@ -20,6 +21,35 @@ final class BufferedReader
) {
}
/**
* Closes the resource, marking it as unusable.
* Whether pending operations are aborted or not is implementation dependent.
*/
public function close(): void
{
$this->stream->close();
}
/**
* Returns whether this resource has been closed.
*
* @return bool {@code true} if closed, otherwise {@code false}
*/
public function isClosed(): bool
{
return $this->stream->isClosed();
}
/**
* Registers a callback that is invoked when this resource is closed.
*
* @param \Closure():void $onClose
*/
public function onClose(\Closure $onClose): void
{
$this->stream->onClose($onClose);
}
/**
* @template TString as string|null
*