Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ZipNewEntry.php « Entry « Model « PhpZip « src « zip « nelexa « vendor - github.com/CarnetApp/CarnetNextcloud.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d10a32c331924f4552ca0cdba3f75ea49e88a288 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php

namespace PhpZip\Model\Entry;

use PhpZip\Exception\InvalidArgumentException;
use PhpZip\Exception\ZipException;
use PhpZip\ZipFileInterface;

/**
 * Abstract class for new zip entry.
 *
 * @see https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT .ZIP File Format Specification
 * @author Ne-Lexa alexey@nelexa.ru
 * @license MIT
 */
class ZipNewEntry extends ZipAbstractEntry
{
    /**
     * @var resource|string|null
     */
    protected $content;
    /**
     * @var bool
     */
    private $clone = false;

    /**
     * ZipNewEntry constructor.
     * @param string|resource|null $content
     * @throws InvalidArgumentException
     */
    public function __construct($content = null)
    {
        parent::__construct();
        if ($content !== null && !is_string($content) && !is_resource($content)) {
            throw new InvalidArgumentException('invalid content');
        }
        $this->content = $content;
    }

    /**
     * Returns an string content of the given entry.
     *
     * @return null|string
     * @throws ZipException
     */
    public function getEntryContent()
    {
        if (is_resource($this->content)) {
            return stream_get_contents($this->content, -1, 0);
        }
        return $this->content;
    }

    /**
     * Version needed to extract.
     *
     * @return int
     */
    public function getVersionNeededToExtract()
    {
        $method = $this->getMethod();
        return self::METHOD_WINZIP_AES === $method ? 51 :
            (
            ZipFileInterface::METHOD_BZIP2 === $method ? 46 :
                (
                $this->isZip64ExtensionsRequired() ? 45 :
                    (ZipFileInterface::METHOD_DEFLATED === $method || $this->isDirectory() ? 20 : 10)
                )
            );
    }

    /**
     * Clone extra fields
     */
    public function __clone()
    {
        $this->clone = true;
        parent::__clone();
    }

    public function __destruct()
    {
        if (!$this->clone && null !== $this->content && is_resource($this->content)) {
            fclose($this->content);
            $this->content = null;
        }
    }
}