File tree Expand file tree Collapse file tree 2 files changed +64
-0
lines changed Expand file tree Collapse file tree 2 files changed +64
-0
lines changed Original file line number Diff line number Diff line change @@ -545,6 +545,38 @@ public function testZeroData()
545545 $ this ->assertEquals (512 * 3 , strlen ($ file )); // 1 header block + 2 footer blocks
546546 }
547547
548+ /**
549+ * Add a zero byte file to a tar and extract it again
550+ */
551+ public function testZeroByteFile () {
552+ $ archive = sys_get_temp_dir () . '/dwziptest ' . md5 (time ()) . '.zip ' ;
553+ $ extract = sys_get_temp_dir () . '/dwziptest ' . md5 (time () + 1 );
554+
555+ $ tar = new Tar ();
556+ $ tar ->create ($ archive );
557+ $ tar ->addFile (__DIR__ . '/zip/zero.txt ' , 'foo/zero.txt ' );
558+ $ tar ->close ();
559+ $ this ->assertFileExists ($ archive );
560+
561+ $ tar = new Tar ();
562+ $ tar ->open ($ archive );
563+ $ contents = $ tar ->contents ();
564+
565+ $ this ->assertEquals (1 , count ($ contents ));
566+ $ this ->assertEquals ('foo/zero.txt ' , ($ contents [0 ])->getPath ());
567+
568+ $ tar = new Tar ();
569+ $ tar ->open ($ archive );
570+ $ tar ->extract ($ extract );
571+ $ tar ->close ();
572+
573+ $ this ->assertFileExists ("$ extract/foo/zero.txt " );
574+ $ this ->assertEquals (0 , filesize ("$ extract/foo/zero.txt " ));
575+
576+ self ::RDelete ($ extract );
577+ unlink ($ archive );
578+ }
579+
548580 /**
549581 * A file of exactly one block should be just a header block + data block + the footer
550582 */
Original file line number Diff line number Diff line change @@ -226,6 +226,38 @@ public function testDogFood()
226226 unlink ($ archive );
227227 }
228228
229+ /**
230+ * Add a zero byte file to a zip and extract it again
231+ */
232+ public function testZeroByteFile () {
233+ $ archive = sys_get_temp_dir () . '/dwziptest ' . md5 (time ()) . '.zip ' ;
234+ $ extract = sys_get_temp_dir () . '/dwziptest ' . md5 (time () + 1 );
235+
236+ $ zip = new Zip ();
237+ $ zip ->create ($ archive );
238+ $ zip ->addFile (__DIR__ . '/zip/zero.txt ' , 'foo/zero.txt ' );
239+ $ zip ->close ();
240+ $ this ->assertFileExists ($ archive );
241+
242+ $ zip = new Zip ();
243+ $ zip ->open ($ archive );
244+ $ contents = $ zip ->contents ();
245+
246+ $ this ->assertEquals (1 , count ($ contents ));
247+ $ this ->assertEquals ('foo/zero.txt ' , ($ contents [0 ])->getPath ());
248+
249+ $ zip = new Zip ();
250+ $ zip ->open ($ archive );
251+ $ zip ->extract ($ extract );
252+ $ zip ->close ();
253+
254+ $ this ->assertFileExists ("$ extract/foo/zero.txt " );
255+ $ this ->assertEquals (0 , filesize ("$ extract/foo/zero.txt " ));
256+
257+ self ::RDelete ($ extract );
258+ unlink ($ archive );
259+ }
260+
229261 /**
230262 * @depends testExtZipIsInstalled
231263 */
You can’t perform that action at this time.
0 commit comments