Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.5.5

Request #12617 Incorrectly marks an archive/file as compressed when it's not
Submitted: 2007-12-05 08:45 UTC
From: andersapt Assigned:
Status: Analyzed Package: File_Archive (version 1.5.3)
PHP Version: 5.2.3 OS: Windows
Roadmaps: 1.5.5    
Subscription  


 [2007-12-05 08:45 UTC] andersapt (Anders S. Øfsdahl)
Description: ------------ I'm trying to make an archive of jpeg files, and only want them stored, not compressed. The archive is supposed to be loaded into a Flash 9 application, with the FZip library. This library can progressivly read zip files if they're not compressed. However, the zip file created by File_Archive incorrectly states that the files are compressed, when they're not. Test script: --------------- $file = "test_archive.zip"; // Store test jpeg File_Archive::setOption("zipCompressionLevel", 0); $source = File_Archive::read('test_file.jpg',null,0,2); $source->close(); //Move back to the begining of the source File_Archive::extract( $source, File_Archive::toArchive( $file, File_Archive::toFiles() ) ); // Load to check compression level $zip = new ZipArchive(); if( $zip->open( $file )!==true ) die( 'Could not open file '.$file ); for ($x=0; $x<$zip->numFiles; $x++) echo '<pre>'.print_r( $zip->statIndex($x), 1).'</pre>'; $zip->close(); Expected result: ---------------- I expect the value of [comp_method] from ZipArchive to be 0, not 8. Actual result: -------------- The value of [comp_method] is 8.

Comments

 [2008-05-28 19:57 UTC] cbrunet (Charles Brunet)
I cannot reproduce described behavior. I tried a similar script that the one provided, and the file isn't compressed, as expected. $ zipinfo img.zip Archive: img.zip 8791 bytes 1 file -rw---- 0.0 fat 8666 b- defN 28-May-08 10:06 charles.jpg 1 file, 8666 bytes uncompressed, 8671 bytes compressed: -0.1% Could you please try with CVS version and tell me if you still experience the bug?
 [2008-05-28 20:39 UTC] andersapt (Anders S. Øfsdahl)
I'll try with CVS and get back to you with the results soon. I'm a bit unsure if you misunderstood the issue though. The file isn't compressed (as expected), but there seems to be some kind of flag in the header of each file entry in the zip file that incorrectly states that the file is compressed, even though it's not. And this makes both FZip (in Flash) and the ZipArchive class in PHP (as my example script examplifies) *think* the file is compressed, even when it's only stored. So the issue isn't that File_Archive doesn't store the file, the issue is that it says it's compressed even though it's just stored.
 [2008-05-29 20:54 UTC] cbrunet (Charles Brunet)
I studied ZIP file format specification (http://www.pkware.com/documents/casestudies/APPNOTE.TXT) and File_Archive code, and now I really understand your issue. ZIP format can handle different compression methods. Actually, File_Archive can uncompress files using Store, Deflate or Bzip2, but always compress them using Deflate. So a compression level of 0 means 'use deflate method without compression', and not 'use store compression method'. The solution would be to tell File_Archive to use store method when compress level is 0. Maybe will I implement it on a future version...