mirror of
https://github.com/Ne-Lexa/php-zip.git
synced 2025-07-31 12:40:09 +02:00
Add support set zip alignment (alternative zipalign
tool)
This commit is contained in:
@@ -1022,6 +1022,44 @@ class ZipTest extends ZipTestCase
|
||||
$zipFile->close();
|
||||
}
|
||||
|
||||
public function testZipAlign()
|
||||
{
|
||||
$zipOutputFile = ZipOutputFile::create();
|
||||
|
||||
for ($i = 0; $i < 100; $i++) {
|
||||
$zipOutputFile->addFromString(
|
||||
'entry' . $i . '.txt',
|
||||
CryptoUtil::randomBytes(mt_rand(100, 4096)),
|
||||
ZipEntry::METHOD_STORED
|
||||
);
|
||||
}
|
||||
$zipOutputFile->saveAsFile($this->outputFilename);
|
||||
$zipOutputFile->close();
|
||||
|
||||
self::assertCorrectZipArchive($this->outputFilename);
|
||||
|
||||
$result = self::doZipAlignVerify($this->outputFilename);
|
||||
if($result === null) return; // zip align not installed
|
||||
|
||||
// check not zip align
|
||||
self::assertFalse($result, false);
|
||||
|
||||
$zipFile = ZipFile::openFromFile($this->outputFilename);
|
||||
$zipOutputFile = ZipOutputFile::openFromZipFile($zipFile);
|
||||
$zipOutputFile->setZipAlign(4);
|
||||
$zipOutputFile->saveAsFile($this->outputFilename);
|
||||
$zipOutputFile->close();
|
||||
$zipFile->close();
|
||||
|
||||
self::assertCorrectZipArchive($this->outputFilename);
|
||||
|
||||
$result = self::doZipAlignVerify($this->outputFilename);
|
||||
self::assertNotNull($result);
|
||||
|
||||
// check zip align
|
||||
self::assertTrue($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test support ZIP64 ext (slow test - normal).
|
||||
*/
|
||||
|
@@ -42,4 +42,20 @@ class ZipTestCase extends \PHPUnit_Framework_TestCase
|
||||
self::assertEquals(file_get_contents($filename), $actualEmptyZipData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $filename
|
||||
* @return bool|null If null - can not install zipalign
|
||||
*/
|
||||
public static function doZipAlignVerify($filename)
|
||||
{
|
||||
if (DIRECTORY_SEPARATOR !== '\\' && `which zipalign`) {
|
||||
exec("zipalign -c -v 4 " . escapeshellarg($filename), $output, $returnCode);
|
||||
return $returnCode === 0;
|
||||
} else {
|
||||
echo 'Can not find program "zipalign" for test' . PHP_EOL;
|
||||
fwrite(STDERR, 'Can not find program "zipalign" for test');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user