|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZGZIPZLIBCompressionHandler class 00004 // 00005 // Created on: <13-Aug-2003 16:20:19 amos> 00006 // 00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00008 // SOFTWARE NAME: eZ Publish 00009 // SOFTWARE RELEASE: 4.0.x 00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS 00011 // SOFTWARE LICENSE: GNU General Public License v2.0 00012 // NOTICE: > 00013 // This program is free software; you can redistribute it and/or 00014 // modify it under the terms of version 2.0 of the GNU General 00015 // Public License as published by the Free Software Foundation. 00016 // 00017 // This program is distributed in the hope that it will be useful, 00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 // GNU General Public License for more details. 00021 // 00022 // You should have received a copy of version 2.0 of the GNU General 00023 // Public License along with this program; if not, write to the Free 00024 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00025 // MA 02110-1301, USA. 00026 // 00027 // 00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00029 // 00030 00031 /*! \file ezgzipzlibcompressionhandler.php 00032 */ 00033 00034 /*! 00035 \class eZGZIPZLIBCompressionHandler ezgzipzlibcompressionhandler.php 00036 \brief Handles files compressed with gzip using the zlib extension 00037 00038 More information on the zlib extension can be found here: 00039 http://www.php.net/manual/en/ref.zlib.php 00040 */ 00041 00042 //include_once( 'lib/ezfile/classes/ezcompressionhandler.php' ); 00043 00044 class eZGZIPZLIBCompressionHandler extends eZCompressionHandler 00045 { 00046 /*! 00047 */ 00048 function eZGZIPZLIBCompressionHandler() 00049 { 00050 $this->File = false; 00051 $this->Level = false; 00052 $this->eZCompressionHandler( 'GZIP (zlib)', 'gzipzlib' ); 00053 } 00054 00055 /*! 00056 Sets the current compression level. 00057 */ 00058 function setCompressionLevel( $level ) 00059 { 00060 if ( $level < 0 or $level > 9 ) 00061 $level = false; 00062 $this->Level = $level; 00063 } 00064 00065 /*! 00066 \return the current compression level which is a number between 0 and 9, 00067 or \c false if the default is to be used. 00068 */ 00069 function compressionLevel() 00070 { 00071 return $this->Level; 00072 } 00073 00074 /*! 00075 \return true if this handler can be used. 00076 This function checks if the zlib extension is available. 00077 */ 00078 static function isAvailable() 00079 { 00080 $extensionName = 'zlib'; 00081 if ( !extension_loaded( $extensionName ) ) 00082 { 00083 $dlExtension = ( eZSys::osType() == 'win32' ) ? '.dll' : '.so'; 00084 @dl( $extensionName . $dlExtension ); 00085 } 00086 return extension_loaded( $extensionName ); 00087 } 00088 00089 /*! 00090 \reimp 00091 */ 00092 function doOpen( $filename, $mode ) 00093 { 00094 $this->File = @gzopen( $filename, $mode ); 00095 return $this->File; 00096 } 00097 00098 /*! 00099 \reimp 00100 */ 00101 function doClose() 00102 { 00103 $result = @gzclose( $this->File ); 00104 $this->File = false; 00105 return $result; 00106 } 00107 00108 /*! 00109 \reimp 00110 */ 00111 function doRead( $uncompressedLength = false ) 00112 { 00113 return @gzread( $this->File, $uncompressedLength ); 00114 } 00115 00116 /*! 00117 \reimp 00118 */ 00119 function doWrite( $data, $uncompressedLength = false ) 00120 { 00121 if ( $uncompressedLength ) 00122 return @gzwrite( $this->File, $data, $uncompressedLength ); 00123 else 00124 return @gzwrite( $this->File, $data ); 00125 } 00126 00127 /*! 00128 \reimp 00129 */ 00130 function doFlush() 00131 { 00132 return @fflush( $this->File ); 00133 } 00134 00135 /*! 00136 \reimp 00137 */ 00138 function doSeek( $offset, $whence ) 00139 { 00140 if ( $whence == SEEK_CUR ) 00141 { 00142 $offset = gztell( $this->File ) + $offset; 00143 } 00144 else if ( $whence == SEEK_END ) 00145 { 00146 eZDebug::writeError( "Seeking from end is not supported for gzipped files", 00147 'eZGZIPZLIBCompressionHandler::doSeek' ); 00148 return false; 00149 } 00150 return @gzseek( $this->File, $offset ); 00151 } 00152 00153 /*! 00154 \reimp 00155 */ 00156 function doRewind() 00157 { 00158 return @gzrewind( $this->File ); 00159 } 00160 00161 /*! 00162 \reimp 00163 */ 00164 function doTell() 00165 { 00166 return @gztell( $this->File ); 00167 } 00168 00169 /*! 00170 \reimp 00171 */ 00172 function doEOF() 00173 { 00174 return @gzeof( $this->File ); 00175 } 00176 00177 /*! 00178 \reimp 00179 */ 00180 function doPasstrough( $closeFile = true ) 00181 { 00182 $result = @gzpasstru( $this->File ); 00183 if ( !$closeFile ) 00184 { 00185 // The file must be reopened because gzpasstru will close the file. 00186 $this->File = @gzopen( $this->filename(), $this->mode(), $this->isBinaryMode() ); 00187 } 00188 else 00189 $this->File = false; 00190 return $result; 00191 } 00192 00193 /*! 00194 \reimp 00195 */ 00196 function compress( $source ) 00197 { 00198 return @gzcompress( $source, $this->Level ); 00199 } 00200 00201 /*! 00202 \reimp 00203 */ 00204 function decompress( $source ) 00205 { 00206 return @gzuncompress( $source ); 00207 } 00208 00209 /*! 00210 \reimp 00211 */ 00212 function errorString() 00213 { 00214 return false; 00215 } 00216 00217 /*! 00218 \reimp 00219 */ 00220 function errorNumber() 00221 { 00222 return false; 00223 } 00224 00225 /// \privatesection 00226 /// File pointer, returned by gzopen 00227 public $File; 00228 /// The compression level 00229 public $Level; 00230 } 00231 00232 ?>