Class LimitStream
- GuzzleHttp\Psr7\LimitStream implements Psr\Http\Message\StreamInterface uses GuzzleHttp\Psr7\StreamDecoratorTrait
- Namespace: GuzzleHttp\Psr7
- Located at LimitStream.php
Decorator used to return only a subset of a stream.
Methods Summary
- __construct ( Psr\Http\Message\StreamInterface $stream, int $limit = -1, int $offset = 0 )
-
eof ( )
Returns true if the stream is at the end of the stream.
-
getSize ( )
Returns the size of the limited subset of data Get the size of the stream if known.
-
seek ( int $offset, int $whence = SEEK_SET )
Allow for a bounded seek on the read limited stream Seek to a position in the stream.
-
tell ( )
Give a relative tell() Returns the current position of the file read/write pointer
-
setOffset ( int $offset )
Set the offset to start limiting from
-
setLimit ( int $limit )
Set the limit of bytes that the decorator allows to be read from the stream.
-
read ( int $length )
Read data from the stream.
Methods inherited from Psr\Http\Message\StreamInterface
__toString()
,
close()
,
detach()
,
getContents()
,
getMetadata()
,
isReadable()
,
isSeekable()
,
isWritable()
,
rewind()
,
write()
Methods used from GuzzleHttp\Psr7\StreamDecoratorTrait
Methods Details
__construct (
Psr\Http\Message\StreamInterface
$stream,
integer
$limit = -1,
integer
$offset = 0
)
Parameters
Psr\Http\Message\StreamInterface |
$stream | Stream to wrap |
integer | $limit = -1 | Total number of bytes to allow to be read from the stream. Pass -1 for no limit. |
integer | $offset = 0 | Position to seek to before reading (only works on seekable streams). |
boolean eof ( )
Returns true if the stream is at the end of the stream.
Returns
boolean |
Implementation of
integer|null getSize ( )
Returns the size of the limited subset of data Get the size of the stream if known.
Returns
integer|null Returns the size in bytes if known, or null if unknown. |
Implementation of
seek ( integer $offset, integer $whence = SEEK_SET )
Allow for a bounded seek on the read limited stream 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. |
Implementation of
integer tell ( )
Give a relative tell() Returns the current position of the file read/write pointer
Returns
integer Position of the file pointer |
Exceptions
RuntimeException on error. |
Implementation of
setOffset ( integer $offset )
Set the offset to start limiting from
Parameters
integer | $offset | Offset to seek to and begin byte limiting from |
Exceptions
RuntimeException if the stream cannot be seeked. |
setLimit ( integer $limit )
Set the limit of bytes that the decorator allows to be read from the stream.
Parameters
integer | $limit | Number of bytes to allow to be read from the stream. Use -1 for no limit. |
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. |