mirror of
https://github.com/Ne-Lexa/php-zip.git
synced 2025-07-19 06:51:24 +02:00
Merge pull request #26 from belgattitude/fix/non-seekable-streams
Re-enable support for remote streams, fix #25
This commit is contained in:
@@ -41,7 +41,9 @@ class ZipNewEntry extends ZipAbstractEntry
|
|||||||
public function getEntryContent()
|
public function getEntryContent()
|
||||||
{
|
{
|
||||||
if (is_resource($this->content)) {
|
if (is_resource($this->content)) {
|
||||||
|
if (stream_get_meta_data($this->content)['seekable']) {
|
||||||
rewind($this->content);
|
rewind($this->content);
|
||||||
|
}
|
||||||
return stream_get_contents($this->content);
|
return stream_get_contents($this->content);
|
||||||
}
|
}
|
||||||
return $this->content;
|
return $this->content;
|
||||||
|
55
tests/PhpZip/ZipRemoteFileTest.php
Normal file
55
tests/PhpZip/ZipRemoteFileTest.php
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PhpZip;
|
||||||
|
|
||||||
|
use PhpZip\Exception\ZipException;
|
||||||
|
use PhpZip\Util\Iterator\IgnoreFilesFilterIterator;
|
||||||
|
use PhpZip\Util\Iterator\IgnoreFilesRecursiveFilterIterator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test add remote files to zip archive
|
||||||
|
*/
|
||||||
|
class ZipRemoteFileTest extends ZipTestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
protected function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws ZipException
|
||||||
|
*/
|
||||||
|
public function testAddRemoteFileFromStream()
|
||||||
|
{
|
||||||
|
$zipFile = new ZipFile();
|
||||||
|
$outputZip = $this->outputFilename;
|
||||||
|
$fileUrl = 'https://raw.githubusercontent.com/Ne-Lexa/php-zip/master/README.md';
|
||||||
|
$fp = @fopen($fileUrl, 'rb', false, stream_context_create([
|
||||||
|
'http' => [
|
||||||
|
'timeout' => 3,
|
||||||
|
]
|
||||||
|
]));
|
||||||
|
if ($fp === false) {
|
||||||
|
self::markTestSkipped(sprintf(
|
||||||
|
"Could not fetch remote file: %s",
|
||||||
|
$fileUrl
|
||||||
|
));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$fileName = 'remote-file-from-http-stream.md';
|
||||||
|
$zipFile->addFromStream($fp, $fileName);
|
||||||
|
|
||||||
|
$zipFile->saveAsFile($outputZip);
|
||||||
|
$zipFile->close();
|
||||||
|
|
||||||
|
$zipFile = new ZipFile();
|
||||||
|
$zipFile->openFile($outputZip);
|
||||||
|
$files = $zipFile->getListFiles();
|
||||||
|
self::assertCount(1, $files);
|
||||||
|
self::assertSame($fileName, $files[0]);
|
||||||
|
$zipFile->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user