static function __static()
    {
        self::$NONE = newinstance(__CLASS__, array(0, 'NONE'), '{
        static function __static() { }
        
        public function getCompressionStream(OutputStream $out, $level= 6) {
          return $out;
        }

        public function getDecompressionStream(InputStream $in) {
          return $in;
        }
      }');
        self::$GZ = newinstance(__CLASS__, array(8, 'GZ'), '{
        static function __static() { }
        
        public function getCompressionStream(OutputStream $out, $level= 6) {
          return new DeflatingOutputStream($out, $level);
        }

        public function getDecompressionStream(InputStream $in) {
          return new InflatingInputStream($in);
        }
      }');
        self::$BZ = newinstance(__CLASS__, array(12, 'BZ'), '{
        static function __static() { }
        
        public function getCompressionStream(OutputStream $out, $level= 6) {
          return new Bz2CompressingOutputStream($out, $level);
        }

        public function getDecompressionStream(InputStream $in) {
          return new Bz2DecompressingInputStream($in);
        }
      }');
    }
 /**
  * Gets current entry
  *
  * @return  io.archive.zip.ZipEntry
  */
 public function currentEntry()
 {
     $type = $this->streamRead(4);
     switch ($type) {
         case self::FHDR:
             // Entry
             $header = unpack('vversion/vflags/vcompression/vtime/vdate/Vcrc/Vcompressed/Vuncompressed/vnamelen/vextralen', $this->streamRead(26));
             if (0 === $header['namelen']) {
                 // Prevent 0-length read.
                 $decoded = '';
             } else {
                 $name = (string) $this->streamRead($header['namelen']);
                 // Decode name from zipfile. If we find general purpose flag bit 11
                 // (EFS), the name is encoded in UTF-8, if not, we try the following:
                 // Decode from utf-8, then try cp437, and if that fails, we will use
                 // it as-is. Do this as certain vendors (Java e.g.) always use utf-8
                 // but do not indicate this via EFS.
                 $decoded = $this->decodeName($name, $header['flags'] & 2048 ? array('utf-8') : array('utf-8', 'cp437'));
             }
             $extra = $this->streamRead($header['extralen']);
             $date = $this->dateFromDosDateTime($header['date'], $header['time']);
             $this->skip = $header['compressed'];
             // Short-circuit here for directories
             if ('/' === substr($name, -1)) {
                 $e = new ZipDirEntry($decoded);
                 $e->setLastModified($date);
                 $e->setSize($header['uncompressed']);
                 return $e;
             }
             // Bit 3: If this bit is set, the fields crc-32, compressed
             // size and uncompressed size are set to zero in the local
             // header.  The correct values are put in the data descriptor
             // immediately following the compressed data.
             if ($header['flags'] & 8) {
                 if (!isset($this->index[$name])) {
                     $position = $this->position;
                     $offset = $this->readCentralDirectory();
                     $this->streamPosition($position);
                 }
                 if (!isset($this->index[$name])) {
                     throw new FormatException('.zip archive broken: cannot find "' . $name . '" in central directory.');
                 }
                 $header = $this->index[$name];
                 // In case we're here, we can be sure to have a
                 // RandomAccessStream - otherwise the central directory
                 // could not have been read in the first place. So,
                 // we may seek.
                 // If we had strict type checking this would not be
                 // possible, though.
                 // The offset is relative to the file begin - but also skip over the usual parts:
                 // * file header signature (4 bytes)
                 // * file header (26 bytes)
                 // * file extra + file name (variable size)
                 $this->streamPosition($header['offset'] + 30 + $header['extralen'] + $header['namelen']);
                 // Set skip accordingly: 4 bytes data descriptor signature + 12 bytes data descriptor
                 $this->skip = $header['compressed'] + 16;
             }
             // Bit 1: The file is encrypted
             if ($header['flags'] & 1) {
                 $cipher = new ZipCipher($this->password);
                 $preamble = $cipher->decipher($this->streamRead(12));
                 // Verify
                 if (ord($preamble[11]) !== ($header['crc'] >> 24 & 0xff)) {
                     throw new IllegalArgumentException('The password did not match (' . ord($preamble[11]) . ' vs. ' . ($header['crc'] >> 24 & 0xff) . ')');
                 }
                 // Password matches.
                 $this->skip -= 12;
                 $header['compressed'] -= 12;
                 $is = new DecipheringInputStream(new ZipFileInputStream($this, $this->position, $header['compressed']), $cipher);
             } else {
                 $is = new ZipFileInputStream($this, $this->position, $header['compressed']);
             }
             // Create ZipEntry object and return it
             $e = new ZipFileEntry($decoded);
             $e->setLastModified($date);
             $e->setSize($header['uncompressed']);
             $e->setCompression(Compression::getInstance($header['compression']));
             $e->is = $is;
             return $e;
         case self::DHDR:
             // Zip directory
             return NULL;
             // XXX: For the moment, ignore directory and stop here
         case self::EOCD:
             // End of central directory
             return NULL;
     }
     throw new FormatException('Unknown byte sequence ' . addcslashes($type, ".."));
 }
 public function unknownInstance()
 {
     Compression::getInstance(-1);
 }
 /**
  * Sets compression method
  *
  * @param   io.archive.zip.Compression compression
  * @param   int level default 6
  * @return  io.archive.zip.ZipFileOutputStream this
  */
 public function withCompression(Compression $compression, $level = 6)
 {
     $this->data = new MemoryOutputStream();
     $this->compression = $compression->getCompressionStream($this->data, $level);
     return $this;
 }
Example #5
0
 /**
  * Outgoing packet handler
  */
 public static function out($client, $packet, $lot = array(), $dontConvert = false, $dontCompress = false)
 {
     $err = null;
     if (false === $dontCompress && isset(UltimaPHP::$socketClients[$client]['compressed']) && true === UltimaPHP::$socketClients[$client]['compressed']) {
         $compression = new Compression();
         $packet = unpack('H*', $compression->compress(strtoupper($packet)))[1];
     }
     if (false === $dontConvert) {
         $packet = Functions::hexToChr($packet);
     } else {
         $packet = $packet;
     }
     if (is_array($lot) && count($lot) == 2 && isset($lot[0]) && isset($lot[1]) && true === $lot[0] && $lot[1] === false) {
         UltimaPHP::$socketClients[$client]['packetLot'] .= $packet;
         $packet = null;
     } else {
         if (is_array($lot) && count($lot) == 2 && isset($lot[0]) && isset($lot[1]) && true === $lot[0] && $lot[1] === true) {
             $packet = UltimaPHP::$socketClients[$client]['packetLot'] . $packet;
             UltimaPHP::$socketClients[$client]['packetLot'] = null;
         }
     }
     if ($packet !== null) {
         if (true === UltimaPHP::$conf['logs']['debug']) {
             echo "Sending packet: " . Functions::strToHex($packet) . "\n\n";
         }
         UltimaPHP::$socketClients[$client]['packets'][] = array('packet' => $packet, 'time' => microtime(true) + 0.001);
     }
 }