unzip-js v1.0.0
unzip-js
unzip .ZIP files in the browser
Install
npm install unzip-jsUsage
var unzip = require('unzip-js')
unzip(getBlobOrFileSomehow(), function (err, zipFile) {
if (err) {
return console.error(err)
}
zipFile.readEntries(function (err, entries) {
if (err) {
return console.error(err)
}
entries.forEach(function (entry) {
zipFile.readEntryData(entry, false, function (err, readStream) {
if (err) {
return console.error(err)
}
readStream.on('data', function (chunk) { ... })
readStream.on('error', function (err) { ... })
readStream.on('end', function () { ... })
})
})
})
})API
unzip(source, callback)
source: must be aBlob,Fileorstringthat represents a valid url.callback:function(err: Error, zipFile: ZipFile)
Class: ZipFile
zipFile.readEntries(callback)\ Read metadata of all entries (parse Central Dircotroy Records).
callback:function(err: Error, entries: Entry[])
zipFile.readEntryData(entry, checkCrc, callback)\ Read data of a specific entry.
entry:Entrycallback:function(err: Error, readStream: ReadStream)checkCrc:booleaniftrue, performs a crc32 check on the extracted data.
Class: Entry\ A representation of a zip entry (a Central Dircotroy Record).
see the zip spec section 4.3.12 Central directory structure for more informations.
entry.versionMadeBy: number\
entry.versionNeededToExtract: number\
entry.generalPurposeBitFlag: number\
entry.compressionMethod: number\
entry.lastModTime: number\
entry.lastModDate: number\
entry.crc32: number\
entry.compressedSize: number\
entry.uncompressedSize: number\
entry.internalAttributes: number\
entry.externalAttributes: number\
entry.localHeaderOffset: number\
entry.name: string\
entry.commment: string\
entry.extraFields: object[]
object:{ headerId: number, dataSize: number, data: Buffer }
entry.encrypted: boolean\
retrun true if the data is encrypted.
entry.lastModTimeDate: Date\
Return a Date object representation of entry.lastModTime and entry.lastModDate.
Class: ReadStream\ see blob-slicer.
Limitations
Only files stored with no compression or compressed with deflate algorithm are supported,
zipFile.readEntryData callback will recieve an error for any entry with compression methode
other than 0 (stored) or 8 (deflated), or if the file is encrypted.
Zip files spanned across multiple removable media are not supported.
Supported browsers
| Firefox | Chrome | Internet Explorer | Edge | Safari | ios | Android |
|---|---|---|---|---|---|---|
| YES | YES | YES (10 - 11) | YES | YES | YES | YES |
License
MIT. Copyright (c) Merzouqi.
7 years ago