{
	"version": 3,
	"sources": [
		"C:\\dev\\streamline-zip\\src\\unzip._js"
	],
	"names": [
		"zlib",
		"require",
		"Readbuffer",
		"exports",
		"Unzip",
		"buffer",
		"filehandler",
		"options",
		"centralDirectoryPos",
		"pos",
		"filebuffer",
		"length",
		"seek",
		"readInt32",
		"Error",
		"skip",
		"list",
		"header",
		"fileNameLength",
		"readInt16",
		"extraLength",
		"commentLength",
		"fileBlockStart",
		"method",
		"time",
		"date",
		"compressedLen",
		"uncompressedLen",
		"filenameLen",
		"extraDataLen",
		"filename",
		"readString",
		"headers",
		"size",
		"moddate",
		"getDate",
		"opts",
		"filter",
		"push",
		"compressedData",
		"readBytes",
		"uncompressedData",
		"handler",
		"decompMethods",
		"id",
		"fullDate",
		"Date",
		"setHours",
		"setMinutes",
		"setSeconds",
		"setFullYear",
		"setMonth",
		"setDate",
		"store",
		"decompress",
		"content",
		"inflate",
		"unzip",
		"result"
	],
	"mappings": ";;;;;;;AAEA,IAAIA,OAAOC,QAAQ,MAAR,CAAX;AACA,IAAIC,aAAaD,QAAQ,cAAR,CAAjB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACAE,QAAQC,KAAR,GAAgB,UAASC,MAAT,EAAiBC,WAAjB,EAA8BC,OAA9B;AAAA;AAAA;AAsCd,OAAIC,sBAAsB,CAA1B;AACC,SAAIC,MAAMC,WAAWC,MAAX,KAAsB,EAAhC,CADD,CACqC;AACpC;AACCD,iBAAWE,IAAX,CAAgBH,GAAhB;AACAA;AAFD,cAGSC,WAAWG,SAAX,OAA2B,UAA3B,IAAyCJ,MAAM,CAHxD;;AAKA,SAAIA,OAAO,CAAX;AACC,aAAM,IAAIK,KAAJ,CAAU,2CAAV,CAAN;AADD;AAGAJ,gB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AAEzB,QAAQ,CAAT,GAAc,GAAf,IAAsB,IAA3C;AACAoB,WAASM,QAAT,CAAoB1B,QAAQ,CAAT,GAAc,EAAjC;AACAoB,WAASO,OAAT,CAAmB3B,QAAQ,CAAT,GAAc,EAAhC;AACA,SAAOoB,QAAP;AA3Kc;;AAEf,KAAIF,gBAAgB;AACnBU,SAAO;AACNT,OAAI,MADE;AAENU,0DAAqBC,OAArB;AAAA;AACC,YAAOA,OAAP;AADD;AAAA;;AAFM,GADY;AAQnBC,WAAS;AACRZ,OAAI,MADI;AAERU,2DAAqBC,OAArB;AAAA;AACC,YAAO,sEAAgBA,OAAhB,QAAP;AADD;AAAA;AAFQ;;AARU,EAApB;;AAiBA,KAAI7C,aAAa,IAAIR,UAAJ,CAAeG,MAAf,CAAjB;AACA,KAAI+B,OAAO7B,WAAW,EAAtB;AACA,KAAIC,sBAAsB,CAAC,CAA3B;;AAEA;;;;;;;;;;;;;;AA4BC;;AAED;;;;;;;;;;;;;;;;;;;;;;;;;AAuDC;;AAED;AAiDC;;AAaA;;AAED,MAAKiD,KAAL;AAAA;AACC;AACA;AAFD;AAAA;AAIA,MAAKzC,IAAL;AAAA;AACC;AACA,OAAI0C,SAAS,EAAb;AACA,kFAAkBA,MAAlB;AACA,UAAOA,MAAP;AAJD;AAAA;AAlLe,CAAhB",
	"file": "unzip._js",
	"sourcesContent": [
		"\"use strict\";\r\n\r\nvar zlib = require(\"zlib\");\r\nvar Readbuffer = require(\"./readbuffer\");\r\n\r\n/// !doc\r\n/// \r\n/// # streamline-zip/lib/unzip/unzip module\r\n/// \r\n/// Simple API to unzip a zip archive.\r\n/// \r\n/// `var zip = require('streamline-zip')`\r\n/// \r\n/// * `unzipper = new zip.Unzip(buffer, filecallback[, options])` \r\n///   `buffer`: buffer containing the content of the zip file. \r\n///   `filecallback`: `function(filename, filecontent, headers, _)`: Function that is called on every file extracted. \r\n///   `options.filter`: `function(filename, headers, _)`: function called before extraction of a file, return `false` to skip. \r\n///   `headers` consists of `filename`, `size` and `moddate`. \r\n/// \r\n/// * `unzipper.unzip(_)` \r\n///   unzips the buffer.\r\n/// \r\n/// * `unzipper.list(_)` \r\n///   returns an array of all file names; `options.filter` is applied \r\n/// \r\n/// Example:\r\n/// \r\n/// ``` javascript\r\n/// var fs = require('fs');\r\n/// var zip = require(\"streamline-zip\");\r\n///\r\n/// var data = fs.readFile(\"myfile.zip\", _);\r\n/// new zip.Unzip(\r\n/// \tdata, \r\n/// \tfunction(filename, filecontent, headers, _) {\r\n/// \t\t// do something with filecontent ...\r\n/// \t},\t{\r\n/// \t\tfilter: function(filename, headers, _) {\r\n/// \t\t\t// insert your filtering condition here ...\r\n/// \t\t\treturn true;\r\n/// \t\t}\r\n/// \t}\r\n/// ).unzip(_);\r\n/// ```\r\nexports.Unzip = function(buffer, filehandler, options) {\r\n\r\n\tvar decompMethods = {\r\n\t\tstore: {\r\n\t\t\tid: 0x0000,\r\n\t\t\tdecompress: function(content, _) {\r\n\t\t\t\treturn content;\r\n\t\t\t}\r\n\r\n\t\t},\r\n\t\tinflate: {\r\n\t\t\tid: 0x0008,\r\n\t\t\tdecompress: function(content, _) {\r\n\t\t\t\treturn zlib.inflateRaw(content, _);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t};\r\n\r\n\tvar filebuffer = new Readbuffer(buffer);\r\n\tvar opts = options || {};\r\n\tvar centralDirectoryPos = -1;\r\n\r\n\t/* Look for central directory by scanning for the end of central directory block\r\n\t   (search only if position has not already been found)\r\n\t  \r\n\t \tOffset \tBytes \tDescription\r\n\t  \t 0 \t4 \tEnd of central directory signature = 0x06054b50\r\n\t\t 4 \t2 \tNumber of this disk\r\n\t\t 6 \t2 \tDisk where central directory starts\r\n\t\t 8 \t2 \tNumber of central directory records on this disk\r\n\t\t10 \t2 \tTotal number of central directory records\r\n\t\t12 \t4 \tSize of central directory (bytes)\r\n\t\t16 \t4 \tOffset of start of central directory, relative to start of archive\r\n\t\t20 \t2 \tComment length (n)\r\n\t\t22 \tn \tComment\r\n\t */\r\n\tfunction scanForCentralDir(_) {\r\n\t\tif (centralDirectoryPos < 0) {\r\n\t\t\tvar pos = filebuffer.length() - 22; // last header is at least 22 bytes\r\n\t\t\tdo {\r\n\t\t\t\tfilebuffer.seek(pos);\r\n\t\t\t\tpos--;\r\n\t\t\t} while (filebuffer.readInt32() !== 0x06054b50 && pos > 0);\r\n\r\n\t\t\tif (pos <= 0) {\r\n\t\t\t\tthrow new Error(\"Unable to locate end of central directory\");\r\n\t\t\t}\r\n\t\t\tfilebuffer.skip(12);\r\n\t\t\tcentralDirectoryPos = filebuffer.readInt32();\t\t\t\r\n\t\t}\r\n\t};\r\n\r\n\t/*\r\n\t * Optional parameter 'list': when set, just the names of the files will be put into that array, no extraction is done \r\n\t * \r\n\t\tOffset \tBytes \tDescription\r\n\t\t 0 \t4 \tCentral directory file header signature = 0x02014b50\r\n\t\t 4 \t2 \tVersion made by\r\n\t\t 6 \t2 \tVersion needed to extract (minimum)\r\n\t\t 8 \t2 \tGeneral purpose bit flag\r\n\t\t10 \t2 \tCompression method\r\n\t\t12 \t2 \tFile last modification time\r\n\t\t14 \t2 \tFile last modification date\r\n\t\t16 \t4 \tCRC-32\r\n\t\t20 \t4 \tCompressed size\r\n\t\t24 \t4 \tUncompressed size\r\n\t\t28 \t2 \tFile name length (n)\r\n\t\t30 \t2 \tExtra field length (m)\r\n\t\t32 \t2 \tFile comment length (k)\r\n\t\t34 \t2 \tDisk number where file starts\r\n\t\t36 \t2 \tInternal file attributes\r\n\t\t38 \t4 \tExternal file attributes\r\n\t\t42 \t4 \tRelative offset of local file header. This is the number of bytes between the start of the first disk on which the file occurs, and the start of the local file header. This allows software reading the central directory to locate the position of the file inside the ZIP file.\r\n\t\t46 \tn \tFile name\r\n\t\t46+n \tm \tExtra field\r\n\t\t46+n+m \tk \tFile comment\r\n\t*/\r\n\tfunction procCentralDir(_, list) {\r\n\t\tfilebuffer.seek(centralDirectoryPos);\r\n\r\n\t\twhile (true) {\r\n\t\t\tvar header = filebuffer.readInt32();\r\n\t\t\tif (header === 0x06054b50) { // regular end of central directory -> finished\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\tif (header !== 0x02014b50) {\r\n\t\t\t\tthrow new Error(\"Invalid header signature for central directory\");\r\n\t\t\t}\r\n\r\n\t\t\tfilebuffer.skip(24);\r\n\t\t\tvar fileNameLength = filebuffer.readInt16();\r\n\t\t\tvar extraLength = filebuffer.readInt16();\r\n\t\t\tvar commentLength = filebuffer.readInt16();\r\n\t\t\tfilebuffer.skip(8);\r\n\t\t\tvar fileBlockStart = filebuffer.readInt32();\r\n\t\t\tfilebuffer.skip(fileNameLength + extraLength + commentLength);\r\n\r\n\t\t\tvar pos = filebuffer.pos();\r\n\r\n\t\t\tfilebuffer.seek(fileBlockStart);\r\n\r\n\t\t\tprocFile(_, list);\r\n\r\n\t\t\tfilebuffer.seek(pos);\r\n\t\t}\r\n\t\tthrow new Error(\"Unexpected end of file\");\r\n\t};\r\n\r\n\t// Optional parameter 'list': when set, just the metadata of the files will be put into that array, no extraction is done \r\n\tfunction procFile(_, list) {\r\n\t\tif (filebuffer.readInt32() !== 0x04034b50) {\r\n\t\t\tthrow new Error(\"Invalid header signature for file block\");\r\n\t\t}\r\n\r\n\t\tfilebuffer.skip(4);\r\n\t\tvar method = filebuffer.readInt16();\r\n\t\tvar time = filebuffer.readInt16();\r\n\t\tvar date = filebuffer.readInt16();\r\n\t\tfilebuffer.skip(4); // crc\r\n\r\n\t\tvar compressedLen = filebuffer.readInt32(); // comp. len\r\n\t\tvar uncompressedLen = filebuffer.readInt32(); // uncomp. len\r\n\r\n\t\tvar filenameLen = filebuffer.readInt16(); // filename len\r\n\t\tvar extraDataLen = filebuffer.readInt16(); // extra len\r\n\t\tvar filename = filebuffer.readString(filenameLen);\r\n\r\n\t\tvar headers = {\r\n\t\t\tfilename: filename,\r\n\t\t\tsize: uncompressedLen,\r\n\t\t\tmoddate: getDate(time, date)\r\n\r\n\t\t};\r\n\t\tif (opts.filter && !opts.filter(filename, headers, _)) return;\r\n\t\t\r\n\t\tif (list) {\r\n\t\t\tlist.push(filename);\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tfilebuffer.skip(extraDataLen);\r\n\r\n\t\tvar compressedData = filebuffer.readBytes(compressedLen);\r\n\t\tvar uncompressedData;\r\n\t\tvar handler;\r\n\r\n\t\tfor (handler in decompMethods) {\r\n\t\t\tif (decompMethods[handler].id === method) {\r\n\t\t\t\tuncompressedData = decompMethods[handler].decompress(compressedData, _);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (!uncompressedData) {\r\n\t\t\tthrow new Error(\"No handler for compression method id: \" + method);\r\n\t\t}\r\n\r\n\t\tfilehandler(filename, uncompressedData, headers, _);\r\n\t};\r\n\r\n\tfunction getDate(time, date) {\r\n\t\tvar fullDate = new Date();\r\n\r\n\t\tfullDate.setHours(((time >> 11) & 32));\r\n\t\tfullDate.setMinutes(((time >> 6) & 64));\r\n\t\tfullDate.setSeconds(((time >> 0) & 32) * 2);\r\n\r\n\t\tfullDate.setFullYear(((date >> 9) & 128) + 1980);\r\n\t\tfullDate.setMonth(((date >> 5) & 16));\r\n\t\tfullDate.setDate(((date >> 0) & 32));\r\n\t\treturn fullDate;\r\n\t};\r\n\r\n\tthis.unzip = function(_) {\r\n\t\tscanForCentralDir(_);\r\n\t\tprocCentralDir(_);\r\n\t};\r\n\tthis.list = function(_) {\r\n\t\tscanForCentralDir(_);\r\n\t\tvar result = [];\r\n\t\tprocCentralDir(_, result);\r\n\t\treturn result;\r\n\t};\r\n};"
	]
}