3 namespace Org\Mxchange\CoreFramework\Compressor\Gzip;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Compressor\Compressor;
7 use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
10 * GZIP compression and decompression class
12 * @author Roland Haeder <webmaster@shipsimu.org>
14 <<<<<<< HEAD:framework/main/classes/compressor/class_GzipCompressor.php
15 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
17 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2016 Core Developer Team
18 >>>>>>> Some updates::inc/main/classes/compressor/class_GzipCompressor.php
19 * @license GNU GPL 3.0 or any newer version
20 * @link http://www.shipsimu.org
22 * This program is free software: you can redistribute it and/or modify
23 * it under the terms of the GNU General Public License as published by
24 * the Free Software Foundation, either version 3 of the License, or
25 * (at your option) any later version.
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
32 * You should have received a copy of the GNU General Public License
33 * along with this program. If not, see <http://www.gnu.org/licenses/>.
35 class GzipCompressor extends BaseFrameworkSystem implements Compressor {
37 * Protected constructor
41 protected function __construct () {
42 // Call parent constructor!
43 parent::__construct(__CLASS__);
47 * Create a new compressor channel based a given compression handler or NULL if the required PHP functions are not found.
49 * @return $compressorInstance An instance of this class or NULL if the required PHP functions are not found.
51 public static final function createGzipCompressor () {
52 // Routines not found by default
53 $compressorInstance = NULL;
56 if ((function_exists('gzencode')) && (function_exists('gzdecode'))) {
57 // Compressor can maybe be used
58 $compressorInstance = new GzipCompressor();
61 // Return the compressor instance
62 return $compressorInstance;
66 * GZIP compression stream
68 * @param $streamData Mixed non-object stream data
69 * @return $streamData The compressed stream data
70 * @throws InvalidObjectException If the stream is an object
72 public function compressStream ($streamData) {
73 if (is_object($streamData)) {
75 throw new InvalidObjectException($streamData, self::EXCEPTION_UNEXPECTED_OBJECT);
78 // Return the compressed stream
79 return gzencode($streamData, 1);
83 * GZIP decompression stream
85 * @param $streamData Mixed non-object stream data
86 * @return $streamData The decompressed stream data
87 * @throws InvalidObjectException If the stream is an object
89 public function decompressStream ($streamData) {
90 if (is_object($streamData)) {
92 throw new InvalidObjectException($streamData, self::EXCEPTION_UNEXPECTED_OBJECT);
95 // Return the decompressed stream
96 return gzdecode($streamData);
100 * Getter for the file extension of this compressor
102 * @return $string Returns always 'gz'
104 public final function getCompressorExtension () {