3 * BZIP2 compression and decompression class
5 class Bzip2Compressor extends BaseFrameworkSystem implements Compressor {
11 private function __construct () {
12 // Call parent constructor!
13 parent::constructor(__CLASS__);
16 if (((defined('DEBUG_COMPRESSOR')) || (defined('DEBUG_ALL'))) && (defined('DEBUG_CONSTRUCT'))) $this->getDebugInstance()->output(sprintf("[%s:] Konstruktor erreicht.<br />\n",
21 $this->setPartDescr("BZIP2-Kompressor");
23 // Create an unique ID
24 $this->createUniqueID();
28 * Create a new compressor channel based a given compression handler
30 * @return $cInstance An instance of this class
32 public final static function createBzip2Compressor () {
34 if ((function_exists('bzcompress')) && (function_exists('bzdecompress'))) {
35 // Compressor can maybe be used
36 $cInstance = new Bzip2Compressor();
39 if ((defined('DEBUG_COMPRESSOR')) || (defined('DEBUG_ALL'))) $cInstance->getDebugInstance()->output(sprintf("[%s:] BZIP2-Kompression wird verwendet.<br />\n",
40 $cInstance->__toString()
43 // Routines not found!
47 if ((defined('DEBUG_COMPRESSOR')) || (defined('DEBUG_ALL'))) $cInstance->getDebugInstance()->output(sprintf("[%s:] BZIP2-Kompressionsroutinen <strong>nicht</strong> gefunden.<br />\n",
48 $cInstance->__toString()
52 // Return the compressor instance
57 * BZIP2 compression stream
59 * @param $streamData Mixed non-object stream data
60 * @return $streamData The compressed stream data
61 * @throws InvalidObjectException If the stream is an object
63 public function compressStream ($streamData) {
64 if (is_object($streamData)) {
66 throw new InvalidObjectException($streamData, self::EXCEPTION_UNEXPECTED_OBJECT);
69 // Return the compressed stream
70 return bzcompress($streamData, 1);
74 * BZIP2 decompression stream
76 * @param $streamData Mixed non-object stream data
77 * @return $streamData The decompressed stream data
78 * @throws InvalidObjectException If the stream is an object
80 public function decompressStream ($streamData) {
81 if (is_object($streamData)) {
83 throw new InvalidObjectException($streamData, self::EXCEPTION_UNEXPECTED_OBJECT);
86 // Return the decompressed stream
87 return bzdecompress($streamData);
91 * Getter for the file extension of this compressor
93 * @return $string Returns always "bz2"
95 public final function getCompressorExtension () {
96 if ((defined('DEBUG_COMPRESSOR')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:] Dateierweiterung angefordert.<br />\n",