-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ZipArchive::setCompressionName and ZipArchive::setCompressionInde…
…x methods
- Loading branch information
1 parent
3638ac2
commit 3a55ea0
Showing
4 changed files
with
178 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
error_reporting(E_ALL); | ||
if (!extension_loaded('zip')) { | ||
dl('zip.so'); | ||
} | ||
|
||
$zip = new ZipArchive(); | ||
$filename = "a.zip"; | ||
|
||
if (!$zip->open($filename, ZIPARCHIVE::CREATE | ZipArchive::OVERWRITE)) { | ||
exit("cannot open <$filename>\n"); | ||
} | ||
|
||
$zip->addFromString("testfilephp.txt", "#1 This is a test string added as testfilephp.txt.\n"); | ||
$zip->addFromString("testfilephp2.txt", "#2 This is a test string added as testfilephp2.txt.\n"); | ||
$zip->addFile("too.php", "testfromfile.php"); | ||
|
||
$zip->setCompressionName("testfilephp2.txt", ZipArchive::CM_STORE); | ||
$zip->setCompressionIndex(2, ZipArchive::CM_STORE); | ||
|
||
$zip->close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
--TEST-- | ||
setCompressionName and setCompressionIndex methods | ||
--SKIPIF-- | ||
<?php | ||
/* $Id$ */ | ||
if (!extension_loaded('zip')) die('skip'); | ||
?> | ||
--FILE-- | ||
<?php | ||
$tmpfile = dirname(__FILE__) . '/__tmp_oo_set_compression.zip'; | ||
|
||
if (file_exists($tmpfile)) { | ||
unlink($tmpfile); | ||
} | ||
|
||
// generate the ZIP file | ||
$zip = new ZipArchive; | ||
if ($zip->open($tmpfile, ZipArchive::CREATE) !== TRUE) { | ||
exit('failed'); | ||
} | ||
$txt = file_get_contents(__FILE__); | ||
$zip->addFromString('entry1.txt', $txt); | ||
$zip->addFromString('entry2.txt', $txt); | ||
$zip->addFromString('dir/entry3.txt', $txt); | ||
$zip->addFromString('entry4.txt', $txt); | ||
$zip->addFromString('entry5.txt', $txt); | ||
$zip->addFromString('entry6.txt', $txt); | ||
$zip->addFromString('entry7.txt', $txt); | ||
|
||
var_dump($zip->setCompressionName('entry2.txt', ZipArchive::CM_DEFAULT)); | ||
var_dump($zip->setCompressionName('dir/entry3.txt', ZipArchive::CM_STORE)); | ||
var_dump($zip->setCompressionName('entry4.txt', ZipArchive::CM_DEFLATE)); | ||
|
||
var_dump($zip->setCompressionIndex(4, ZipArchive::CM_STORE)); | ||
var_dump($zip->setCompressionIndex(5, ZipArchive::CM_DEFLATE)); | ||
var_dump($zip->setCompressionIndex(6, ZipArchive::CM_DEFAULT)); | ||
|
||
if (!$zip->close()) { | ||
exit('failed'); | ||
} | ||
|
||
|
||
// check the ZIP file | ||
$zip = zip_open($tmpfile); | ||
if (!is_resource($zip)) { | ||
exit('failed'); | ||
} | ||
|
||
while ($e = zip_read($zip)) { | ||
echo zip_entry_name($e) . ': ' . zip_entry_compressionmethod($e) . "\n"; | ||
} | ||
zip_close($zip); | ||
?> | ||
--CLEAN-- | ||
<?php | ||
$tmpfile = dirname(__FILE__) . '/__tmp_oo_set_compression.zip'; | ||
unlink($tmpfile); | ||
?> | ||
--EXPECT-- | ||
bool(true) | ||
bool(true) | ||
bool(true) | ||
bool(true) | ||
bool(true) | ||
bool(true) | ||
entry1.txt: deflated | ||
entry2.txt: deflated | ||
dir/entry3.txt: stored | ||
entry4.txt: deflated | ||
entry5.txt: stored | ||
entry6.txt: deflated | ||
entry7.txt: deflated |