Copied!

A version of Guzzle's CachingStream that will read bytes from one stream, write them into another decorated stream, and read them back from a 3rd, undecorated, buffered stream where the bytes are written to.

A read operation is basically:

Read from A, write to B (which decorates C), read and return from C (which is backed by a BufferedStream).

Note that the DecoratedCachingStream doesn't support write operations.

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

Allow decorators to implement custom methods

  • return mixed
public __construct(Psr\Http\Message\StreamInterface $stream, callable $decorator, int $minBytesCache = 16384)
 
  • param \StreamInterface $stream Stream to cache. The cursor is assumed to be at the beginning of the stream.
  • param callable $decorator takes the passed StreamInterface and decorates it, and returns the decorated StreamInterface
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
 

Close both the remote stream and buffer stream

public detach()
public eof() : bool
public getContents() : string
public getMetadata( $key = NULL)
 
  • return mixed
public getSize() : ?int
public isReadable() : bool
public isSeekable() : bool
public isWritable() : bool
public read( $length) : string
public rewind() : void
public seek( $offset, $whence = 0ZBateson\StreamDecorators\SEEK_SET) : void
public tell() : int
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 $minBytesCache
 
  • var int Minimum buffer read length. At least this many bytes will be read and cached into $writeStream on each call to read from $readStream
private Psr\Http\Message\StreamInterface $readStream
 
  • var \StreamInterface the stream to read from and fill writeStream with
private Psr\Http\Message\StreamInterface $stream
 
  • var \StreamInterface the underlying undecorated stream to read from, where $writeStream is being written to
private ?Psr\Http\Message\StreamInterface $writeStream
 
  • var \StreamInterface decorated $stream that will be written to for caching that wraps $stream. Once filled, the stream is closed so it supports a Base64Stream which writes bytes at the end.
Methods
private cacheBytes(int $size) : void
private cacheEntireStream() : int
© 2025 Bruce Wells
Search Namespaces \ Classes
Configuration