/** * Limit the given input stream to the given number of bytes. * * @param StreamInterface $stream * @param int $limit * * @throws \InvalidArgumentException When the given limit is negative. */ public function __construct(StreamInterface $stream, $limit) { parent::__construct($stream); $this->limit = (int) $limit; if ($this->limit < 0) { throw new \InvalidArgumentException(sprintf('Limit must not be less than 0, given: %s', $this->limit)); } }
/** * Wrap the given input stream with the cache decorator. * * @param StreamInterface $stream * @param string $cacheUrl Cache file URL, defaults to "php://temp". * @param int $minBufferChunk Minimum number of bytes to read when fetching data from the underlying input stream. * * @throws \InvalidArgumentException When the given stream is not readable. */ public function __construct(StreamInterface $stream, $cacheUrl = 'php://temp', $minBufferChunk = 8192) { parent::__construct($stream); $this->buffer = $this->invokeWithErrorHandler('fopen', $cacheUrl, 'rb+'); $this->minBufferChunk = (int) $minBufferChunk; if ($this->minBufferChunk < 1) { throw new \InvalidArgumentException(sprintf('Minimum chunk size must not be less than 1, given %s', $this->minBufferChunk)); } }
/** * Decompress data as it is being read from the given input stream. * * @param StreamInterface $stream * @param int $encoding * * @throws \RuntimeException When decompression is not supported by the installed PHP version. * @throws \InvalidArgumentException When an invalid compression encoding is specified. */ public function __construct(StreamInterface $stream, $encoding = self::DEFLATE) { if (!function_exists('inflate_init')) { throw new \RuntimeException('Stream decompression requires PHP 7'); } parent::__construct($stream); switch ($encoding) { case self::RAW: case self::DEFLATE: case self::GZIP: // OK break; default: throw new \InvalidArgumentException(sprintf('Invalid decompression ecncoding specified: %s', $encoding)); } $this->context = $this->invokeWithErrorHandler('inflate_init', $encoding); }
/** * Compress data as it being read from the given input stream. * * @param StreamInterface $stream * @param int $encoding * @param int $level * @param int $window * * @throws \RuntimeException When compression is not supported by the installed PHP version. * @throws \InvalidArgumentException When compression level / window are invalid. */ public function __construct(StreamInterface $stream, $encoding = ZLIB_ENCODING_DEFLATE, $level = 1, $window = 32768) { if (!function_exists('deflate_init')) { throw new \RuntimeException('Stream compression requires PHP 7'); } parent::__construct($stream); switch ($encoding) { case self::RAW: case self::DEFLATE: case self::GZIP: // OK break; default: throw new \InvalidArgumentException(sprintf('Invalid compression ecncoding specified: %s', $encoding)); } $level = (int) $level; if ($level < 1 || $level > 9) { throw new \InvalidArgumentException(sprintf('Compression level must be between 1 and 9, given %s', $level)); } $this->context = $this->invokeWithErrorHandler('deflate_init', $encoding, ['level' => $level]); $this->window = (int) $window; }
public function __construct(StreamInterface $stream) { parent::__construct($stream); $this->md5 = hash_init('md5'); }