1
0
mirror of https://github.com/Ne-Lexa/php-zip.git synced 2025-08-10 17:33:56 +02:00

solving problems with lack of memory, the new ZipReader and ZipWriter class, adds .phpstorm.meta.php

#13
#16
#27
#31
#41
This commit is contained in:
Ne-Lexa
2019-12-30 18:47:37 +03:00
parent 28e220718c
commit f377b889b5
126 changed files with 12805 additions and 7819 deletions

View File

@@ -0,0 +1,100 @@
<?php
namespace PhpZip\Tests\SlowTests;
use PhpZip\Constants\ZipCompressionMethod;
use PhpZip\Exception\ZipException;
use PhpZip\Tests\ZipTestCase;
use PhpZip\Util\FilesUtil;
use PhpZip\ZipFile;
/**
* @internal
*
* @large
*/
class Zip64Test extends ZipTestCase
{
/**
* @throws ZipException
*
* @runInSeparateProcess
*/
public function testCreateLargeZip64File()
{
if (\PHP_INT_SIZE === 4) { // php 32 bit
static::markTestSkipped('Only php-64 bit.');
return;
}
if (!self::existsProgram('fallocate')) {
static::markTestSkipped('Cannot find the program "fallocate" for the test');
return;
}
$basedir = \dirname($this->outputFilename);
$tmpLargeFile = $basedir . '/large_bin_file.bin';
$sizeLargeBinFile = (int) (4.2 * 1024 * 1024 * 1024);
$needFreeSpace = $sizeLargeBinFile * 4;
$diskFreeSpace = disk_free_space($basedir);
if ($needFreeSpace > $diskFreeSpace) {
static::markTestIncomplete(
sprintf(
'Not enough disk space for the test. Need to free %s',
FilesUtil::humanSize($needFreeSpace - $diskFreeSpace)
)
);
return;
}
try {
$commandCreateLargeBinFile = 'fallocate -l ' . escapeshellarg($sizeLargeBinFile) . ' ' . escapeshellarg($tmpLargeFile);
exec($commandCreateLargeBinFile, $output, $returnCode);
if ($returnCode !== 0) {
static::markTestIncomplete('Cannot create large file. Error code: ' . $returnCode);
return;
}
$zipFile = new ZipFile();
$zipFile
->addFile($tmpLargeFile, 'large_file1.bin', ZipCompressionMethod::STORED)
->addFile($tmpLargeFile, 'large_file2.bin', ZipCompressionMethod::DEFLATED)
->saveAsFile($this->outputFilename)
->close()
;
if (is_file($tmpLargeFile)) {
unlink($tmpLargeFile);
}
self::assertCorrectZipArchive($this->outputFilename);
if (!is_dir($this->outputDirname)) {
mkdir($this->outputDirname, 0755, true);
}
$zipFile->openFile($this->outputFilename);
$zipFile->extractTo($this->outputDirname);
static::assertTrue(is_file($this->outputDirname . '/large_file1.bin'));
static::assertTrue(is_file($this->outputDirname . '/large_file2.bin'));
$zipFile->deleteFromName('large_file1.bin');
$zipFile->saveAsFile($this->outputFilename);
self::assertCorrectZipArchive($this->outputFilename);
} finally {
if (is_file($tmpLargeFile)) {
unlink($tmpLargeFile);
}
}
}
}