Пример #1
0
 public function testCompressedStream()
 {
     $dir = $this->createTempDir("ezcArchive_");
     // $file =   $dir . "/blockfile";
     $file = "compress.zlib://" . $dir . "/blockfile";
     // Create the file.
     // Blocksize = 4.
     $bf = new ezcArchiveBlockFile($file, true, 4);
     $this->assertFalse($bf->valid());
     // Exact 1 block.
     $bf->append("abcd");
     $this->assertTrue($bf->valid());
     $this->assertEquals(0, $bf->key(), "Current block should be 0");
     $this->assertEquals(0, $bf->getLastBlockNumber(), "Last block should be 0");
     // halve block.
     $bf->append("ef");
     $this->assertEquals(1, $bf->key(), "Current block should be 1");
     $this->assertEquals(1, $bf->getLastBlockNumber(), "Last block should be 1");
     // File should contain: abcdef\0\0
     $this->assertEquals("abcdef", file_get_contents($file));
     $bf->rewind();
     $this->assertEquals(0, $bf->key(), "Current block should be 0");
     $this->assertEquals("abcd", $bf->current());
     $this->assertTrue($bf->valid());
     $this->assertEquals(1, $bf->getLastBlockNumber());
     try {
         $bf->append("ZZ");
         $this->fail("Expected an exception that the block could not be appended in the middle");
     } catch (ezcArchiveException $e) {
     }
     $bf->next();
     $bf->append("ZZ");
     $this->assertEquals(2, $bf->key(), "Current block should be 0");
     $this->assertEquals("ZZ", $bf->current());
     $this->assertTrue($bf->valid());
     $this->assertEquals(2, $bf->getLastBlockNumber());
 }
Пример #2
0
 /**
  * Returns an array with pax header information.
  *
  * This method reads an extended set of data from the ezcArchiveBlockFile
  * $file and returns the values in an array.
  *
  * @param ezcArchiveBlockFile $file
  * @return array(string=>string)
  */
 protected function getPaxDecodedHeader(ezcArchiveBlockFile $file)
 {
     $result = array();
     // next block has the info.
     $file->next();
     $data = $file->current();
     $offset = 0;
     while (strcmp($data[$offset], "") != 0) {
         $space = strpos($data, " ", $offset);
         $length = substr($data, $offset, $space - $offset);
         $equalSign = strpos($data, "=", $space);
         $keyword = substr($data, $space + 1, $equalSign - $space - 1);
         $value = rtrim(substr($data, $equalSign + 1, $length - $equalSign - 1), "\n");
         $result[$keyword] = $value;
         $offset += $length;
     }
     return $result;
 }