コード例 #1
0
ファイル: kzip.php プロジェクト: sunlight-cms/sunlight-cms-7
 /**
  * Pack file stream
  * @internal
  *
  * @param  int   $compr compression type
  * @param  array $file  file data
  * @return array array(handle, path)
  */
 protected function _pack_stream($compr, $file)
 {
     // get stream
     $stream = new KZipStream($file[0] === self::FILE_REAL ? $this->handle : null, $file);
     // create temporary file
     $tmp = _tmpFile();
     // read
     while (!$stream->eof()) {
         // load chunk
         if ($compr === self::COMPR_NONE) {
             $read = $stream->read();
         } else {
             // compress
             $read = $stream->read(self::STREAM_CBUFFER);
             switch ($compr) {
                 case self::COMPR_DEFLATE:
                     $read = gzdeflate($read, $this->compr_level);
                     break;
             }
             $read = pack('V', strlen($read)) . $read;
         }
         // write to temporary file
         fwrite($tmp[0], $read);
         $read = '';
     }
     // free stream, reset and return tmpfile
     $stream->free();
     fseek($tmp[0], 0);
     return $tmp;
 }