1
0
mirror of https://github.com/splitbrain/php-archive.git synced 2025-01-17 05:28:25 +01:00

correctly skip in bzip streams. closes #9

This commit is contained in:
Andreas Gohr 2015-08-12 15:21:54 +02:00
parent 2492960566
commit c2490eaadc
2 changed files with 37 additions and 1 deletions

View File

@ -431,7 +431,12 @@ class Tar extends Archive
@gzseek($this->fh, $bytes, SEEK_CUR);
} elseif ($this->comptype === Archive::COMPRESS_BZIP) {
// there is no seek in bzip2, we simply read on
@bzread($this->fh, $bytes);
// bzread allows to read a max of 8kb at once
while($bytes) {
$toread = min(8192, $bytes);
@bzread($this->fh, $toread);
$bytes -= $toread;
}
} else {
@fseek($this->fh, $bytes, SEEK_CUR);
}

View File

@ -155,6 +155,37 @@ class Tar_TestCase extends PHPUnit_Framework_TestCase
}
}
/**
* Create an archive and unpack it again
*/
public function test_dogfood() {
foreach ($this->extensions as $ext) {
$input = glob(dirname(__FILE__) . '/../src/*');
$archive = sys_get_temp_dir() . '/dwtartest' . md5(time()) . '.' . $ext;
$extract = sys_get_temp_dir() . '/dwtartest' . md5(time() + 1);
$tar = new Tar();
$tar->create($archive);
foreach($input as $path) {
$file = basename($path);
$tar->addFile($path, $file);
}
$tar->close();
$this->assertFileExists($archive);
$tar = new Tar();
$tar->open($archive);
$tar->extract($extract, '', '/FileInfo\\.php/', '/.*\\.php/');
$this->assertFileExists("$extract/Tar.php");
$this->assertFileExists("$extract/Zip.php");
$this->assertFileNotExists("$extract/FileInfo.php");
self::rdelete($extract);
unlink($archive);
}
}
/**
* Extract the prebuilt tar files
*/