Copied!

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.

CloneableInstantiable
Methods
public __call(string $method, array $args)
 

Allow decorators to implement custom methods

  • return mixed
public __construct(Psr\Http\Message\StreamInterface $stream, int $limit = -1, int $offset = 0)
 
  • param \StreamInterface $stream Stream to wrap
  • param int $limit Total number of bytes to allow to be read from the stream. Pass -1 for no limit.
  • param int $offset Position to seek to before reading (only works on seekable streams).
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).

  • return \StreamInterface
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)
 
  • return mixed
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().

  • param int $length
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

  • param int $offset
  • param int $whence
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.

  • throws \BadMethodCallException
Properties
private int $limit
 
  • var int Limit the number of bytes that can be read
private int $offset
 
  • var int Offset to start reading from
private int $position = 0
 
  • var int Number of bytes written, and importantly, if non-zero, writes a final $lineEnding on close (and so maintained instead of using tell() directly)
private Psr\Http\Message\StreamInterface $stream
 
  • var \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).

© 2024 Bruce Wells
Search Namespaces \ Classes
Configuration