README.textile.txt (3547B)
1 h2. JSUnzip 2 3 A javascript library for reading the contents of zip files. 4 5 NOTE: Does not uncompress/inflate files. Zip is a package format that can use many different compression methods. See "Working with <code>JSUnzip.ZipEntry</code>" below. 6 7 <pre><code>var myZip = ... // Get it with an XHR request, HTML5 files, etc. 8 var unzipper = new JSUnzip(myZip); 9 unzipper.isZipFile(); // true or false 10 11 unzipper.readEntries(); // Creates "entries" 12 unzipper.entries; // Array of JSUnzip.ZipEntry objects. 13 </code></pre> 14 15 The test suite runs on Chrome 4, FireFox 3.6, IE7, Opera 10 and Safari 4.0.4. [TODO: Run tests on more browsers.] 16 17 h2. Download 18 19 "http://github.com/downloads/augustl/js-unzip/js-unzip.min.js":http://github.com/downloads/augustl/js-unzip/js-unzip.min.js 20 21 h2. Working with <code>JSUnzip.ZipEntry</code> objects 22 23 After <code>readEntries</code> is called, an array of <code>JSUnzip.ZipEntry</code> objects is created, one per file in the Zip archive. 24 25 <pre><code>entry = myZip.entries[0]; 26 27 // Attributes 28 entry.fileName; // The file name of the entry. Contains the full path. 29 // Examples: 30 // "foo.txt" 31 // "directory/bar.jpg" 32 entry.data; // The raw compressed data 33 entry.compressionMethod; // Number representing compression method. 34 // 1: No compression. File can be used as-is. 35 // 8: DEFLATE. The most common compression method. 36 // Use a inflate algorithm to uncompress, such 37 // as http://github.com/augustl/js-inflate/ 38 entry.compressedSize; // The size of the commpressed data 39 entry.uncompressedSize; // The size of the data when it's uncompressed 40 entry.signature; // The magic number used to determine if it is in fact 41 // a zip file. 42 entry.versionNeeded; // Zip specification version needed to work with the file. 43 entry.bitFlag; // Flag for various states 44 45 // Functions (mostly for internal use) 46 entry.isEncrypted(); 47 entry.isUsingUtf8(); 48 entry.isUzingZip64(); // Zip64 is for 4gb+ files. Not supported by this lib. 49 </code></pre> 50 51 See "http://www.pkware.com/documents/casestudies/APPNOTE.TXT":http://www.pkware.com/documents/casestudies/APPNOTE.TXT for more information about the Zip format, such as all the compression methods. 52 53 h2. Uncompressing with JSInflate 54 55 Almost all Zip files are compressed with the deflate algorithm. You can use "JSInflate":http://github.com/augustl/js-inflate to uncompress these Zips. 56 57 <pre><code>var blob = ...; // A HTML5 binary file, for example. 58 var unzipper = new JSUnzip(blob); 59 if (unzipper.isZipFile()) { 60 61 unzipper.readEntries(); 62 63 for (var i = 0; i < unzipper.entries.length; i++) { 64 var entry = unzipper.entries[i]; 65 if (entry.compressionMethod === 0) { 66 // Uncompressed 67 var uncompressed = entry.data; 68 } else if (entry.compressionMethod === 8) { 69 // Deflated 70 var uncompressed = JSInflate.inflate(entry.data); 71 } 72 } 73 }</code></pre> 74 75 h2. Credits 76 77 * Jacob Seidelin for his "JavaScript EXIF Reader":http://blog.nihilogic.dk/2008/05/reading-exif-data-with-javascript.html. 78 * Jonas Höglund for his cute little "zip parser":http://etc.firefly.nu/js/zip/zipParser.js. 79 * "Cheeso" for his "js zip library":http://cheeso.members.winisp.net/srcview.aspx?dir=js-unzip&file=js-zip.zip. 80 81 h2. About 82 83 Written by August Lilleaas <august.lilleaas@gmail.com>. Licensed under the MIT license.