Bläddra i källkod

fix php 5.5 compat, fix append stream filter

wapplay 6 år sedan
förälder
incheckning
8efbfd67f4
2 ändrade filer med 12 tillägg och 18 borttagningar
  1. 5 0
      src/IO/ZipReader.php
  2. 7 18
      src/ZipFile.php

+ 5 - 0
src/IO/ZipReader.php

@@ -765,6 +765,11 @@ class ZipReader
             $filters[] = $encContextFilter;
         }
 
+        // hack, see https://groups.google.com/forum/#!topic/alt.comp.lang.php/37_JZeW63uc
+        $pos = ftell($this->inStream);
+        rewind($this->inStream);
+        fseek($this->inStream, $pos);
+
         $contextDecompress = null;
         switch ($compressionMethod) {
             case ZipCompressionMethod::STORED:

+ 7 - 18
src/ZipFile.php

@@ -1,6 +1,7 @@
 <?php
 
 /** @noinspection AdditionOperationOnArraysInspection */
+
 /** @noinspection PhpUsageOfSilenceOperatorInspection */
 
 namespace PhpZip;
@@ -243,8 +244,8 @@ class ZipFile implements ZipFileInterface
      *
      * @param string $entryName
      *
-     * @throws ZipEntryNotFoundException
      * @throws ZipException
+     * @throws ZipEntryNotFoundException
      *
      * @return string
      */
@@ -259,8 +260,8 @@ class ZipFile implements ZipFileInterface
      * @param string      $entryName
      * @param string|null $comment
      *
-     * @throws ZipException
      * @throws ZipEntryNotFoundException
+     * @throws ZipException
      *
      * @return ZipFile
      */
@@ -276,8 +277,8 @@ class ZipFile implements ZipFileInterface
      *
      * @param string $entryName
      *
-     * @throws ZipException
      * @throws ZipEntryNotFoundException
+     * @throws ZipException
      *
      * @return string
      */
@@ -295,8 +296,8 @@ class ZipFile implements ZipFileInterface
     /**
      * @param string $entryName
      *
-     * @throws ZipException
      * @throws ZipEntryNotFoundException
+     * @throws ZipException
      *
      * @return resource
      */
@@ -313,8 +314,8 @@ class ZipFile implements ZipFileInterface
      *
      * @param string|ZipEntry $entryName
      *
-     * @throws ZipEntryNotFoundException
      * @throws ZipException
+     * @throws ZipEntryNotFoundException
      *
      * @return ZipInfo
      */
@@ -395,19 +396,7 @@ class ZipFile implements ZipFileInterface
 
             if (\is_array($entries)) {
                 $entries = array_unique($entries);
-                $flipEntries = array_flip($entries);
-                $zipEntries = array_filter(
-                    $zipEntries,
-                    /**
-                     * @param string $entryName
-                     *
-                     * @return bool
-                     */
-                    static function ($entryName) use ($flipEntries) {
-                        return isset($flipEntries[$entryName]);
-                    },
-                    \ARRAY_FILTER_USE_KEY
-                );
+                $zipEntries = array_intersect_key($zipEntries, array_flip($entries));
             }
         }