diff options
author | Phie <phie@phie.ovh> | 2018-08-21 18:39:12 +0300 |
---|---|---|
committer | Phie <phie@phie.ovh> | 2018-08-21 18:39:12 +0300 |
commit | 7d24cc0120859fc4e46b301c08effc97ddfbb1bb (patch) | |
tree | 94b5b52074022ceccd4c91073f217feaec38ca40 /vendor/nelexa/zip/src/PhpZip/Model/Entry/ZipSourceEntry.php |
first commit for Carnet NC server
Diffstat (limited to 'vendor/nelexa/zip/src/PhpZip/Model/Entry/ZipSourceEntry.php')
-rw-r--r-- | vendor/nelexa/zip/src/PhpZip/Model/Entry/ZipSourceEntry.php | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/vendor/nelexa/zip/src/PhpZip/Model/Entry/ZipSourceEntry.php b/vendor/nelexa/zip/src/PhpZip/Model/Entry/ZipSourceEntry.php new file mode 100644 index 0000000..7c43f10 --- /dev/null +++ b/vendor/nelexa/zip/src/PhpZip/Model/Entry/ZipSourceEntry.php @@ -0,0 +1,95 @@ +<?php + +namespace PhpZip\Model\Entry; + +use PhpZip\Exception\ZipException; +use PhpZip\Stream\ZipInputStreamInterface; + +/** + * This class is used to represent a ZIP file entry. + * + * @see https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT .ZIP File Format Specification + * @author Ne-Lexa alexey@nelexa.ru + * @license MIT + */ +class ZipSourceEntry extends ZipAbstractEntry +{ + /** + * Max size cached content in memory. + */ + const MAX_SIZE_CACHED_CONTENT_IN_MEMORY = 524288; // 512 kb + /** + * @var ZipInputStreamInterface + */ + protected $inputStream; + /** + * @var string|resource Cached entry content. + */ + protected $entryContent; + /** + * @var string + */ + protected $readPassword; + /** + * @var bool + */ + private $clone = false; + + /** + * ZipSourceEntry constructor. + * @param ZipInputStreamInterface $inputStream + */ + public function __construct(ZipInputStreamInterface $inputStream) + { + parent::__construct(); + $this->inputStream = $inputStream; + } + + /** + * @return ZipInputStreamInterface + */ + public function getInputStream() + { + return $this->inputStream; + } + + /** + * Returns an string content of the given entry. + * + * @return string + * @throws ZipException + */ + public function getEntryContent() + { + if (null === $this->entryContent) { + $content = $this->inputStream->readEntryContent($this); + if ($this->getSize() < self::MAX_SIZE_CACHED_CONTENT_IN_MEMORY) { + $this->entryContent = $content; + } else { + $this->entryContent = fopen('php://temp', 'rb'); + fwrite($this->entryContent, $content); + } + return $content; + } + if (is_resource($this->entryContent)) { + return stream_get_contents($this->entryContent, -1, 0); + } + return $this->entryContent; + } + + /** + * Clone extra fields + */ + public function __clone() + { + $this->clone = true; + parent::__clone(); + } + + public function __destruct() + { + if (!$this->clone && null !== $this->entryContent && is_resource($this->entryContent)) { + fclose($this->entryContent); + } + } +} |