use Org\Mxchange\CoreFramework\Compressor\Compressor;
use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
-// Load SPL stuff
-use \InvalidArgumentException;
-
/**
* BZIP2 compression and decompression class
*
$compressorInstance = NULL;
// Get new instance
- if ((function_exists('bzcompress')) && (function_exists('bzdecompress'))) {
+ if (extension_loaded('bzip2')) {
// Compressor can maybe be used
$compressorInstance = new Bzip2Compressor();
}
*
* @param $streamData Mixed non-object stream data
* @return $streamData The compressed stream data
- * @throws InvalidArgumentException If the stream is not compressable or decompressable
*/
public function compressStream (string $streamData) {
- // Validate parameter
- if (is_object($streamData) || is_resource($streamData)) {
- // Throw an exception
- throw new InvalidArgumentException(sprintf('streamData[]=%s cannot be compressed/decompressed', gettype($streamData)));
- }
+ // Compress it
+ $streamData = bzcompress($streamData, 1);
// Return the compressed stream
- return bzcompress($streamData, 1);
+ return $streamData;
}
/**
*
* @param $streamData Mixed non-object stream data
* @return $streamData The decompressed stream data
- * @throws InvalidArgumentException If the stream is not compressable or decompressable
*/
public function decompressStream (string $streamData) {
- // Validate parameter
- if (is_object($streamData) || is_resource($streamData)) {
- // Throw an exception
- throw new InvalidArgumentException(sprintf('streamData[]=%s cannot be compressed/decompressed', gettype($streamData)));
- }
-
// Decompress it
$streamData = bzdecompress($streamData, true);
use Org\Mxchange\CoreFramework\Compressor\Compressor;
use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
-// Load SPL stuff
-use \InvalidArgumentException;
-
/**
* GZIP compression and decompression class
*
*
* @param $streamData Mixed non-object stream data
* @return $streamData The compressed stream data
- * @throws InvalidArgumentException If the stream is not compressable or decompressable
*/
public function compressStream (string $streamData) {
- // Validate parameter
- if (is_object($streamData) || is_resource($streamData)) {
- // Throw an exception
- throw new InvalidArgumentException(sprintf('streamData[]=%s cannot be compressed/decompressed', gettype($streamData)));
- }
+ // Compress stream
+ $streamData = gzencode($streamData, 1);
- // Return the compressed stream
- return gzencode($streamData, 1);
+ // Return it
+ return $streamData;
}
/**
*
* @param $streamData Mixed non-object stream data
* @return $streamData The decompressed stream data
- * @throws InvalidArgumentException If the stream is not compressable or decompressable
*/
public function decompressStream (string $streamData) {
- // Validate parameter
- if (is_object($streamData) || is_resource($streamData)) {
- // Throw an exception
- throw new InvalidArgumentException(sprintf('streamData[]=%s cannot be compressed/decompressed', gettype($streamData)));
- }
+ // Decompress string
+ $streamData = gzdecode($streamData);
- // Return the decompressed stream
- return gzdecode($streamData);
+ // Return it
+ return $streamData;
}
/**
use Org\Mxchange\CoreFramework\Compressor\Compressor;
use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
-// Load SPL stuff
-use \InvalidArgumentException;
-
/**
* ZLIB compression and decompression class
*
*
* @param $streamData Mixed non-object stream data
* @return $streamData The compressed stream data
- * @throws InvalidArgumentException If the stream is not compressable or decompressable
*/
public function compressStream (string $streamData) {
- // Validate parameter
- if (is_object($streamData) || is_resource($streamData)) {
- // Throw an exception
- throw new InvalidArgumentException(sprintf('streamData[]=%s cannot be compressed/decompressed', gettype($streamData)));
- }
+ // Compress string
+ $streamData = gzcompress($streamData, 1);
- // Return the compressed stream
- return gzcompress($streamData, 1);
+ // Return it
+ return $streamData;
}
/**
*
* @param $streamData Mixed non-object stream data
* @return $streamData The decompressed stream data
- * @throws InvalidArgumentException If the stream is not compressable or decompressable
*/
public function decompressStream (string $streamData) {
- // Validate parameter
- if (is_object($streamData) || is_resource($streamData)) {
- // Throw an exception
- throw new InvalidArgumentException(sprintf('streamData[]=%s cannot be compressed/decompressed', gettype($streamData)));
- }
-
// Return the decompressed stream
- return gzuncompress($streamData);
+ $streamData = gzuncompress($streamData);
+
+ // Return it
+ return $streamData;
}
/**