|
eZ Publish
[trunk]
|
00001 <?php 00002 /** 00003 * File containing the eZGZIPZLIBCompressionHandler class. 00004 * 00005 * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved. 00006 * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2 00007 * @version //autogentag// 00008 * @package lib 00009 */ 00010 00011 /*! 00012 \class eZGZIPZLIBCompressionHandler ezgzipzlibcompressionhandler.php 00013 \brief Handles files compressed with gzip using the zlib extension 00014 00015 More information on the zlib extension can be found here: 00016 http://www.php.net/manual/en/ref.zlib.php 00017 */ 00018 00019 class eZGZIPZLIBCompressionHandler extends eZCompressionHandler 00020 { 00021 function eZGZIPZLIBCompressionHandler() 00022 { 00023 $this->File = false; 00024 $this->Level = false; 00025 $this->eZCompressionHandler( 'GZIP (zlib)', 'gzipzlib' ); 00026 } 00027 00028 /*! 00029 Sets the current compression level. 00030 */ 00031 function setCompressionLevel( $level ) 00032 { 00033 if ( $level < 0 or $level > 9 ) 00034 $level = false; 00035 $this->Level = $level; 00036 } 00037 00038 /*! 00039 \return the current compression level which is a number between 0 and 9, 00040 or \c false if the default is to be used. 00041 */ 00042 function compressionLevel() 00043 { 00044 return $this->Level; 00045 } 00046 00047 /*! 00048 \return true if this handler can be used. 00049 This function checks if the zlib extension is available. 00050 */ 00051 static function isAvailable() 00052 { 00053 $extensionName = 'zlib'; 00054 if ( !extension_loaded( $extensionName ) ) 00055 { 00056 $dlExtension = ( eZSys::osType() == 'win32' ) ? '.dll' : '.so'; 00057 @dl( $extensionName . $dlExtension ); 00058 } 00059 return extension_loaded( $extensionName ); 00060 } 00061 00062 function doOpen( $filename, $mode ) 00063 { 00064 $this->File = @gzopen( $filename, $mode ); 00065 return $this->File; 00066 } 00067 00068 function doClose() 00069 { 00070 $result = @gzclose( $this->File ); 00071 $this->File = false; 00072 return $result; 00073 } 00074 00075 function doRead( $uncompressedLength = false ) 00076 { 00077 return @gzread( $this->File, $uncompressedLength ); 00078 } 00079 00080 function doWrite( $data, $uncompressedLength = false ) 00081 { 00082 if ( $uncompressedLength ) 00083 return @gzwrite( $this->File, $data, $uncompressedLength ); 00084 else 00085 return @gzwrite( $this->File, $data ); 00086 } 00087 00088 function doFlush() 00089 { 00090 return @fflush( $this->File ); 00091 } 00092 00093 function doSeek( $offset, $whence ) 00094 { 00095 if ( $whence == SEEK_CUR ) 00096 { 00097 $offset = gztell( $this->File ) + $offset; 00098 } 00099 else if ( $whence == SEEK_END ) 00100 { 00101 eZDebug::writeError( "Seeking from end is not supported for gzipped files", __METHOD__ ); 00102 return false; 00103 } 00104 return @gzseek( $this->File, $offset ); 00105 } 00106 00107 function doRewind() 00108 { 00109 return @gzrewind( $this->File ); 00110 } 00111 00112 function doTell() 00113 { 00114 return @gztell( $this->File ); 00115 } 00116 00117 function doEOF() 00118 { 00119 return @gzeof( $this->File ); 00120 } 00121 00122 function doPasstrough( $closeFile = true ) 00123 { 00124 $result = @gzpassthru( $this->File ); 00125 if ( !$closeFile ) 00126 { 00127 // The file must be reopened because gzpasstru will close the file. 00128 $this->File = @gzopen( $this->filename(), $this->mode(), $this->isBinaryMode() ); 00129 } 00130 else 00131 $this->File = false; 00132 return $result; 00133 } 00134 00135 function compress( $source ) 00136 { 00137 return @gzcompress( $source, $this->Level ); 00138 } 00139 00140 function decompress( $source ) 00141 { 00142 return @gzuncompress( $source ); 00143 } 00144 00145 function errorString() 00146 { 00147 return false; 00148 } 00149 00150 function errorNumber() 00151 { 00152 return false; 00153 } 00154 00155 /// \privatesection 00156 /// File pointer, returned by gzopen 00157 public $File; 00158 /// The compression level 00159 public $Level; 00160 } 00161 00162 ?>