mirror of
https://github.com/Ne-Lexa/php-zip.git
synced 2025-04-21 15:21:51 +02:00
Merge branch 'hotfix/3.2.2'
This commit is contained in:
commit
074443dbc4
@ -39,7 +39,7 @@ matrix:
|
||||
|
||||
- php: 7.4
|
||||
os: linux
|
||||
dist: bionic
|
||||
dist: xenial
|
||||
env: COVERAGE=true ZIPALIGN_INSTALL=true PHPUNIT_FLAGS="-v -c phpunit.xml --testsuite only_fast_tests --coverage-clover=coverage.clover"
|
||||
|
||||
before_install:
|
||||
|
@ -3,6 +3,7 @@
|
||||
`PhpZip` - php библиотека для продвинутой работы с ZIP-архивами.
|
||||
|
||||
[](https://travis-ci.org/Ne-Lexa/php-zip)
|
||||
[](https://scrutinizer-ci.com/g/Ne-Lexa/php-zip/?branch=master)
|
||||
[](https://packagist.org/packages/nelexa/zip)
|
||||
[](https://packagist.org/packages/nelexa/zip)
|
||||
[](https://php.net/)
|
||||
|
@ -3,6 +3,7 @@
|
||||
`PhpZip` is a php-library for extended work with ZIP-archives.
|
||||
|
||||
[](https://travis-ci.org/Ne-Lexa/php-zip)
|
||||
[](https://scrutinizer-ci.com/g/Ne-Lexa/php-zip/?branch=master)
|
||||
[](https://packagist.org/packages/nelexa/zip)
|
||||
[](https://packagist.org/packages/nelexa/zip)
|
||||
[](https://php.net/)
|
||||
|
@ -4,6 +4,7 @@ namespace PhpZip\Model\Data;
|
||||
|
||||
use PhpZip\Exception\ZipException;
|
||||
use PhpZip\Model\ZipData;
|
||||
use PhpZip\Model\ZipEntry;
|
||||
|
||||
/**
|
||||
* Class ZipFileData.
|
||||
@ -16,11 +17,12 @@ class ZipFileData implements ZipData
|
||||
/**
|
||||
* ZipStringData constructor.
|
||||
*
|
||||
* @param ZipEntry $zipEntry
|
||||
* @param \SplFileInfo $fileInfo
|
||||
*
|
||||
* @throws ZipException
|
||||
*/
|
||||
public function __construct(\SplFileInfo $fileInfo)
|
||||
public function __construct(ZipEntry $zipEntry, \SplFileInfo $fileInfo)
|
||||
{
|
||||
if (!$fileInfo->isFile()) {
|
||||
throw new ZipException('$fileInfo is not a file.');
|
||||
@ -31,6 +33,7 @@ class ZipFileData implements ZipData
|
||||
}
|
||||
|
||||
$this->file = $fileInfo;
|
||||
$zipEntry->setUncompressedSize($fileInfo->getSize());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -665,10 +665,9 @@ class ZipFile implements ZipFileInterface
|
||||
ZipCompressionMethod::DEFLATED;
|
||||
}
|
||||
|
||||
$zipEntry->setUncompressedSize($file->getSize());
|
||||
$zipEntry->setCompressionMethod($compressionMethod);
|
||||
|
||||
$zipData = new ZipFileData($file);
|
||||
$zipData = new ZipFileData($zipEntry, $file);
|
||||
} elseif ($file->isDir()) {
|
||||
$zipEntry->setCompressionMethod(ZipCompressionMethod::STORED);
|
||||
$zipEntry->setUncompressedSize(0);
|
||||
|
@ -1522,9 +1522,10 @@ class ZipEntryTest extends TestCase
|
||||
public function testClone()
|
||||
{
|
||||
$newUnixExtra = new NewUnixExtraField();
|
||||
$zipData = new ZipFileData(new \SplFileInfo(__FILE__));
|
||||
|
||||
$zipEntry = new ZipEntry('entry');
|
||||
$zipData = new ZipFileData($zipEntry, new \SplFileInfo(__FILE__));
|
||||
|
||||
$zipEntry->addExtraField($newUnixExtra);
|
||||
$zipEntry->setData($zipData);
|
||||
|
||||
|
@ -10,6 +10,7 @@ use PhpZip\Exception\InvalidArgumentException;
|
||||
use PhpZip\Exception\ZipEntryNotFoundException;
|
||||
use PhpZip\Exception\ZipException;
|
||||
use PhpZip\Exception\ZipUnsupportMethodException;
|
||||
use PhpZip\Model\Data\ZipFileData;
|
||||
use PhpZip\Model\ZipEntry;
|
||||
use PhpZip\Model\ZipInfo;
|
||||
use PhpZip\Util\FilesUtil;
|
||||
@ -2418,4 +2419,34 @@ class ZipFileTest extends ZipTestCase
|
||||
static::assertSame($zipFile->getEntry($newEntryName)->getCompressionMethod(), ZipCompressionMethod::STORED);
|
||||
$zipFile->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ZipEntryNotFoundException
|
||||
* @throws ZipException
|
||||
*/
|
||||
public function testReplaceEntryContentsByFile()
|
||||
{
|
||||
$entryName = basename(__FILE__);
|
||||
|
||||
$zipFile = new ZipFile();
|
||||
$zipFile[$entryName] = 'contents';
|
||||
$zipFile->saveAsFile($this->outputFilename);
|
||||
$zipFile->close();
|
||||
|
||||
$zipFile->openFile($this->outputFilename);
|
||||
$entry = $zipFile->getEntry($entryName);
|
||||
$data = new ZipFileData($entry, new \SplFileInfo(__FILE__));
|
||||
$entry->setData($data);
|
||||
$zipFile->saveAsFile($this->outputFilename);
|
||||
$zipFile->close();
|
||||
|
||||
self::assertCorrectZipArchive($this->outputFilename);
|
||||
|
||||
$zipFile->openFile($this->outputFilename);
|
||||
static::assertSame(
|
||||
$zipFile->getEntryContents($entryName),
|
||||
file_get_contents(__FILE__)
|
||||
);
|
||||
$zipFile->close();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user