示例#1
0
 public function testCompressionFacadeCreate()
 {
     $this->assertInstanceOf(ZlibCompression::class, CompressionFacade::create(AbstractCompression::ZLIB_DEFLATE));
     try {
         CompressionFacade::create('unknown encoding');
         $this->assertTrue(false);
     } catch (CompressionNotFoundException $Ex) {
         $this->assertTrue(true);
     }
 }
示例#2
0
 /**
  * Method for unpack data
  * @param string $package packaged data
  * @return string unpackaging data
  * @throws CompressionNotFoundException when compression class not found for encoding
  * @throws IncorrectPackageFormatException when package has invalid format
  * @throws InvalidArgumentException when data is not string type
  */
 public static function unpack($package)
 {
     if (is_string($package)) {
         $packageParts = explode("\n\n", $package, 2);
         if (count($packageParts) != 2) {
             throw new IncorrectPackageFormatException('package header not found');
         }
         list($header, $compressed) = $packageParts;
         $headerParts = explode(' ', $header);
         if (count($headerParts) != 2) {
             throw new IncorrectPackageFormatException('package header invalid');
         }
         list($headerName, $encoding) = $headerParts;
         $Compression = CompressionFacade::create($encoding);
         return $Compression->decompress($compressed);
     } else {
         throw new InvalidArgumentException('package must be a string');
     }
 }