diff --git a/src/PhpZip/Model/Entry/ZipNewEntry.php b/src/PhpZip/Model/Entry/ZipNewEntry.php index 14bfad5..57074f9 100644 --- a/src/PhpZip/Model/Entry/ZipNewEntry.php +++ b/src/PhpZip/Model/Entry/ZipNewEntry.php @@ -41,7 +41,9 @@ class ZipNewEntry extends ZipAbstractEntry public function getEntryContent() { if (is_resource($this->content)) { - rewind($this->content); + if (stream_get_meta_data($this->content)['seekable']) { + rewind($this->content); + } return stream_get_contents($this->content); } return $this->content; diff --git a/tests/PhpZip/ZipRemoteFileTest.php b/tests/PhpZip/ZipRemoteFileTest.php new file mode 100644 index 0000000..dbd5a59 --- /dev/null +++ b/tests/PhpZip/ZipRemoteFileTest.php @@ -0,0 +1,55 @@ +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(); + } + +}