Documentation

ReadableStream extends Closable, Traversable
in

A `ReadableStream` allows reading byte streams in chunks.

Example

function readAll(ReadableStream $source): string {
    $buffer = "";

    while (null !== $chunk = $source->read()) {
        $buffer .= $chunk;
    }

    return $buffer;
}
Tags
extends

Table of Contents

Methods

close()  : void
Closes the resource, marking it as unusable.
isClosed()  : bool
Returns whether this resource has been closed.
isReadable()  : bool
onClose()  : void
Registers a callback that is invoked when this resource is closed.
read()  : string|null
Reads data from the stream.

Methods

close()

Closes the resource, marking it as unusable.

public close() : void

Whether pending operations are aborted or not is implementation dependent.

isClosed()

Returns whether this resource has been closed.

public isClosed() : bool
Return values
bool

true if closed, otherwise false.

isReadable()

public isReadable() : bool
Return values
bool

A stream may become unreadable if the underlying source is closed or lost.

onClose()

Registers a callback that is invoked when this resource is closed.

public onClose(callable(): void $onClose) : void
Parameters
$onClose : callable(): void

read()

Reads data from the stream.

public read([Cancellation|null $cancellation = null ]) : string|null
Parameters
$cancellation : Cancellation|null = null

Cancel the read operation. The state in which the stream will be after a cancelled operation is implementation dependent.

Tags
throws
PendingReadError

Thrown if another read operation is still pending.

throws
StreamException

If the stream contains invalid data, e.g. invalid compression

Return values
string|null

Returns a string when new data is available or null if the stream has closed.


        
On this page

Search results