From: <var...@us...> - 2014-10-03 14:38:57
|
Revision: 9175 http://sourceforge.net/p/phpwiki/code/9175 Author: vargenau Date: 2014-10-03 14:38:55 +0000 (Fri, 03 Oct 2014) Log Message: ----------- gzcompress, gzuncompress, gzinflate and gzopen exist Modified Paths: -------------- trunk/lib/CachedMarkup.php trunk/lib/ziplib.php Modified: trunk/lib/CachedMarkup.php =================================================================== --- trunk/lib/CachedMarkup.php 2014-10-03 14:26:30 UTC (rev 9174) +++ trunk/lib/CachedMarkup.php 2014-10-03 14:38:55 UTC (rev 9175) @@ -49,12 +49,7 @@ return serialize($this); } - if (function_exists('gzcompress')) - return gzcompress(serialize($this), 9); - return serialize($this); - - // FIXME: probably should implement some sort of "compression" - // when no gzcompress is available. + return gzcompress(serialize($this), 9); } function unpack($packed) @@ -69,17 +64,9 @@ or (substr($packed, 0, 2) == "x\332") ) // 120, 218 { - if (function_exists('gzuncompress')) { - // Looks like ZLIB. - $data = gzuncompress($packed); - return unserialize($data); - } else { - // user our php lib. TESTME - include_once 'ziplib.php'; - $zip = new ZipReader($packed); - list(, $data, $attrib) = $zip->readFile(); - return unserialize($data); - } + // Looks like ZLIB. + $data = gzuncompress($packed); + return unserialize($data); } if (substr($packed, 0, 2) == "O:") { // Looks like a serialized object Modified: trunk/lib/ziplib.php =================================================================== --- trunk/lib/ziplib.php 2014-10-03 14:26:30 UTC (rev 9174) +++ trunk/lib/ziplib.php 2014-10-03 14:38:55 UTC (rev 9175) @@ -186,33 +186,19 @@ function zip_inflate($data, $crc32, $uncomp_size) { - if (function_exists('gzinflate')) { - $data = gzinflate($data); - if (strlen($data) != $uncomp_size) - trigger_error("not enough output from gzinflate", E_USER_ERROR); - $zcrc32 = zip_crc32($data); - if ($zcrc32 < 0) { // force unsigned - $zcrc32 += 4294967296; - } - if ($crc32 < 0) { // force unsigned - $crc32 += 4294967296; - } - if ($zcrc32 != $crc32) - trigger_error("CRC32 mismatch: calculated=$zcrc32, expected=$crc32", E_USER_ERROR); - return $data; + $data = gzinflate($data); + if (strlen($data) != $uncomp_size) + trigger_error("not enough output from gzinflate", E_USER_ERROR); + $zcrc32 = zip_crc32($data); + if ($zcrc32 < 0) { // force unsigned + $zcrc32 += 4294967296; } - - if (!function_exists('gzopen')) { - global $request; - $request->finish(_("Can't inflate data: zlib support not enabled in this PHP")); + if ($crc32 < 0) { // force unsigned + $crc32 += 4294967296; } - - // Reconstruct gzip header and ungzip the data. - $mtime = time(); //(Bogus mtime) - - return gzip_uncompress(pack("a2CxV@10", GZIP_MAGIC, GZIP_DEFLATE, $mtime) - . $data - . pack("VV", $crc32, $uncomp_size)); + if ($zcrc32 != $crc32) + trigger_error("CRC32 mismatch: calculated=$zcrc32, expected=$crc32", E_USER_ERROR); + return $data; } function unixtime2dostime($unix_time) @@ -278,18 +264,12 @@ function addRegularFile($filename, $content, $attrib = array()) { $size = strlen($content); - if (function_exists('gzopen')) { - list ($data, $crc32, $os_type) = zip_deflate($content); - if (strlen($data) < $size) { - $content = $data; // Use compressed data. - $comp_type = ZIP_DEFLATE; - } else - unset($crc32); // force plain store. - } else { - // Punt: - $os_type = 3; // 0 = FAT --- hopefully this is good enough. - /* (Another choice might be 3 = Unix) */ - } + list ($data, $crc32, $os_type) = zip_deflate($content); + if (strlen($data) < $size) { + $content = $data; // Use compressed data. + $comp_type = ZIP_DEFLATE; + } else + unset($crc32); // force plain store. if (!isset($crc32)) { $comp_type = ZIP_STORE; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |