Payload
in package
implements
ReadableStream, IteratorAggregate, Stringable
uses
ReadableStreamIteratorAggregate, ForbidCloning, ForbidSerialization
Creates a buffered message from a ReadableStream.
The message can be consumed in chunks using the read() API, or it may be buffered and accessed in its entirety by calling buffer(). Once buffering is requested through buffer(), the stream cannot be read in chunks.
Tags
Table of Contents
Interfaces
- ReadableStream
- A `ReadableStream` allows reading byte streams in chunks.
- IteratorAggregate
- Stringable
Constants
- MODE_BUFFER = 2
- MODE_STREAM = 1
Properties
- $mode : int
- $onClose : DeferredFuture
- $stream : ReadableStream|string|null
Methods
- __construct() : mixed
- __destruct() : mixed
- __serialize() : never
- __toString() : string
- Buffers entire stream before returning. Use {@see self::buffer()} to optionally provide a {@see Cancellation} and/or length limit.
- __unserialize() : never
- buffer() : string
- Buffers the entire message.
- close() : void
- Closes the resource, marking it as unusable.
- getIterator() : Traversable<int, string>
- 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.
- __clone() : mixed
Constants
MODE_BUFFER
private
mixed
MODE_BUFFER
= 2
MODE_STREAM
private
mixed
MODE_STREAM
= 1
Properties
$mode
private
int
$mode
= 0
$onClose read-only
private
DeferredFuture
$onClose
$stream
private
ReadableStream|string|null
$stream
Methods
__construct()
public
__construct(ReadableStream|string $stream) : mixed
Parameters
- $stream : ReadableStream|string
__destruct()
public
__destruct() : mixed
__serialize()
public
final __serialize() : never
Return values
never__toString()
Buffers entire stream before returning. Use {@see self::buffer()} to optionally provide a {@see Cancellation} and/or length limit.
public
__toString() : string
Tags
Return values
string__unserialize()
public
final __unserialize(array<string|int, mixed> $data) : never
Parameters
- $data : array<string|int, mixed>
Return values
neverbuffer()
Buffers the entire message.
public
final buffer([Cancellation|null $cancellation = null ][, int $limit = PHP_INT_MAX ]) : string
Parameters
- $cancellation : Cancellation|null = null
- $limit : int = PHP_INT_MAX
-
Only buffer up to the given number of bytes, throwing BufferException if exceeded.
Tags
Return values
string —The entire message contents.
close()
Closes the resource, marking it as unusable.
public
close() : void
Whether pending operations are aborted or not is implementation dependent.
getIterator()
public
getIterator() : Traversable<int, string>
Return values
Traversable<int, string>isClosed()
Returns whether this resource has been closed.
public
isClosed() : bool
Return values
bool —true if closed, otherwise false.
isReadable()
public
final 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(Closure $onClose) : void
Parameters
- $onClose : Closure
read()
Reads data from the stream.
public
final 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.
Return values
string|null —Returns a string when new data is available or null if the stream has closed.
__clone()
protected
final __clone() : mixed