예제 #1
0
 /**
  * @param int $type Compression type. Use GZIP or DEFLATE constants defined in this class.
  * @param int $hwm
  *
  * @throws \Icicle\Exception\UnsupportedError If the zlib extension is not loaded.
  */
 public function __construct(int $type, int $hwm = 0)
 {
     // @codeCoverageIgnoreStart
     if (!extension_loaded('zlib')) {
         throw new UnsupportedError('zlib extension required to decode compressed streams.');
     }
     // @codeCoverageIgnoreEnd
     parent::__construct($hwm);
     switch ($type) {
         case self::GZIP:
         case self::DEFLATE:
             $this->resource = inflate_init($type);
             break;
         default:
             throw new InvalidArgumentError('Invalid compression type.');
     }
     if (null === $this->resource) {
         throw new FailureException('Could not initialize inflate handle.');
     }
 }
예제 #2
0
 /**
  * @param int $type Compression type. Use GZIP or DEFLATE constants defined in this class.
  * @param int $level Compression level.
  * @param int $hwm
  *
  * @throws \Icicle\Exception\UnsupportedError If the zlib extension is not loaded.
  * @throws \Icicle\Exception\InvalidArgumentError If the $type is not a valid compression type.
  */
 public function __construct(int $type, int $level = self::DEFAULT_LEVEL, int $hwm = 0)
 {
     // @codeCoverageIgnoreStart
     if (!extension_loaded('zlib')) {
         throw new UnsupportedError('zlib extension required to decode compressed streams.');
     }
     // @codeCoverageIgnoreEnd
     if (-1 > $level || 9 < $level) {
         throw new InvalidArgumentError('Level must be between -1 (default) and 9.');
     }
     switch ($type) {
         case self::GZIP:
         case self::DEFLATE:
             $this->resource = deflate_init($type, ['level' => $level]);
             break;
         default:
             throw new InvalidArgumentError('Invalid compression type.');
     }
     if (null === $this->resource) {
         throw new FailureException('Could not initialize deflate handle.');
     }
     parent::__construct($hwm);
 }
예제 #3
0
 /**
  * @param int $hwm
  */
 public function __construct(int $hwm = 0)
 {
     parent::__construct($hwm);
     $this->buffer = new Buffer();
 }