From 6688f474b5ba724762b01f473c873815b4787fe1 Mon Sep 17 00:00:00 2001 From: wapplay-home-linux Date: Sat, 11 Nov 2017 17:21:01 +0300 Subject: [PATCH] fix bug issue #8 - Error if the file is empty --- .codeclimate.yml | 9 --------- .travis.yml | 10 +--------- CHANGELOG.md | 3 +++ README.md | 1 - src/PhpZip/Model/Entry/ZipReadEntry.php | 5 ++++- tests/PhpZip/ZipFileTest.php | 14 ++++++++++++++ 6 files changed, 22 insertions(+), 20 deletions(-) delete mode 100644 .codeclimate.yml diff --git a/.codeclimate.yml b/.codeclimate.yml deleted file mode 100644 index eb2cfbb..0000000 --- a/.codeclimate.yml +++ /dev/null @@ -1,9 +0,0 @@ -engines: - duplication: - enabled: true - config: - languages: - - php -exclude_paths: - - tests/ - - vendor/ \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 6ee971a..ecce87e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,10 +12,6 @@ cache: - vendor - $HOME/.composer/cache -addons: - code_climate: - repo_token: 486a09d58d663450146c53c81c6c64938bcf3bb0b7c8ddebdc125fe97c18213a - install: - travis_retry composer self-update && composer --version - travis_retry composer install --prefer-dist --no-interaction @@ -25,8 +21,4 @@ before_script: script: - composer validate --no-check-lock - - vendor/bin/phpunit -v -c bootstrap.xml --coverage-clover build/logs/clover.xml - -after_success: - - vendor/bin/test-reporter - + - vendor/bin/phpunit -v -c bootstrap.xml diff --git a/CHANGELOG.md b/CHANGELOG.md index 79a8519..3b14722 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 3.0.3 (2017-11-11) +Fix bug issue #8 - Error if the file is empty. + ## 3.0.0 (2017-03-15) Merge `ZipOutputFile` with ZipFile and optimize the zip archive update. diff --git a/README.md b/README.md index 5f7269a..2657496 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,6 @@ [![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%2064bit-%3E%3D%205.5-8892BF.svg)](https://php.net/) -[![Test Coverage](https://codeclimate.com/github/Ne-Lexa/php-zip/badges/coverage.svg)](https://codeclimate.com/github/Ne-Lexa/php-zip/coverage) [![License](https://poser.pugx.org/nelexa/zip/license)](https://packagist.org/packages/nelexa/zip) Table of contents diff --git a/src/PhpZip/Model/Entry/ZipReadEntry.php b/src/PhpZip/Model/Entry/ZipReadEntry.php index 2363884..aea781c 100644 --- a/src/PhpZip/Model/Entry/ZipReadEntry.php +++ b/src/PhpZip/Model/Entry/ZipReadEntry.php @@ -151,7 +151,10 @@ class ZipReadEntry extends ZipAbstractEntry fseek($this->inputStream, $pos); // Get raw entry content - $content = fread($this->inputStream, $this->getCompressedSize()); + $content = ''; + if ($this->getCompressedSize() > 0) { + $content = fread($this->inputStream, $this->getCompressedSize()); + } // Strong Encryption Specification - WinZip AES if ($this->isEncrypted()) { diff --git a/tests/PhpZip/ZipFileTest.php b/tests/PhpZip/ZipFileTest.php index a9810e9..549e650 100644 --- a/tests/PhpZip/ZipFileTest.php +++ b/tests/PhpZip/ZipFileTest.php @@ -1,4 +1,5 @@ addFromString('file', $contents); + $zipFile->saveAsFile($this->outputFilename); + $zipFile->close(); + + $zipFile->openFile($this->outputFilename); + self::assertEquals($zipFile['file'], $contents); + $zipFile->close(); + } + /** * Test support ZIP64 ext (slow test - normal). * Create > 65535 files in archive and open and extract to /dev/null.