/** * Execute action * * @return int */ public function perform() { $this->archive->open(Archive::CREATE); $args = $this->getArguments(); foreach ($args as $arg) { $archive = new Archive(new File($arg)); $archive->open(Archive::READ); while ($entry = $archive->getEntry()) { // Prevent overwriting earlier additions if ($this->archive->contains($entry)) { $this->err->writeLine('Warning: Duplicate entry "', $entry, '" from ', $archive->getURI(), ' - skipping.'); continue; } $data = $archive->extract($entry); $this->options & Options::VERBOSE && $this->out->writeLinef('%10s %s', number_format(strlen($data), 0, false, '.'), $entry); $this->archive->addBytes($entry, $data); } $archive->close(); } // Create, if not in simulation mode if (!($this->options & Options::SIMULATE)) { $this->archive->create(); } else { $this->archive->close(); } }
public function read_archive_with_version_1() { $a = new Archive($this->getClass()->getPackage()->getResourceAsStream('v1.xar')); $a->open(ARCHIVE_READ); $this->assertEquals(1, $a->version); $this->assertTrue($a->contains('contained.txt')); $this->assertEntries($a, array('contained.txt' => "This file is contained in an archive!\n")); }
/** * Execute action * * @return int */ public function perform() { $this->archive->open(Archive::READ); $args = $this->getArguments(); if (!isset($args[0]) || !file_exists(current($args))) { throw new IllegalArgumentException('No archive to compare given or not found.'); } $cmp = new Archive(new File(current($args))); $cmp->open(Archive::READ); return $this->compare($this->archive, $cmp); }
public function creating_archive() { $contents = ['lang/Object.class.php' => '<?php class Object { }', 'lang/Type.class.php' => '<?php class Type extends Object { }']; $out = new MemoryOutputStream(); $a = new Archive(new File(Streams::writeableFd($out))); $a->open(Archive::CREATE); foreach ($contents as $filename => $bytes) { $a->addBytes($filename, $bytes); } $a->create(); $file = new File(Streams::readableFd(new MemoryInputStream($out->getBytes()))); $this->assertEntries(new Archive($file), $contents); }
public function archive_version_1_contents() { $a = new Archive($this->getClass()->getPackage()->getResourceAsStream('v1.xar')); $a->open(Archive::READ); $this->assertEntries($a, ['contained.txt' => "This file is contained in an archive!\n"]); }
/** * Constructor * * @param lang.archive.Archive archive * @param string name */ public function __construct(Archive $archive, $name) { $archive->isOpen() || $archive->open(Archive::READ); $this->archive = $archive; $this->name = $name; }
public function creating_archive() { $contents = array('lang/Object.class.php' => 'class Object { }', 'lang/Type.class.php' => 'class Type extends Object { }'); $a = new Archive(new Stream()); $a->open(ARCHIVE_CREATE); foreach ($contents as $filename => $bytes) { $a->addFileBytes($filename, NULL, NULL, $bytes); } $a->create(); $this->assertEntries($a, $contents); }