Exemplo n.º 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());
 }