3 * GZIP compression and decompression class
5 class GzipCompressor 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("GZIP-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 createGzipCompressor () {
34 if ((function_exists('gzcompress')) && (function_exists('gzuncompress'))) {
35 // Compressor can maybe be used
36 $cInstance = new GzipCompressor();
39 if ((defined('DEBUG_COMPRESSOR')) || (defined('DEBUG_ALL'))) $cInstance->getDebugInstance()->output(sprintf("[%s:] GZIP-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:] GZIP-Kompressionsroutinen <strong>nicht</strong> gefunden.<br />\n",
48 $cInstance->__toString()
52 // Return the compressor instance
57 * GZIP 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 gzcompress($streamData, 1);
74 * GZIP 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 gzuncompress($streamData);
91 * Getter for the file extension of this compressor
93 * @return $string Returns always "gz"
95 public final function getCompressorExtension () {
96 if ((defined('DEBUG_COMPRESSOR')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:] Dateierweiterung angefordert.<br />\n",