* A test to see if it was possible to recreate the result of * Issue #7, if not the cause. * And a demonstration on why the author of the script calling zip * needs to be diligent not to add extra characters to the output. */ // To use the new namespaces, you need a bootstrapper/autoloader, examples are provided here. // The changes to your Zip use are limited to two lines after that is in place. // Require your bootstrap.php, or the autoload.php, and change the class instantiation from nwe ZipStream( to // new \PHPZip\Zip\Stream\ZipStream( // The parameters are unchanged. require_once('bootstrap.php'); // include_once("ZipStream.php"); $zip = new \PHPZip\Zip\Stream\ZipStream('test.zip'); // $zip = new ZipStream("test.zip"); /* * As seen in the output, the above construct with a PHP end and start tag after * creating the ZipStream is a bad idea. The Zip file will be starting with a * space followed by the newline characters. */ $zip->addDirectory("test"); $zip->addDirectoryContent("testData" . DIRECTORY_SEPARATOR . "test","test"); $rv = $zip->finalize(); // If non-fatal errors occurred during execution, this will append them // to the end of the generated file. // It'll create an invalid Zip file, however chances are that it is invalid // already due to the error happening in the first place. // The idea is that errors will be very easy to spot.
$tLast = $tStart; $f = "Mem usage:\r\n\r\nInitial:" . getMem(); $errors = ""; // To use the new namespaces, you need a bootstrapper/autoloader, examples are provided here. // The changes to your Zip use are limited to two lines after that is in place. // Require your bootstrap.php, or the autoload.php, and change the class instantiation from nwe ZipStream( to // new \PHPZip\Zip\Stream\ZipStream( // The parameters are unchanged. require_once('bootstrap.php'); // include_once("ZipStream.php"); $f .= "\r\nbootstrapped: " . getMem(); $zip = new \PHPZip\Zip\Stream\ZipStream('test2.zip'); // $zip = new ZipStream("test.zip"); $f .= "\r\nZip initialized: " . getMem(); /* * As seen in the output, the above construct with a PHP end and start tag after * creating the ZipStream is a bad idea. The Zip file will be starting with a * space followed by the newline characters. */ $testPath = \RelativePath::pathJoin("..", "testData"); //$zip->addDirectory("images"); //$zip->addDirectoryContent("testData" . DIRECTORY_SEPARATOR . "test","test"); //$zip->addLargeFile(\RelativePath::pathJoin($testPath, "500k.tc"), "test/500k.tc"); //$zip->addLargeFile(\RelativePath::pathJoin($testPath, "750k.tc"), "test/750k.tc"); //$zip->addLargeFile(\RelativePath::pathJoin($testPath, "1m.tc"), "test/1m.tc");
// To use the new namespaces, you need a bootstrapper/autoloader, examples are provided here. // The changes to your Zip use are limited to two lines after that is in place. // Require your bootstrap.php, or the autoload.php, and change the class instantiation from nwe ZipStream( to // new \PHPZip\Zip\Stream\ZipStream( // The parameters are unchanged. require_once('bootstrap.php'); // include_once("ZipStream.php"); //print_r(ini_get_all()); $fileTime = date("D, d M Y H:i:s T"); $chapter1 = "Chapter 1\n" . "Lorem ipsum\n" . "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec magna lorem, mattis sit amet porta vitae, consectetur ut eros. Nullam id mattis lacus. In eget neque magna, congue imperdiet nulla. Aenean erat lacus, imperdiet a adipiscing non, dignissim eget felis. Nulla facilisi. Vivamus sit amet lorem eget mauris dictum pharetra. In mauris nulla, placerat a accumsan ac, mollis sit amet ligula. Donec eget facilisis dui. Cras elit quam, imperdiet at malesuada vitae, luctus id orci. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Pellentesque eu libero in leo ultrices tristique. Etiam quis ornare massa. Donec in velit leo. Sed eu ante tortor.\n"; $zip = new \PHPZip\Zip\Stream\ZipStream('ZipStreamExample1.zip'); // $zip = new ZipStream("ZipStreamExample1.zip"); $zip->setComment("Example Zip file for Large file sets.\nCreated on " . date('l jS \of F Y h:i:s A')); $zip->addFile("Hello World!\r\n", "Hello.txt"); $zip->openStream("big one3.txt"); $zip->addStreamData($chapter1."\n\n\n"); $zip->addStreamData($chapter1."\n\n\n"); $zip->addStreamData($chapter1."\n\n\n"); $zip->closeStream(); // For this test you need to create a large text file called "big one1.txt" if (file_exists("big one1.txt")) { $zip->addLargeFile("big one1.txt", "big one2a.txt", 0, null, \PHPZip\Zip\Core\ZipUtils::getFileExtAttr("big one1.txt")); $fhandle = fopen("big one1.txt", "rb");
// Require your bootstrap.php, or the autoload.php, and change the class instantiation from nwe ZipStream( to // new \PHPZip\Zip\Stream\ZipStream( // The parameters are unchanged. require_once('bootstrap.php'); // include_once("ZipStream.php"); //print_r(ini_get_all()); $fileTime = date("D, d M Y H:i:s T"); $chapter1 = "Chapter 1\n" . "Lorem ipsum\n" . "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n"; //$zip = new ZipStream("ZipStreamExample1s.zip"); //$zip = new ZipStream("ZipStreamExample1s_€2,000.zip"); $zip = new \PHPZip\Zip\Stream\ZipStream("ZipStreamExample1s_€2,000.zip", "application/zip", "ZipStreamExample1s_€2,000_utf8.zip"); // $zip = new ZipStream("ZipStreamExample1s_€2,000.zip", "application/zip", "ZipStreamExample1s_€2,000_utf8.zip"); // Archive comments don't really support utf-8. Some tools detect and read it though. $zip->setComment("Example Zip file for Large file sets.\nАрхив Комментарий\nCreated on " . date('l jS \of F Y h:i:s A')); // A bit of russian (I hope), to test UTF-8 file names. $zip->addFile("Привет мир!", "Кириллица имя файла.txt"); $zip->addFile("Привет мир!", "Привет мир. С комментарий к файлу.txt", 0, "Кириллица файл комментарий"); $zip->openStream("big one3.txt"); $zip->addStreamData($chapter1."\n\n\n"); $zip->addStreamData($chapter1."\n\n\n"); $zip->addStreamData($chapter1."\n\n\n"); $zip->closeStream();