summaryrefslogtreecommitdiff
path: root/inc/ZipLib.class.php
diff options
context:
space:
mode:
authorDanjer <Danjer@doudouke.org>2007-12-10 20:18:26 +0100
committerDanjer <Danjer@doudouke.org>2007-12-10 20:18:26 +0100
commit9af0f7275d707d28c7a5c9c0c81877b9a121a7b2 (patch)
tree7482668bebec37bf647cad4a3568ddf92a76c9df /inc/ZipLib.class.php
parent280adf3ebd680eadda34e9c7c5d616900d09981c (diff)
downloadrpg-9af0f7275d707d28c7a5c9c0c81877b9a121a7b2.tar.gz
rpg-9af0f7275d707d28c7a5c9c0c81877b9a121a7b2.tar.bz2
read a file from a ZIP without diskwrite
darcs-hash:20071210191826-da454-9b88e46e7ab574d605280152905f884cc64abad6.gz
Diffstat (limited to 'inc/ZipLib.class.php')
-rw-r--r--inc/ZipLib.class.php86
1 files changed, 86 insertions, 0 deletions
diff --git a/inc/ZipLib.class.php b/inc/ZipLib.class.php
index 3b39ad1b6..84164dd4a 100644
--- a/inc/ZipLib.class.php
+++ b/inc/ZipLib.class.php
@@ -349,5 +349,91 @@ class ZipLib
return ap_mkdir($d);
}
//--CS end
+
+
+ function ExtractStr($zn, $name) {
+ $ok = 0;
+ $zip = @fopen($zn,'rb');
+ if(!$zip) return(NULL);
+ $cdir = $this->ReadCentralDir($zip,$zn);
+ $pos_entry = $cdir['offset'];
+
+ for ($i=0; $i<$cdir['entries']; $i++)
+ {
+ @fseek($zip, $pos_entry);
+ $header = $this->ReadCentralFileHeaders($zip);
+ $header['index'] = $i;
+ $pos_entry = ftell($zip);
+ @rewind($zip);
+ fseek($zip, $header['offset']);
+ if ($name == $header['stored_filename'] || $name == $header['filename']) {
+ $str = $this->ExtractStrFile($header, $zip);
+ fclose($zip);
+ return $str;
+ }
+
+ }
+ fclose($zip);
+ return null;
+ }
+
+ function ExtractStrFile($header,$zip) {
+ $hdr = $this->readfileheader($zip);
+ $binary_data = '';
+ if (!($header['external']==0x41FF0010) && !($header['external']==16))
+ {
+ if ($header['compression']==0)
+ {
+ while ($size != 0)
+ {
+ $read_size = ($size < 2048 ? $size : 2048);
+ $buffer = fread($zip, $read_size);
+ $binary_data .= pack('a'.$read_size, $buffer);
+ $size -= $read_size;
+ }
+ return $binary_data;
+ } else {
+ $size = $header['compressed_size'];
+ if ($size == 0) {
+ return '';
+ }
+ //Just in case
+ if ($size > ($this->_ret_bytes(ini_get('memory_limit'))/2)) {
+ die("Compressed file is to huge to be uncompress in memory.");
+ }
+ while ($size != 0)
+ {
+ $read_size = ($size < 2048 ? $size : 2048);
+ $buffer = fread($zip, $read_size);
+ $binary_data .= pack('a'.$read_size, $buffer);
+ $size -= $read_size;
+ }
+ $str = gzinflate($binary_data, $header['size']);
+ if ($header['crc'] == crc32($str)) {
+ return $str;
+ } else {
+ die("Crc Error");
+ }
+ }
+ }
+ return NULL;
+ }
+
+ function _ret_bytes($val) {
+ $val = trim($val);
+ $last = $val{strlen($val)-1};
+ switch($last) {
+ case 'k':
+ case 'K':
+ return (int) $val * 1024;
+ break;
+ case 'm':
+ case 'M':
+ return (int) $val * 1048576;
+ break;
+ default:
+ return $val;
+ }
+ }
}