Пример #1
0
 /**
  * Public for testing purposes only.
  *
  * @param string $data
  * @return string
  */
 public function _decodeData($data)
 {
     $this->profilerStart(__METHOD__);
     switch (substr($data, 0, 4)) {
         // asking the data which library it uses allows for transparent changes of libraries
         case ':sn:':
             $data = snappy_uncompress(substr($data, 4));
             break;
         case ':lz:':
             $data = lzf_decompress(substr($data, 4));
             break;
         case ':l4:':
             $data = lz4_uncompress(substr($data, 4));
             break;
         case ':gz:':
             $data = gzuncompress(substr($data, 4));
             break;
     }
     $this->profilerStop(__METHOD__);
     return $data;
 }
Пример #2
0
 /**
  * Decode data
  *
  * @param string $data
  * @return string
  */
 protected function _decodeData($data)
 {
     switch (substr($data, 0, 4)) {
         // asking the data which library it uses allows for transparent changes of libraries
         case ':sn:':
             $data = snappy_uncompress(substr($data, 4));
             break;
         case ':lz:':
             $data = lzf_decompress(substr($data, 4));
             break;
         case ':l4:':
             $data = lz4_uncompress(substr($data, 4));
             break;
         case ':gz:':
             $data = gzuncompress(substr($data, 4));
             break;
     }
     return $data;
 }
Пример #3
0
 /**
  * Decompress data
  *
  * @param string $data
  * @return string
  * @throws Exception
  */
 protected function decompress($data)
 {
     switch ($this->compression) {
         case self::COMPRESSION_LZ4:
             $decompressedData = @lz4_uncompress($data);
             if (false === $decompressedData) {
                 throw new Exception('Error decompressing with lz4_uncompress.');
             }
             break;
         case self::COMPRESSION_SNAPPY:
             $decompressedData = @snappy_uncompress($data);
             if (false === $decompressedData) {
                 throw new Exception('Error decompressing with snappy_uncompress.');
             }
             break;
         case self::COMPRESSION_LZF:
             $decompressedData = @lzf_decompress($data);
             if (false === $decompressedData) {
                 throw new Exception('Error decompressing with lzf_decompress.');
             }
             break;
         case self::COMPRESSION_GZ:
             $decompressedData = @gzuncompress($data);
             if (false === $decompressedData) {
                 throw new Exception('Error decompressing with gzuncompress.');
             }
             break;
         case self::COMPRESSION_NONE:
         default:
             $decompressedData = $data;
     }
     return $decompressedData;
 }
Пример #4
0
VERIFY(strlen($t) < strlen($s));
$u = nzuncompress($t);
VS($u, $s);
$compressable = str_repeat('\\0', 1024);
$bs = $compressable;
$bt = nzcompress($bs);
VERIFY(strlen($bt) < strlen($bs));
$bu = nzuncompress($bt);
VS($bu, $bs);
VS(count($bu), count($bs));
//////////////////////////////////////////////////////////////////////
$s = "garbage stuff";
$v = nzuncompress($s);
VERIFY($v == false);
$empty = "";
$c = nzcompress($empty);
$d = nzuncompress($c);
VERIFY($d == $empty);
VS(lz4_uncompress(lz4_compress("testing lz4_compress")), "testing lz4_compress");
VS(lz4_uncompress(lz4_hccompress("testing lz4_hccompress")), "testing lz4_hccompress");
// first test uncompressing invalid string
$s = "invalid compressed string";
$v = lz4_uncompress($s);
VERIFY($v == false);
// try uncompressing empty string
$empty = "";
$v = lz4_uncompress($empty);
VERIFY($v == false);
$c = lz4_compress($empty);
$d = lz4_uncompress($c);
VERIFY($d == $empty);
Пример #5
0
 /**
  * Create memory stream from input file content
  * @return void
  */
 private function createMemoryStream()
 {
     if ($this->inputFileData !== null) {
         // Create memory stream
         $this->memoryStream = null;
         $this->memoryStreamSize = 0;
         try {
             $this->memoryStream = fopen("php://memory", 'r+');
             $this->memoryStreamSize = fputs($this->memoryStream, $this->method == self::COMPRESS ? lz4_compress($this->inputFileData, $this->compressionLevel) : lz4_uncompress($this->inputFileData));
             rewind($this->memoryStream);
             if ($this->method == self::DECOMPRESS && !$this->AllowFileOutput && ($contentType = $this->getStreamContentType()) !== self::TEXT_TYPE) {
                 fclose($this->memoryStream);
                 $this->memoryStream = null;
                 $this->errors[] = sprintf('Bad decoded content type detected, expected "%s" found "%s"', self::TEXT_TYPE, $contentType);
             }
         } catch (Exception $e) {
             $this->errors[] = $e->getMessage();
         }
         // Free memory
         unset($this->inputFileData);
         $this->inputFileData = null;
     }
 }