From d2711ac334af3eb283913366a775c3cbb0708464 Mon Sep 17 00:00:00 2001 From: vargenau Date: Fri, 3 Oct 2014 14:38:55 +0000 Subject: [PATCH] gzcompress, gzuncompress, gzinflate and gzopen exist git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@9175 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- lib/CachedMarkup.php | 21 +++------------- lib/ziplib.php | 58 +++++++++++++++----------------------------- 2 files changed, 23 insertions(+), 56 deletions(-) diff --git a/lib/CachedMarkup.php b/lib/CachedMarkup.php index c2c272c4b..4ce08d52a 100644 --- a/lib/CachedMarkup.php +++ b/lib/CachedMarkup.php @@ -49,12 +49,7 @@ class CacheableMarkup extends XmlContent 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 @@ class CacheableMarkup extends XmlContent 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 diff --git a/lib/ziplib.php b/lib/ziplib.php index 4b7ce5e31..e06056882 100644 --- a/lib/ziplib.php +++ b/lib/ziplib.php @@ -186,33 +186,19 @@ function zip_deflate($content) 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; - } - - if (!function_exists('gzopen')) { - global $request; - $request->finish(_("Can't inflate data: zlib support not enabled in this PHP")); - } - - // 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)); + $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; } function unixtime2dostime($unix_time) @@ -278,18 +264,12 @@ class ZipWriter 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; -- 2.45.0