Skip to content

Commit 0893b4b

Browse files
committedJul 28, 2023
add ZipArchive::LENGTH_TO_END and ZipArchive::LENGTH_UNCHECKED constants
1 parent 566cf37 commit 0893b4b

File tree

5 files changed

+41
-7
lines changed

5 files changed

+41
-7
lines changed
 

‎UPGRADING

+2
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,8 @@ PHP 8.3 UPGRADE NOTES
483483
. ZipArchive::AFL_WANT_TORRENTZIP (libzip >= 1.10)
484484
. ZipArchive::AFL_CREATE_OR_KEEP_FILE_FOR_EMPTY_ARCHIVE (libzip >= 1.10)
485485
. ZipArchive::FL_OPEN_FILE_NOW
486+
. ZipArchive::LENGTH_TO_END as default value for addFile and replaceFile
487+
. ZipArchive::LENGTH_UNCHECKED (libzip >= 1.10.1)
486488

487489
========================================
488490
11. Changes to INI File Handling

‎ext/zip/php_zip.h

+5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ extern zend_module_entry zip_module_entry;
3131
#define ZIP_OVERWRITE ZIP_TRUNCATE
3232
#endif
3333

34+
/* since 1.10.1 */
35+
#ifndef ZIP_LENGTH_TO_END
36+
#define ZIP_LENGTH_TO_END 0
37+
#endif
38+
3439
/* Additionnal flags not from libzip */
3540
#define ZIP_FL_OPEN_FILE_NOW (1u<<30)
3641

‎ext/zip/php_zip.stub.php

+16-3
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,6 @@ class ZipArchive implements Countable
459459
public const ER_WRONGPASSWD = UNKNOWN;
460460

461461
/* since 1.0.0 */
462-
463462
#ifdef ZIP_ER_OPNOTSUPP
464463
/**
465464
* N Operation not supported
@@ -721,6 +720,20 @@ class ZipArchive implements Countable
721720
*/
722721
public const LIBZIP_VERSION = UNKNOWN;
723722

723+
/**
724+
* @var int
725+
* @cvalue ZIP_LENGTH_TO_END
726+
*/
727+
public const LENGTH_TO_END = UNKNOWN;
728+
/* since 1.10.1 */
729+
#ifdef ZIP_LENGTH_UNCHECKED
730+
/**
731+
* @var int
732+
* @cvalue ZIP_LENGTH_UNCHECKED
733+
*/
734+
public const LENGTH_UNCHECKED = UNKNOWN;
735+
#endif
736+
724737
/** @readonly */
725738
public int $lastId;
726739
/** @readonly */
@@ -760,10 +773,10 @@ public function addEmptyDir(string $dirname, int $flags = 0): bool {}
760773
public function addFromString(string $name, string $content, int $flags = ZipArchive::FL_OVERWRITE): bool {}
761774

762775
/** @tentative-return-type */
763-
public function addFile(string $filepath, string $entryname = "", int $start = 0, int $length = 0, int $flags = ZipArchive::FL_OVERWRITE): bool {}
776+
public function addFile(string $filepath, string $entryname = "", int $start = 0, int $length = ZipArchive::LENGTH_TO_END, int $flags = ZipArchive::FL_OVERWRITE): bool {}
764777

765778
/** @tentative-return-type */
766-
public function replaceFile(string $filepath, int $index, int $start = 0, int $length = 0, int $flags = 0): bool {}
779+
public function replaceFile(string $filepath, int $index, int $start = 0, int $length = ZipArchive::LENGTH_TO_END, int $flags = 0): bool {}
767780

768781
/** @tentative-return-type */
769782
public function addGlob(string $pattern, int $flags = 0, array $options = []): array|false {}

‎ext/zip/php_zip_arginfo.h

+17-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎ext/zip/tests/oo_addfile.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ if (!$zip->addFile($dirname . 'utils.inc', 'mini.txt', 12, 34)) {
2424
echo "failed\n";
2525
}
2626
var_dump($zip->lastId);
27-
if (!$zip->addFile($dirname . 'utils.inc', 'other.txt', 0, 0, ZipArchive::FL_OPEN_FILE_NOW)) {
27+
if (!$zip->addFile($dirname . 'utils.inc', 'other.txt', 0, ZipArchive::LENGTH_TO_END, ZipArchive::FL_OPEN_FILE_NOW)) {
2828
echo "failed\n";
2929
}
3030
var_dump($zip->lastId);

0 commit comments

Comments
 (0)
Please sign in to comment.