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