function readFile() { $head = $this->_read(30); extract( unpack( 'a4magic/vreq_version/vflags/vcomp_type' . '/vmod_time/vmod_date' . '/Vcrc32/Vcomp_size/Vuncomp_size' . '/vfilename_len/vextrafld_len', $head ) ); //FIXME: we should probably check $req_version. $attrib['mtime'] = dostime2unixtime($mod_date, $mod_time); if ($magic != ZIP_LOCHEAD_MAGIC) { if ($magic != ZIP_CENTHEAD_MAGIC) // FIXME: better message? ExitWiki(sprintf('Bad header type: %s', $magic)); return $this->done(); } if (($flags & 0x21) != 0) ExitWiki('Encryption and/or zip patches not supported.'); if (($flags & 0x08) != 0) // FIXME: better message? ExitWiki('Postponed CRC not yet supported.'); $filename = $this->_read($filename_len); if ($extrafld_len != 0) $attrib['extra_field'] = $this->_read($extrafld_len); $data = $this->_read($comp_size); if ($comp_type == ZIP_DEFLATE) { $data = zip_inflate($data, $crc32, $uncomp_size); } else if ($comp_type == ZIP_STORE) { $crc = zip_crc32($data); if ($crc32 != $crc) ExitWiki(sprintf('CRC mismatch %x != %x', $crc, $crc32)); } else ExitWiki(sprintf('Compression method %s unsupported', $comp_method)); if (strlen($data) != $uncomp_size) ExitWiki(sprintf('Uncompressed size mismatch %d != %d', strlen($data), $uncomp_size)); return array( $filename, $data, $attrib ); }
function readFile() { $head = $this->_read(30); // FIXME: This is bad for gzip compressed buffers extract(unpack("a4magic/vreq_version/vflags/vcomp_type" . "/vmod_time/vmod_date" . "/Vcrc32/Vcomp_size/Vuncomp_size" . "/vfilename_len/vextrafld_len", $head)); if ($magic != ZIP_LOCHEAD_MAGIC) { // maybe gzip? //$x = substr($magic,0,3); if (substr($magic, 0, 3) == "‹•") { if ($this->fp) { fclose($this->fp); $this->fp = fopen($this->zipfile, "rb"); $content = $this->_read(filesize($this->fp)); } else { $content = $this->buf; } // TODO... $data = zip_deflate($content); return array($filename, $data, $attrib); } if ($magic != ZIP_CENTHEAD_MAGIC) { // FIXME: better message? ExitWiki(sprintf("Unsupported ZIP header type: %s", $magic)); } return $this->done(); } if (($flags & 0x21) != 0) { ExitWiki("Encryption and/or zip patches not supported."); } if (($flags & 0x8) != 0) { // FIXME: better message? ExitWiki("Postponed CRC not yet supported."); } $filename = $this->_read($filename_len); //FIXME: we should probably check $req_version. $attrib['mtime'] = dostime2unixtime($mod_date, $mod_time); if ($extrafld_len != 0) { $attrib['extra_field'] = $this->_read($extrafld_len); } $data = $this->_read($comp_size); if ($comp_type == ZIP_DEFLATE) { $data = zip_inflate($data, $crc32, $uncomp_size); } else { if ($comp_type == ZIP_STORE) { $crc = zip_crc32($data); if ($crc32 != $crc) { ExitWiki(sprintf("CRC mismatch %x != %x", $crc, $crc32)); } } else { ExitWiki(sprintf("Compression method %s unsupported", $comp_method)); } } if (strlen($data) != $uncomp_size) { ExitWiki(sprintf("Uncompressed size mismatch %d != %d", strlen($data), $uncomp_size)); } return array($filename, $data, $attrib); }
function readFile() { $head = $this->_read(30); extract(unpack("a4magic/vreq_version/vflags/vcomp_type" . "/vmod_time/vmod_date" . "/Vcrc32/Vcomp_size/Vuncomp_size" . "/vfilename_len/vextrafld_len", $head)); //FIXME: we should probably check $req_version. $attrib['mtime'] = dostime2unixtime($mod_date, $mod_time); if ($magic != ZIP_LOCHEAD_MAGIC) { if ($magic != ZIP_CENTHEAD_MAGIC) { die("Bad header type: " . htmlspecialchars($magic)); } // FIXME: better message? return $this->done(); } if (($flags & 0x21) != 0) { die("Encryption and/or zip patches not supported."); } if (($flags & 0x8) != 0) { die("Postponed CRC not yet supported."); } // FIXME: ??? $filename = $this->_read($filename_len); if ($extrafld_len != 0) { $attrib['extra_field'] = $this->_read($extrafld_len); } $data = $this->_read($comp_size); if ($comp_type == ZIP_DEFLATE) { $data = zip_inflate($data, $crc32, $uncomp_size); } else { if ($comp_type == ZIP_STORE) { $crc = zip_crc32($data); if ($crc32 != $crc) { die(sprintf("CRC mismatch %x != %x", $crc, $crc32)); } } else { die("Compression method {$comp_method} unsupported"); } } if (strlen($data) != $uncomp_size) { die(sprintf("Uncompressed size mismatch %d != %d", strlen($data), $uncomp_size)); } return array($filename, $data, $attrib); }