Class CachingStream
- GuzzleHttp\Psr7\CachingStream implements Psr\Http\Message\StreamInterface uses GuzzleHttp\Psr7\StreamDecoratorTrait
- Namespace: GuzzleHttp\Psr7
- Located at CachingStream.php
Stream decorator that can cache previously read bytes from a sequentially read stream.
Methods Summary
-
__construct ( Psr\Http\Message\StreamInterface $stream, Psr\Http\Message\StreamInterface $target = null )
We will treat the buffer object as the body of the stream
-
getSize ( )
Get the size of the stream if known.
-
rewind ( )
Seek to the beginning of the stream.
-
seek ( int $offset, int $whence = SEEK_SET )
Seek to a position in the stream.
-
read ( int $length )
Read data from the stream.
-
write ( string $string )
Write data to the stream.
-
eof ( )
Returns true if the stream is at the end of the stream.
-
close ( )
Close both the remote stream and buffer stream
Methods inherited from Psr\Http\Message\StreamInterface
__toString()
,
detach()
,
getContents()
,
getMetadata()
,
isReadable()
,
isSeekable()
,
isWritable()
,
tell()
Methods used from GuzzleHttp\Psr7\StreamDecoratorTrait
Methods Details
__construct (
Psr\Http\Message\StreamInterface
$stream,
Psr\Http\Message\StreamInterface
$target = null
)
We will treat the buffer object as the body of the stream
Parameters
Psr\Http\Message\StreamInterface |
$stream | Stream to cache. The cursor is assumed to be at the beginning of the stream. |
Psr\Http\Message\StreamInterface |
$target = null | Optionally specify where data is cached |
integer|null getSize ( )
Get the size of the stream if known.
Returns
integer|null Returns the size in bytes if known, or null if unknown. |
Implementation of
rewind ( )
Seek to the beginning of the stream.
If the stream is not seekable, this method will raise an exception; otherwise, it will perform a seek(0).
Exceptions
RuntimeException on failure. |
See
Link
Implementation of
seek ( integer $offset, integer $whence = SEEK_SET )
Seek to a position in the stream.
Parameters
integer | $offset | Stream offset |
integer | $whence = SEEK_SET | Specifies how the cursor position will be calculated
based on the seek offset. Valid values are identical to the built-in
PHP $whence values for |
Exceptions
RuntimeException on failure. |
Link
Implementation of
string read ( integer $length )
Read data from the stream.
Parameters
integer | $length | Read up to $length bytes from the object and return them. Fewer than $length bytes may be returned if underlying stream call returns fewer bytes. |
Returns
string Returns the data read from the stream, or an empty string if no bytes are available. |
Exceptions
RuntimeException if an error occurs. |
Implementation of
integer write ( string $string )
Write data to the stream.
Parameters
string | $string | The string that is to be written. |
Returns
integer Returns the number of bytes written to the stream. |
Exceptions
RuntimeException on failure. |
Implementation of
boolean eof ( )
Returns true if the stream is at the end of the stream.
Returns
boolean |
Implementation of
close ( )
Close both the remote stream and buffer stream