Ejemplo n.º 1
0
 public function testCrc32FromFile()
 {
     $this->createTempDir("ezcArchive_");
     $dir = $this->getTempDir();
     file_put_contents("{$dir}/crc32file.txt", $this->testString);
     $crcExpected = ezcArchiveChecksums::getCrc32FromString(file_get_contents("{$dir}/crc32file.txt"));
     $crc = ezcArchiveChecksums::getCrc32FromFile("{$dir}/crc32file.txt");
     $this->assertEquals($crcExpected, $crc);
 }
Ejemplo n.º 2
0
 /**
  * Sets this header with the values from the ezcArchiveEntry $entry.
  *
  * The values that are possible to set from the ezcArchiveEntry $entry are set in this header.
  *
  * @param ezcArchiveEntry $entry
  * @return void
  */
 public function setHeaderFromArchiveEntry(ezcArchiveEntry $entry)
 {
     $this->version = 10;
     // FIXME
     $this->bitFlag = 0;
     // FIXME
     $this->atime = $entry->getAccessTime();
     $this->groupId = $entry->getGroupId();
     $this->userId = $entry->getUserId();
     $this->setModificationTime($entry->getModificationTime());
     if ($entry->isSymLink()) {
         $this->uncompressedSize = strlen($entry->getLink());
         $this->crc = ezcArchiveChecksums::getCrc32FromString($entry->getLink());
     } else {
         $this->uncompressedSize = $entry->getSize();
         $this->crc = ezcArchiveChecksums::getCrc32FromFile($entry->getPath());
     }
     $this->setFileName($entry->getPath(false));
 }
Ejemplo n.º 3
0
 /**
  * Returns the encoded header as given as the parameter $encodedHeader but includes the
  * checksum of the header.
  *
  * The encoded header $encodedHeader should have spaces at the place where the checksum should be stored.
  *
  * @param string $encodedHeader
  * @return string
  */
 protected function setChecksum($encodedHeader)
 {
     $total = ezcArchiveChecksums::getTotalByteValueFromString($encodedHeader);
     $checksum = pack("a7", str_pad(decoct($total), 6, "0", STR_PAD_LEFT));
     $checksum .= " ";
     $begin = substr($encodedHeader, 0, 148);
     $end = substr($encodedHeader, 156);
     return $begin . $checksum . $end;
 }