Maintains an internal 'read' position, and seeks to it before reading, then seeks back to the original position of the underlying stream after reading if the attached stream supports seeking.
Although copied form LimitStream, it's not inherited from it since $offset and $limit are set to private on LimitStream, and most other functions are re-implemented anyway. This also decouples the implementation from upstream changes.
- Implements
Psr\Http\Message\StreamInterface Stringable - Traits
Methods |
public __call(string $method, array $args) Allow decorators to implement custom methods
|
public __construct(Psr\Http\Message\StreamInterface $stream, int $limit = -1, int $offset = 0)
|
public __get(string $name) Magic method used to create a new stream if streams are not added in the constructor of a decorator (e.g., LazyOpenStream).
|
public __toString() : string |
public close() : void |
public detach() |
public eof() : bool Returns true if the current read position is at the end of the limited stream |
public getContents() : string |
public getMetadata( $key = NULL)
|
public getSize() : ?int Returns the size of the limited subset of data, or null if the wrapped stream returns null for getSize. |
public isReadable() : bool |
public isSeekable() : bool |
public isWritable() : bool |
public read( $length) : string Reads from the underlying stream after seeking to the position within the bounds set for this limited stream. After reading, the wrapped stream is 'seeked' back to its position prior to the call to read().
|
public rewind() : void |
public seek( $offset, $whence = 0ZBateson\StreamDecorators\SEEK_SET) : void Seeks to the passed position within the confines of the limited stream's bounds. For SeekingLimitStream, no actual seek is performed on the underlying wrapped stream. Instead, an internal pointer is set, and the stream is 'seeked' on read operations
|
public seekAndRead(int $length) : string Seeks to the current position and reads up to $length bytes, or less if it would result in reading past $this->limit |
public setLimit(int $limit) : void Sets the length of the stream to the passed $limit. |
public setOffset(int $offset) : void Sets the offset to start reading from the wrapped stream. |
public tell() : int Returns the current relative read position of this stream subset. |
public write( $string) : int |
Methods |
protected createStream() : Psr\Http\Message\StreamInterface Implement in subclasses to dynamically create streams when requested.
|
Properties |
private int $limit
|
private int $offset
|
private int $position = 0
|
private Psr\Http\Message\StreamInterface $stream
|
Methods |
private doSeek(int $pos) : void Ensures the seek position specified is within the stream's bounds, and sets the internal position pointer (doesn't actually seek). |