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