From ac20d6fbf3d05e93a65e83b370547f97bcf7c516 Mon Sep 17 00:00:00 2001 From: Ne-Lexa <alexey@nelexa.ru> Date: Mon, 26 Sep 2016 18:04:52 +0300 Subject: [PATCH] Optimize pack and unpack long fro PHP >= 5.6.3 --- src/PhpZip/Util/PackUtil.php | 8 ++++++-- tests/PhpZip/ZipTest.php | 11 +++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/PhpZip/Util/PackUtil.php b/src/PhpZip/Util/PackUtil.php index a7f54a9..1ef10d0 100644 --- a/src/PhpZip/Util/PackUtil.php +++ b/src/PhpZip/Util/PackUtil.php @@ -18,7 +18,9 @@ class PackUtil */ public static function packLongLE($longValue) { - // TODO test if (version_compare(PHP_VERSION, '5.6.3') >= 0) {return pack("P", $longValue);} + if (version_compare(PHP_VERSION, '5.6.3') >= 0) { + return pack("P", $longValue); + } $left = 0xffffffff00000000; $right = 0x00000000ffffffff; @@ -36,7 +38,9 @@ class PackUtil */ public static function unpackLongLE($value) { - // TODO test if (version_compare(PHP_VERSION, '5.6.3') >= 0){ return current(unpack('P', $value)); } + if (version_compare(PHP_VERSION, '5.6.3') >= 0) { + return current(unpack('P', $value)); + } $unpack = unpack('Va/Vb', $value); return $unpack['a'] + ($unpack['b'] << 32); } diff --git a/tests/PhpZip/ZipTest.php b/tests/PhpZip/ZipTest.php index 3003744..6f5327b 100644 --- a/tests/PhpZip/ZipTest.php +++ b/tests/PhpZip/ZipTest.php @@ -848,7 +848,7 @@ class ZipTest extends ZipTestCase 'data' => CryptoUtil::randomBytes(255), 'password' => CryptoUtil::randomBytes(255), 'encryption_method' => ZipEntry::ENCRYPTION_METHOD_WINZIP_AES, - 'compression_method' => ZipEntry::METHOD_BZIP2, + 'compression_method' => extension_loaded("bz2") ? ZipEntry::METHOD_BZIP2 : ZipEntry::METHOD_STORED, ], 'Not password.dat' => [ 'data' => CryptoUtil::randomBytes(255), @@ -1022,6 +1022,9 @@ class ZipTest extends ZipTestCase $zipFile->close(); } + /** + * Test zip alignment. + */ public function testZipAlign() { $zipOutputFile = ZipOutputFile::create(); @@ -1042,7 +1045,7 @@ class ZipTest extends ZipTestCase if($result === null) return; // zip align not installed // check not zip align - self::assertFalse($result, false); + self::assertFalse($result); $zipFile = ZipFile::openFromFile($this->outputFilename); $zipOutputFile = ZipOutputFile::openFromZipFile($zipFile); @@ -1062,6 +1065,7 @@ class ZipTest extends ZipTestCase /** * Test support ZIP64 ext (slow test - normal). + * Create > 65535 files in archive and open and extract to /dev/null. */ public function testCreateAndOpenZip64Ext() { @@ -1078,8 +1082,7 @@ class ZipTest extends ZipTestCase $zipFile = ZipFile::openFromFile($this->outputFilename); self::assertEquals($zipFile->count(), $countFiles); - foreach ($zipFile->getListFiles() as $entry) { - $zipFile->getEntryContent($entry); + foreach ($zipFile as $entry => $content) { } $zipFile->close(); }