Exemplo n.º 1
0
 /**
  * Serializes this header and appends it to the given ezcArchiveCharacterFile $archiveFile.
  *
  * @param ezcArchiveCharacterFile $archiveFile
  * @return void
  */
 public function writeEncodedHeader($archiveFile)
 {
     $this->properties["extraFieldLength"] = 13;
     // 9 + 4.
     $enc = pack("VvvvvvvVVVvvvvvVV", self::magic, $this->versionMadeBy, $this->versionNeededToExtract, $this->bitFlag, $this->compressionMethod, $this->lastModFileTime, $this->lastModFileDate, $this->crc, $this->compressedSize, $this->uncompressedSize, $this->fileNameLength, $this->extraFieldLength, $this->fileCommentLength, $this->diskNumberStart, $this->internalFileAttributes, $this->externalFileAttributes, $this->relativeHeaderOffset);
     $time = pack("vvcV", self::EF_TIME, 5, 1, $this->mtime);
     // fixme atime?
     $unix2 = pack("vv", self::EF_IZUNIX2, 0);
     // Add empty unix2 stamp.
     $archiveFile->write($enc . $this->fileName . $time . $unix2 . $this->comment);
 }
Exemplo n.º 2
0
 /**
  * Serializes this header and appends it to the given ezcArchiveCharacterFile $archiveFile.
  *
  * @param ezcArchiveCharacterFile $archiveFile
  * @return void
  */
 public function writeEncodedHeader($archiveFile)
 {
     $this->properties["extraFieldLength"] = 21;
     // FIXME.
     $enc = pack("VvvvvvVVVvv", self::magic, $this->properties["version"], $this->properties["bitFlag"], $this->properties["compressionMethod"], $this->properties["lastModFileTime"], $this->properties["lastModFileDate"], $this->properties["crc"], $this->properties["compressedSize"], $this->properties["uncompressedSize"], $this->properties["fileNameLength"], $this->properties["extraFieldLength"]);
     $time = pack("vvcVV", self::EF_TIME, 9, 3, $this->mtime, $this->atime);
     // set accesss time to modification time.
     $unix2 = pack("vvvv", self::EF_IZUNIX2, 4, $this->userId, $this->groupId);
     $archiveFile->write($enc . $this->fileName . $time . $unix2);
 }
 /**
  * Serializes this header and appends it to the given ezcArchiveCharacterFile $archiveFile.
  *
  * @param ezcArchiveCharacterFile $archiveFile
  * @return void
  */
 public function writeEncodedHeader($archiveFile)
 {
     $enc = pack("VvvvvVVv", self::magic, $this->properties["diskNumber"], $this->properties["centralDirectoryDisk"], $this->properties["totalCentralDirectoryEntriesOnDisk"], $this->properties["totalCentralDirectoryEntries"], $this->properties["centralDirectorySize"], $this->properties["centralDirectoryStart"], $this->properties["commentLength"]);
     $archiveFile->write($enc . $this->properties["comment"]);
 }
Exemplo n.º 4
0
 public function testWrite()
 {
     $dir = $this->createTempDir("ezcArchive_");
     $file = $dir . "/myfile.txt";
     $char = new ezcArchiveCharacterFile($file, true);
     $char->write("ab");
     $char->write("cd");
     $this->assertEquals("abcd", file_get_contents($file));
     $char->seek(2);
     $this->assertEquals("c", $char->current());
     $char->append("De");
     $this->assertEquals("abcDe", file_get_contents($file));
     $this->assertTrue($char->valid());
     $this->assertEquals("c", $char->current());
     $char->seek(3);
     $this->assertEquals("D", $char->current());
     $char->seek(2);
     $this->assertEquals("c", $char->current());
     $char->write("Cde");
     $this->assertEquals("abCde", file_get_contents($file));
     unset($char);
     $this->removeTempDir();
 }
Exemplo n.º 5
0
 /**
  * Reads the file data from the archive and writes it the the $writeTo file.
  *
  * The data from the entry with $fileNumber is read from the archive.
  * If the data is compressed or deflated it will be, respectively, decompressed or inflated.
  *
  * @throws ezcArchiveChecksumException if the checksum is invalid from the created file.
  *
  * @param   int     $fileNumber
  * @param   string  $writeTo
  * @return  void
  */
 public function writeFile($fileNumber, $writeTo)
 {
     $header = $this->getLocalHeader($fileNumber);
     $pos = $this->localHeaderPositions[$fileNumber] + $header->getHeaderSize();
     // FIXME.. don't write the entire stuff to memory.
     $this->file->seek($pos);
     /*
     Part: 1
     - Append the stream filter.
     switch ( $header->compressionMethod )
     {
         case 8:  $this->file->appendStreamFilter( "zlib.inflate" ); break;
         case 12: $this->file->appendStreamFilter( "bzip2.decompress" ); break;
     }
     */
     $data = $this->file->read($header->compressedSize);
     /*
     Part: 2
     - And remove the stream filter.
     - Then we can write the file directly from the archive without copying it entirely to memory.
     - Unfortunately, this method segfaults for me.
     
     if ( $header->compressionMethod == 8  || $header->compressionMethod == 12 )
     {
         $this->file->removeStreamFilter();
     }
     */
     if ($data) {
         switch ($header->compressionMethod) {
             case 8:
                 $data = gzinflate($data);
                 break;
                 // Evil, memory consuming.
             // Evil, memory consuming.
             case 12:
                 $data = bzdecompress($data);
                 break;
         }
     }
     if (strcmp(sprintf("%u", crc32($data)), sprintf("%u", $header->crc & 0xffffffff)) == 0) {
         $newFile = new ezcArchiveCharacterFile($writeTo, true);
         $newFile->write($data);
         unset($newFile);
     } else {
         throw new ezcArchiveChecksumException($writeTo);
     }
 }