Пример #1
0
 /**
  * Chunk encode data as it is being written to the given output stream.
  * 
  * @param StreamInterface $stream
  * @param int $chunkSize
  * 
  * @throws \InvalidArgumentException When the given chunk size is too small.
  */
 public function __construct(StreamInterface $stream, $chunkSize = self::DEFAULT_CHUNK_SIZE)
 {
     parent::__construct($stream);
     $this->chunkSize = (int) $chunkSize;
     if ($this->chunkSize < 16) {
         throw new \InvalidArgumentException(sprintf('Chunk size must not be less than 16, given %s (you can use flush() to send smaller chunks as needed)', $this->chunkSize));
     }
 }
Пример #2
0
 /**
  * Decompress data as it is being written.
  * 
  * @param StreamInterface $stream
  * @param int $encoding
  * 
  * @throws \RuntimeException When decompression is not supported by the installed PHP version.
  * @throws \InvalidArgumentException When the given compression encoding is invalid.
  */
 public function __construct(StreamInterface $stream, $encoding = ZLIB_ENCODING_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);
 }
Пример #3
0
 /**
  * Compress data as it is being written to the given output 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 encoding or level is invalid.
  */
 public function __construct(StreamInterface $stream, $encoding = self::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;
 }