mirror of
https://github.com/Ne-Lexa/php-zip.git
synced 2025-01-17 15:28:14 +01:00
fix replace contents by file
This commit is contained in:
parent
d305ab68bc
commit
cbb693213e
@ -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-архивами.
|
||||
|
||||
[![Build Status](https://travis-ci.org/Ne-Lexa/php-zip.svg?branch=master)](https://travis-ci.org/Ne-Lexa/php-zip)
|
||||
[![Code Coverage](https://scrutinizer-ci.com/g/Ne-Lexa/php-zip/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/Ne-Lexa/php-zip/?branch=master)
|
||||
[![Latest Stable Version](https://poser.pugx.org/nelexa/zip/v/stable)](https://packagist.org/packages/nelexa/zip)
|
||||
[![Total Downloads](https://poser.pugx.org/nelexa/zip/downloads)](https://packagist.org/packages/nelexa/zip)
|
||||
[![Minimum PHP Version](http://img.shields.io/badge/php-%3E%3D%205.5-8892BF.svg)](https://php.net/)
|
||||
|
@ -3,6 +3,7 @@
|
||||
`PhpZip` is a php-library for extended work with ZIP-archives.
|
||||
|
||||
[![Build Status](https://travis-ci.org/Ne-Lexa/php-zip.svg?branch=master)](https://travis-ci.org/Ne-Lexa/php-zip)
|
||||
[![Code Coverage](https://scrutinizer-ci.com/g/Ne-Lexa/php-zip/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/Ne-Lexa/php-zip/?branch=master)
|
||||
[![Latest Stable Version](https://poser.pugx.org/nelexa/zip/v/stable)](https://packagist.org/packages/nelexa/zip)
|
||||
[![Total Downloads](https://poser.pugx.org/nelexa/zip/downloads)](https://packagist.org/packages/nelexa/zip)
|
||||
[![Minimum PHP Version](http://img.shields.io/badge/php-%3E%3D%205.5-8892BF.svg)](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