From 530d672995040c320a9506a0b93258a49c4d0b29 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Thu, 13 Aug 2015 10:40:35 +0200 Subject: updated php-archive to 1.0.7 fixes #1296 --- vendor/splitbrain/php-archive/.gitignore | 3 +- vendor/splitbrain/php-archive/README.md | 14 +++++--- vendor/splitbrain/php-archive/src/Archive.php | 4 +++ vendor/splitbrain/php-archive/src/FileInfo.php | 1 + vendor/splitbrain/php-archive/src/Tar.php | 50 +++++++++++++++++++------- 5 files changed, 53 insertions(+), 19 deletions(-) (limited to 'vendor/splitbrain/php-archive') diff --git a/vendor/splitbrain/php-archive/.gitignore b/vendor/splitbrain/php-archive/.gitignore index 39b851b56..c6277c187 100644 --- a/vendor/splitbrain/php-archive/.gitignore +++ b/vendor/splitbrain/php-archive/.gitignore @@ -3,5 +3,6 @@ composer.phar vendor/ composer.lock - +apigen.phar +docs/ diff --git a/vendor/splitbrain/php-archive/README.md b/vendor/splitbrain/php-archive/README.md index 6c5780a7a..f18764b61 100644 --- a/vendor/splitbrain/php-archive/README.md +++ b/vendor/splitbrain/php-archive/README.md @@ -19,8 +19,11 @@ Usage ----- The usage for the Zip and Tar classes are basically the same. Here are some -examples for working with TARs to get you started. Check the source code -comments for more info +examples for working with TARs to get you started. + +Check the [API docs](https://splitbrain.github.io/php-archive/) for more +info. + ```php require_once 'vendor/autoload.php'; @@ -51,16 +54,17 @@ $tar->close(); // To create a TAR archive directly in memory, create() it, add*() // files and then either save() or getArchive() it: $tar = new Tar(); +$tar->setCompression(9, Archive::COMPRESS_BZIP); $tar->create(); $tar->addFile(...); $tar->addData(...); ... -$tar->save('myfile.tgz'); // compresses and saves it -echo $tar->getArchive(Archive::COMPRESS_GZIP); // compresses and returns it +$tar->save('myfile.tbz'); // compresses and saves it +echo $tar->getArchive(); // compresses and returns it ``` Differences between Tar and Zip: Tars are compressed as a whole, while Zips compress each file individually. Therefore you can call ```setCompression``` before each ```addFile()``` and ```addData()``` function call. The FileInfo class can be used to specify additional info like ownership or permissions when adding a file to -an archive. \ No newline at end of file +an archive. diff --git a/vendor/splitbrain/php-archive/src/Archive.php b/vendor/splitbrain/php-archive/src/Archive.php index c60fea777..d672cc6ec 100644 --- a/vendor/splitbrain/php-archive/src/Archive.php +++ b/vendor/splitbrain/php-archive/src/Archive.php @@ -126,3 +126,7 @@ class ArchiveIOException extends \Exception class ArchiveIllegalCompressionException extends \Exception { } + +class ArchiveCorruptedException extends \Exception +{ +} diff --git a/vendor/splitbrain/php-archive/src/FileInfo.php b/vendor/splitbrain/php-archive/src/FileInfo.php index c443aa977..612f924c3 100644 --- a/vendor/splitbrain/php-archive/src/FileInfo.php +++ b/vendor/splitbrain/php-archive/src/FileInfo.php @@ -61,6 +61,7 @@ class FileInfo $file->setMode(fileperms($path)); $file->setOwner(fileowner($path)); $file->setGroup(filegroup($path)); + $file->setSize(filesize($path)); $file->setUid($stat['uid']); $file->setGid($stat['gid']); $file->setMtime($stat['mtime']); diff --git a/vendor/splitbrain/php-archive/src/Tar.php b/vendor/splitbrain/php-archive/src/Tar.php index bd78136da..e29c7d5a6 100644 --- a/vendor/splitbrain/php-archive/src/Tar.php +++ b/vendor/splitbrain/php-archive/src/Tar.php @@ -36,6 +36,8 @@ class Tar extends Archive $this->compressioncheck($type); $this->comptype = $type; $this->complevel = $level; + if($level == 0) $this->comptype = Archive::COMPRESS_NONE; + if($type == Archive::COMPRESS_NONE) $this->complevel = 0; } /** @@ -366,7 +368,7 @@ class Tar extends Archive public function save($file) { if ($this->comptype === Archive::COMPRESS_AUTO) { - $this->setCompression($this->filetype($this->complevel, $file)); + $this->setCompression($this->complevel, $this->filetype($file)); } if (!file_put_contents($file, $this->getArchive())) { @@ -429,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); } @@ -513,15 +520,19 @@ class Tar extends Archive /** * Decode the given tar file header * - * @param string $block a 512 byte block containign the header data - * @return array|bool + * @param string $block a 512 byte block containing the header data + * @return array|false returns false when this was a null block + * @throws ArchiveCorruptedException */ protected function parseHeader($block) { if (!$block || strlen($block) != 512) { - return false; + throw new ArchiveCorruptedException('Unexpected length of header'); } + // null byte blocks are ignored + if(trim($block) === '') return false; + for ($i = 0, $chks = 0; $i < 148; $i++) { $chks += ord($block[$i]); } @@ -535,12 +546,12 @@ class Tar extends Archive $block ); if (!$header) { - return false; + throw new ArchiveCorruptedException('Failed to parse header'); } $return['checksum'] = OctDec(trim($header['checksum'])); if ($return['checksum'] != $chks) { - return false; + throw new ArchiveCorruptedException('Header does not match it\'s checksum'); } $return['filename'] = trim($header['filename']); @@ -613,7 +624,9 @@ class Tar extends Archive } /** - * Guesses the wanted compression from the given filename extension + * Guesses the wanted compression from the given file + * + * Uses magic bytes for existing files, the file extension otherwise * * You don't need to call this yourself. It's used when you pass Archive::COMPRESS_AUTO somewhere * @@ -622,14 +635,25 @@ class Tar extends Archive */ public function filetype($file) { + // for existing files, try to read the magic bytes + if(file_exists($file) && is_readable($file) && filesize($file) > 5) { + $fh = fopen($file, 'rb'); + if(!$fh) return false; + $magic = fread($fh, 5); + fclose($fh); + + if(strpos($magic, "\x42\x5a") === 0) return Archive::COMPRESS_BZIP; + if(strpos($magic, "\x1f\x8b") === 0) return Archive::COMPRESS_GZIP; + } + + // otherwise rely on file name $file = strtolower($file); if (substr($file, -3) == '.gz' || substr($file, -4) == '.tgz') { - $comptype = Archive::COMPRESS_GZIP; + return Archive::COMPRESS_GZIP; } elseif (substr($file, -4) == '.bz2' || substr($file, -4) == '.tbz') { - $comptype = Archive::COMPRESS_BZIP; - } else { - $comptype = Archive::COMPRESS_NONE; + return Archive::COMPRESS_BZIP; } - return $comptype; + + return Archive::COMPRESS_NONE; } } -- cgit v1.2.3