read-excel-file 9.3.3 → 9.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (255) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +32 -2
  3. package/browser/index.cjs +3 -0
  4. package/browser/index.d.ts +16 -0
  5. package/browser/index.js +4 -1
  6. package/bundle/read-excel-file.min.js +1 -1
  7. package/bundle/read-excel-file.min.js.map +1 -1
  8. package/commonjs/export/convertInputToNodeStream.js +0 -12
  9. package/commonjs/export/convertInputToNodeStream.js.map +1 -1
  10. package/commonjs/export/parseSheet.js +14 -7
  11. package/commonjs/export/parseSheet.js.map +1 -1
  12. package/commonjs/export/readSheetBrowser.js +3 -6
  13. package/commonjs/export/readSheetBrowser.js.map +1 -1
  14. package/commonjs/export/readSheetNode.js +3 -6
  15. package/commonjs/export/readSheetNode.js.map +1 -1
  16. package/commonjs/export/readSheetUniversal.js +2 -2
  17. package/commonjs/export/readSheetUniversal.js.map +1 -1
  18. package/commonjs/export/readSheetWebWorker.js +5 -5
  19. package/commonjs/export/readSheetWebWorker.js.map +1 -1
  20. package/commonjs/export/readXlsxFileBrowser.js +3 -6
  21. package/commonjs/export/readXlsxFileBrowser.js.map +1 -1
  22. package/commonjs/export/readXlsxFileNode.js +3 -6
  23. package/commonjs/export/readXlsxFileNode.js.map +1 -1
  24. package/commonjs/export/readXlsxFileUniversal.js +2 -2
  25. package/commonjs/export/readXlsxFileUniversal.js.map +1 -1
  26. package/commonjs/export/readXlsxFileWebWorker.js +5 -5
  27. package/commonjs/export/readXlsxFileWebWorker.js.map +1 -1
  28. package/commonjs/export/unpackXlsxFileBrowser.js +15 -4
  29. package/commonjs/export/unpackXlsxFileBrowser.js.map +1 -1
  30. package/commonjs/export/unpackXlsxFileBrowser.test.js.map +1 -0
  31. package/commonjs/export/unpackXlsxFileNode.js +32 -5
  32. package/commonjs/export/unpackXlsxFileNode.js.map +1 -1
  33. package/commonjs/export/unpackXlsxFileNode.test.js.map +1 -0
  34. package/commonjs/export/unpackXlsxFileUniversal.js +14 -3
  35. package/commonjs/export/unpackXlsxFileUniversal.js.map +1 -1
  36. package/commonjs/export/unpackXlsxFileUniversal.test.js.map +1 -0
  37. package/commonjs/parseSheetData/parseSheetData.js +9 -6
  38. package/commonjs/parseSheetData/parseSheetData.js.map +1 -1
  39. package/commonjs/saxen/parser.js +1 -1
  40. package/commonjs/saxen/parser.js.map +1 -1
  41. package/commonjs/utility/convertValuesFromUint8ArraysToStrings.js +100 -0
  42. package/commonjs/utility/convertValuesFromUint8ArraysToStrings.js.map +1 -0
  43. package/commonjs/xlsx/InvalidSpreadsheetError.js +55 -0
  44. package/commonjs/xlsx/InvalidSpreadsheetError.js.map +1 -0
  45. package/commonjs/xlsx/SheetNotFoundError.js +55 -0
  46. package/commonjs/xlsx/SheetNotFoundError.js.map +1 -0
  47. package/commonjs/xlsx/file/InputValidationStream.js +101 -0
  48. package/commonjs/xlsx/file/InputValidationStream.js.map +1 -0
  49. package/commonjs/xlsx/file/InputValidationStream.test.js.map +1 -0
  50. package/commonjs/xlsx/file/InvalidInputError.js +105 -0
  51. package/commonjs/xlsx/file/InvalidInputError.js.map +1 -0
  52. package/commonjs/xlsx/file/createFileTypeDetector.js +70 -0
  53. package/commonjs/xlsx/file/createFileTypeDetector.js.map +1 -0
  54. package/commonjs/xlsx/file/createFileTypeDetector.test.js.map +1 -0
  55. package/commonjs/xlsx/file/validateLeadingBytes.js +47 -0
  56. package/commonjs/xlsx/file/validateLeadingBytes.js.map +1 -0
  57. package/commonjs/xlsx/file/validateLeadingBytes.test.js.map +1 -0
  58. package/commonjs/xlsx/isDateFormat.js +32 -27
  59. package/commonjs/xlsx/isDateFormat.js.map +1 -1
  60. package/commonjs/xlsx/isDateFormatStyle.js +19 -21
  61. package/commonjs/xlsx/isDateFormatStyle.js.map +1 -1
  62. package/commonjs/xlsx/parseCell.js +252 -115
  63. package/commonjs/xlsx/parseCell.js.map +1 -1
  64. package/commonjs/xlsx/parseCellAddress.js +22 -18
  65. package/commonjs/xlsx/parseCellAddress.js.map +1 -1
  66. package/commonjs/xlsx/parseExcelDate.js +4 -124
  67. package/commonjs/xlsx/parseExcelDate.js.map +1 -1
  68. package/commonjs/xlsx/parseExcelDate.test.js.map +1 -1
  69. package/commonjs/xlsx/parseExcelTimestamp.js +139 -0
  70. package/commonjs/xlsx/parseExcelTimestamp.js.map +1 -0
  71. package/commonjs/xlsx/parseFilePaths.js +48 -47
  72. package/commonjs/xlsx/parseFilePaths.js.map +1 -1
  73. package/commonjs/xlsx/parseSharedStrings.js +91 -36
  74. package/commonjs/xlsx/parseSharedStrings.js.map +1 -1
  75. package/commonjs/xlsx/parseSheet.js +527 -69
  76. package/commonjs/xlsx/parseSheet.js.map +1 -1
  77. package/commonjs/xlsx/parseSpreadsheetContents.js +154 -83
  78. package/commonjs/xlsx/parseSpreadsheetContents.js.map +1 -1
  79. package/commonjs/xlsx/parseSpreadsheetInfo.js +60 -59
  80. package/commonjs/xlsx/parseSpreadsheetInfo.js.map +1 -1
  81. package/commonjs/xlsx/parseStyles.js +75 -75
  82. package/commonjs/xlsx/parseStyles.js.map +1 -1
  83. package/commonjs/xml/parseXml.js +112 -0
  84. package/commonjs/xml/parseXml.js.map +1 -0
  85. package/commonjs/xml/parseXml.test.js.map +1 -0
  86. package/commonjs/xml/parseXmlStream.js.map +1 -1
  87. package/commonjs/xml/parseXmlStream.sax.js +69 -28
  88. package/commonjs/xml/parseXmlStream.sax.js.map +1 -1
  89. package/commonjs/xml/parseXmlStream.saxen.js +66 -40
  90. package/commonjs/xml/parseXmlStream.saxen.js.map +1 -1
  91. package/commonjs/zip/UnzipError.js +55 -0
  92. package/commonjs/zip/UnzipError.js.map +1 -0
  93. package/commonjs/zip/unzipFromArrayBuffer.js +21 -1
  94. package/commonjs/zip/unzipFromArrayBuffer.js.map +1 -1
  95. package/commonjs/zip/unzipFromArrayBuffer.test.js.map +1 -0
  96. package/commonjs/zip/unzipFromStream.fflate.js +43 -35
  97. package/commonjs/zip/unzipFromStream.fflate.js.map +1 -1
  98. package/commonjs/zip/unzipFromStream.js +188 -6
  99. package/commonjs/zip/unzipFromStream.js.map +1 -1
  100. package/commonjs/zip/unzipFromStream.unzipper.js +19 -34
  101. package/commonjs/zip/unzipFromStream.unzipper.js.map +1 -1
  102. package/modules/export/convertInputToNodeStream.js +0 -12
  103. package/modules/export/convertInputToNodeStream.js.map +1 -1
  104. package/modules/export/parseSheet.js +13 -6
  105. package/modules/export/parseSheet.js.map +1 -1
  106. package/modules/export/readSheetBrowser.js +3 -5
  107. package/modules/export/readSheetBrowser.js.map +1 -1
  108. package/modules/export/readSheetNode.js +3 -5
  109. package/modules/export/readSheetNode.js.map +1 -1
  110. package/modules/export/readSheetUniversal.js +2 -2
  111. package/modules/export/readSheetUniversal.js.map +1 -1
  112. package/modules/export/readSheetWebWorker.js +7 -8
  113. package/modules/export/readSheetWebWorker.js.map +1 -1
  114. package/modules/export/readXlsxFileBrowser.js +3 -5
  115. package/modules/export/readXlsxFileBrowser.js.map +1 -1
  116. package/modules/export/readXlsxFileNode.js +3 -5
  117. package/modules/export/readXlsxFileNode.js.map +1 -1
  118. package/modules/export/readXlsxFileUniversal.js +2 -2
  119. package/modules/export/readXlsxFileUniversal.js.map +1 -1
  120. package/modules/export/readXlsxFileWebWorker.js +7 -8
  121. package/modules/export/readXlsxFileWebWorker.js.map +1 -1
  122. package/modules/export/unpackXlsxFileBrowser.js +15 -4
  123. package/modules/export/unpackXlsxFileBrowser.js.map +1 -1
  124. package/modules/export/unpackXlsxFileBrowser.test.js.map +1 -0
  125. package/modules/export/unpackXlsxFileNode.js +32 -5
  126. package/modules/export/unpackXlsxFileNode.js.map +1 -1
  127. package/modules/export/unpackXlsxFileNode.test.js.map +1 -0
  128. package/modules/export/unpackXlsxFileUniversal.js +14 -3
  129. package/modules/export/unpackXlsxFileUniversal.js.map +1 -1
  130. package/modules/export/unpackXlsxFileUniversal.test.js.map +1 -0
  131. package/modules/parseSheetData/parseSheetData.js +9 -6
  132. package/modules/parseSheetData/parseSheetData.js.map +1 -1
  133. package/modules/saxen/parser.js +1 -1
  134. package/modules/saxen/parser.js.map +1 -1
  135. package/modules/utility/convertValuesFromUint8ArraysToStrings.js +92 -0
  136. package/modules/utility/convertValuesFromUint8ArraysToStrings.js.map +1 -0
  137. package/modules/xlsx/InvalidSpreadsheetError.js +50 -0
  138. package/modules/xlsx/InvalidSpreadsheetError.js.map +1 -0
  139. package/modules/xlsx/SheetNotFoundError.js +50 -0
  140. package/modules/xlsx/SheetNotFoundError.js.map +1 -0
  141. package/modules/xlsx/file/InputValidationStream.js +96 -0
  142. package/modules/xlsx/file/InputValidationStream.js.map +1 -0
  143. package/modules/xlsx/file/InputValidationStream.test.js.map +1 -0
  144. package/modules/xlsx/file/InvalidInputError.js +100 -0
  145. package/modules/xlsx/file/InvalidInputError.js.map +1 -0
  146. package/modules/xlsx/file/createFileTypeDetector.js +63 -0
  147. package/modules/xlsx/file/createFileTypeDetector.js.map +1 -0
  148. package/modules/xlsx/file/createFileTypeDetector.test.js.map +1 -0
  149. package/modules/xlsx/file/validateLeadingBytes.js +37 -0
  150. package/modules/xlsx/file/validateLeadingBytes.js.map +1 -0
  151. package/modules/xlsx/file/validateLeadingBytes.test.js.map +1 -0
  152. package/modules/xlsx/isDateFormat.js +31 -27
  153. package/modules/xlsx/isDateFormat.js.map +1 -1
  154. package/modules/xlsx/isDateFormatStyle.js +18 -21
  155. package/modules/xlsx/isDateFormatStyle.js.map +1 -1
  156. package/modules/xlsx/parseCell.js +251 -111
  157. package/modules/xlsx/parseCell.js.map +1 -1
  158. package/modules/xlsx/parseCellAddress.js +21 -18
  159. package/modules/xlsx/parseCellAddress.js.map +1 -1
  160. package/modules/xlsx/parseExcelDate.js +4 -124
  161. package/modules/xlsx/parseExcelDate.js.map +1 -1
  162. package/modules/xlsx/parseExcelDate.test.js.map +1 -1
  163. package/modules/xlsx/parseExcelTimestamp.js +133 -0
  164. package/modules/xlsx/parseExcelTimestamp.js.map +1 -0
  165. package/modules/xlsx/parseFilePaths.js +48 -47
  166. package/modules/xlsx/parseFilePaths.js.map +1 -1
  167. package/modules/xlsx/parseSharedStrings.js +91 -37
  168. package/modules/xlsx/parseSharedStrings.js.map +1 -1
  169. package/modules/xlsx/parseSheet.js +526 -68
  170. package/modules/xlsx/parseSheet.js.map +1 -1
  171. package/modules/xlsx/parseSpreadsheetContents.js +153 -81
  172. package/modules/xlsx/parseSpreadsheetContents.js.map +1 -1
  173. package/modules/xlsx/parseSpreadsheetInfo.js +60 -59
  174. package/modules/xlsx/parseSpreadsheetInfo.js.map +1 -1
  175. package/modules/xlsx/parseStyles.js +75 -75
  176. package/modules/xlsx/parseStyles.js.map +1 -1
  177. package/modules/xml/parseXml.js +106 -0
  178. package/modules/xml/parseXml.js.map +1 -0
  179. package/modules/xml/parseXml.test.js.map +1 -0
  180. package/modules/xml/parseXmlStream.js +2 -0
  181. package/modules/xml/parseXmlStream.js.map +1 -1
  182. package/modules/xml/parseXmlStream.sax.js +69 -28
  183. package/modules/xml/parseXmlStream.sax.js.map +1 -1
  184. package/modules/xml/parseXmlStream.saxen.js +67 -40
  185. package/modules/xml/parseXmlStream.saxen.js.map +1 -1
  186. package/modules/zip/UnzipError.js +49 -0
  187. package/modules/zip/UnzipError.js.map +1 -0
  188. package/modules/zip/unzipFromArrayBuffer.js +21 -1
  189. package/modules/zip/unzipFromArrayBuffer.js.map +1 -1
  190. package/modules/zip/unzipFromArrayBuffer.test.js.map +1 -0
  191. package/modules/zip/unzipFromStream.fflate.js +41 -35
  192. package/modules/zip/unzipFromStream.fflate.js.map +1 -1
  193. package/modules/zip/unzipFromStream.js +124 -1
  194. package/modules/zip/unzipFromStream.js.map +1 -1
  195. package/modules/zip/unzipFromStream.unzipper.js +19 -35
  196. package/modules/zip/unzipFromStream.unzipper.js.map +1 -1
  197. package/node/index.cjs +3 -0
  198. package/node/index.d.ts +16 -0
  199. package/node/index.js +3 -0
  200. package/package.json +5 -3
  201. package/types/InvalidInputError.d.ts +16 -0
  202. package/types/InvalidSpreadsheetError.d.ts +4 -0
  203. package/types/SheetNotFoundError.d.ts +4 -0
  204. package/universal/index.cjs +3 -0
  205. package/universal/index.d.ts +16 -0
  206. package/universal/index.js +3 -0
  207. package/web-worker/index.cjs +3 -0
  208. package/web-worker/index.d.ts +16 -0
  209. package/web-worker/index.js +3 -0
  210. package/commonjs/export/convertValuesFromUint8ArraysToStrings.js +0 -23
  211. package/commonjs/export/convertValuesFromUint8ArraysToStrings.js.map +0 -1
  212. package/commonjs/xlsx/convertCellsToData2dArray.js +0 -84
  213. package/commonjs/xlsx/convertCellsToData2dArray.js.map +0 -1
  214. package/commonjs/xlsx/dropEmptyColumns.js +0 -40
  215. package/commonjs/xlsx/dropEmptyColumns.js.map +0 -1
  216. package/commonjs/xlsx/dropEmptyColumns.test.js.map +0 -1
  217. package/commonjs/xlsx/dropEmptyRows.js +0 -43
  218. package/commonjs/xlsx/dropEmptyRows.js.map +0 -1
  219. package/commonjs/xlsx/dropEmptyRows.test.js.map +0 -1
  220. package/commonjs/xlsx/parseCellValue.js +0 -186
  221. package/commonjs/xlsx/parseCellValue.js.map +0 -1
  222. package/commonjs/xlsx/parseNumber.js +0 -20
  223. package/commonjs/xlsx/parseNumber.js.map +0 -1
  224. package/commonjs/xlsx/parseSharedString.js +0 -64
  225. package/commonjs/xlsx/parseSharedString.js.map +0 -1
  226. package/commonjs/xlsx/parseSheetData.js +0 -68
  227. package/commonjs/xlsx/parseSheetData.js.map +0 -1
  228. package/commonjs/xlsx/reconstructSheetDimensionsFromSheetCells.js +0 -29
  229. package/commonjs/xlsx/reconstructSheetDimensionsFromSheetCells.js.map +0 -1
  230. package/commonjs/xml/parseXmlStream.saxen.code.js +0 -953
  231. package/commonjs/xml/parseXmlStream.saxen.code.js.map +0 -1
  232. package/commonjs/xml/parseXmlStream.test.js.map +0 -1
  233. package/modules/export/convertValuesFromUint8ArraysToStrings.js +0 -17
  234. package/modules/export/convertValuesFromUint8ArraysToStrings.js.map +0 -1
  235. package/modules/xlsx/convertCellsToData2dArray.js +0 -77
  236. package/modules/xlsx/convertCellsToData2dArray.js.map +0 -1
  237. package/modules/xlsx/dropEmptyColumns.js +0 -34
  238. package/modules/xlsx/dropEmptyColumns.js.map +0 -1
  239. package/modules/xlsx/dropEmptyColumns.test.js.map +0 -1
  240. package/modules/xlsx/dropEmptyRows.js +0 -37
  241. package/modules/xlsx/dropEmptyRows.js.map +0 -1
  242. package/modules/xlsx/dropEmptyRows.test.js.map +0 -1
  243. package/modules/xlsx/parseCellValue.js +0 -180
  244. package/modules/xlsx/parseCellValue.js.map +0 -1
  245. package/modules/xlsx/parseNumber.js +0 -14
  246. package/modules/xlsx/parseNumber.js.map +0 -1
  247. package/modules/xlsx/parseSharedString.js +0 -55
  248. package/modules/xlsx/parseSharedString.js.map +0 -1
  249. package/modules/xlsx/parseSheetData.js +0 -55
  250. package/modules/xlsx/parseSheetData.js.map +0 -1
  251. package/modules/xlsx/reconstructSheetDimensionsFromSheetCells.js +0 -23
  252. package/modules/xlsx/reconstructSheetDimensionsFromSheetCells.js.map +0 -1
  253. package/modules/xml/parseXmlStream.saxen.code.js +0 -947
  254. package/modules/xml/parseXmlStream.saxen.code.js.map +0 -1
  255. package/modules/xml/parseXmlStream.test.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UnzipError.js","names":["UnzipError","exports","_Error","_inherits","_super","_createSuper","_classCallCheck","apply","arguments","_createClass","_wrapNativeSuper","Error","createUnzipError","error","unzipError","message","stack","captureStackTrace","cause"],"sources":["../../source/zip/UnzipError.js"],"sourcesContent":["export default class UnzipError extends Error {}\r\n\r\nexport function createUnzipError(error) {\r\n\tconst unzipError = new UnzipError(error.message)\r\n\t// Keep original stack if it exists\r\n\tif (error.stack) {\r\n\t\tunzipError.stack = error.stack\r\n\t}\r\n\t// Clean up stack trace a bit in Node.js/V8 environments\r\n\tif (Error.captureStackTrace) {\r\n\t\tError.captureStackTrace(unzipError, createUnzipError)\r\n\t}\r\n\t// `Error.prototype.cause` property indicates the specific, original reason\r\n\t// a given error occurred. Standardized in ES2022, it allows you to chain errors\r\n\t// by catching a low-level exception and re-throwing a meaningful, high-level error\r\n\t// without wiping out the diagnostic context or stack trace of the original failure.\r\n\t//\r\n\t// Adding a `.cause` property mimics modern error chaining for environments that support it\r\n\t// while remaining completely harmless in older systems.\r\n\t//\r\n\tunzipError.cause = error\r\n\t// Return the error.\r\n\treturn unzipError\r\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;IAAqBA,UAAU,GAAAC,OAAA,qCAAAC,MAAA;EAAAC,SAAA,CAAAH,UAAA,EAAAE,MAAA;EAAA,IAAAE,MAAA,GAAAC,YAAA,CAAAL,UAAA;EAAA,SAAAA,WAAA;IAAAM,eAAA,OAAAN,UAAA;IAAA,OAAAI,MAAA,CAAAG,KAAA,OAAAC,SAAA;EAAA;EAAA,OAAAC,YAAA,CAAAT,UAAA;AAAA,gBAAAU,gBAAA,CAASC,KAAK;AAEtC,SAASC,gBAAgBA,CAACC,KAAK,EAAE;EACvC,IAAMC,UAAU,GAAG,IAAId,UAAU,CAACa,KAAK,CAACE,OAAO,CAAC;EAChD;EACA,IAAIF,KAAK,CAACG,KAAK,EAAE;IAChBF,UAAU,CAACE,KAAK,GAAGH,KAAK,CAACG,KAAK;EAC/B;EACA;EACA,IAAIL,KAAK,CAACM,iBAAiB,EAAE;IAC5BN,KAAK,CAACM,iBAAiB,CAACH,UAAU,EAAEF,gBAAgB,CAAC;EACtD;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACAE,UAAU,CAACI,KAAK,GAAGL,KAAK;EACxB;EACA,OAAOC,UAAU;AAClB"}
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports["default"] = unzipFromArrayBuffer;
7
7
  exports.unzipFromArrayBufferUsingFunction = unzipFromArrayBufferUsingFunction;
8
8
  var _fflate = require("fflate");
9
+ var _UnzipError = require("./UnzipError.js");
9
10
  // `fflate` uses "synchronous" decompressor on `.zip` files that're under `512KB`
10
11
  // (or when the compression level is too low), and an "asynchronous" (web worker)
11
12
  // decompressor otherwise, as it can be seen from the source code of the `unzip()` function.
@@ -27,7 +28,7 @@ function unzipFromArrayBuffer(input, options) {
27
28
  * @param {ArrayBuffer} input
28
29
  * @param {(ArrayBuffer) => Record<string, Uint8Array> | Promise<Record<string, Uint8Array>>} unzip
29
30
  * @param {boolean} isAsync — Should be `true` when `unzip()` returns a `Promise`, `false` otherwise.
30
- * @return {Promise<Record<string,Uint8Array>>|Record<string,Uint8Array>} Resolves to an object holding `*.zip` file entries.
31
+ * @return {Promise<Record<string,Uint8Array>> | Record<string,Uint8Array>} Resolves to an object holding `*.zip` file entries.
31
32
  */
32
33
  function unzipFromArrayBufferUsingFunction(input) {
33
34
  var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
@@ -46,6 +47,15 @@ function unzipFromArrayBufferUsingFunction(input) {
46
47
  }
47
48
  return true;
48
49
  }
50
+ }).then(function (result) {
51
+ return result;
52
+ }, function (error) {
53
+ // If `fflate` throws its specific error then it implies that the `.zip` file is not valid.
54
+ if (isFlateError(error)) {
55
+ throw (0, _UnzipError.createUnzipError)(error);
56
+ } else {
57
+ throw error;
58
+ }
49
59
  });
50
60
  }
51
61
  function unzipAsync(archive) {
@@ -62,4 +72,14 @@ function unzipAsync(archive) {
62
72
  });
63
73
  });
64
74
  }
75
+
76
+ // This function attempts to guess if a given `error` was thrown by `fflate`.
77
+ function isFlateError(error) {
78
+ // `fflate` doesn't export a `FlateError` class.
79
+ // https://github.com/101arrowz/fflate/issues/290
80
+ // return error instanceof FlateError
81
+
82
+ // Here, it attempts to guess if an `error` is a `FlateError` by checking if `error.code` is a `number`.
83
+ return typeof error.code === 'number';
84
+ }
65
85
  //# sourceMappingURL=unzipFromArrayBuffer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"unzipFromArrayBuffer.js","names":["_fflate","require","unzipFromArrayBuffer","input","options","unzipFromArrayBufferUsingFunction","unzipAsync","_ref","arguments","length","undefined","filter","unzip","isAsync","Uint8Array","file","path","name","archive","Promise","resolve","reject","error","files"],"sources":["../../source/zip/unzipFromArrayBuffer.js"],"sourcesContent":["// `fflate` uses \"synchronous\" decompressor on `.zip` files that're under `512KB`\r\n// (or when the compression level is too low), and an \"asynchronous\" (web worker)\r\n// decompressor otherwise, as it can be seen from the source code of the `unzip()` function.\r\n// This is because using web workers comes with an overhead of\r\n// both creating a new worker and sending data back and forth.\r\n//\r\nimport { unzip } from 'fflate'\r\n\r\n/**\r\n * Reads `*.zip` file contents. Ignores anything besides `.xml` or `.xml.rels` files.\r\n * @param {ArrayBuffer} input\r\n * @return {Promise<Record<string,Uint8Array>>} Resolves to an object holding `*.zip` file entries.\r\n */\r\nexport default function unzipFromArrayBuffer(input, options) {\r\n\treturn unzipFromArrayBufferUsingFunction(input, options, unzipAsync, true)\r\n}\r\n\r\n/**\r\n * Reads `*.zip` file contents. Ignores anything besides `.xml` or `.xml.rels` files.\r\n * @param {ArrayBuffer} input\r\n * @param {(ArrayBuffer) => Record<string, Uint8Array> | Promise<Record<string, Uint8Array>>} unzip\r\n * @param {boolean} isAsync — Should be `true` when `unzip()` returns a `Promise`, `false` otherwise.\r\n * @return {Promise<Record<string,Uint8Array>>|Record<string,Uint8Array>} Resolves to an object holding `*.zip` file entries.\r\n */\r\nexport function unzipFromArrayBufferUsingFunction(input, { filter } = {}, unzip, isAsync) {\r\n\t// Read the `.zip` archive.\r\n\t// `result` is either `object` or `Promise<object>`\r\n\treturn unzip(new Uint8Array(input), {\r\n\t\t// Ignore certain types of files.\r\n\t\tfilter: (file) => {\r\n\t\t\tif (filter) {\r\n\t\t\t\treturn filter({\r\n\t\t\t\t\tpath: file.name\r\n\t\t\t\t})\r\n\t\t\t}\r\n\t\t\treturn true\r\n\t\t}\r\n\t})\r\n}\r\n\r\nfunction unzipAsync(archive) {\r\n return new Promise((resolve, reject) => {\r\n\t\t// `unzip()` will resort to \"synchronous\" decompression in two edge cases:\r\n // * When the archive size is less than `512KB`.\r\n // * When the data is barely compressed, i.e. the compression ratio is less than 20% reduction in size.\r\n unzip(archive, (error, files) => {\r\n if (error) {\r\n reject(error)\r\n } else {\r\n resolve(files)\r\n }\r\n })\r\n })\r\n}"],"mappings":";;;;;;;AAMA,IAAAA,OAAA,GAAAC,OAAA;AANA;AACA;AACA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACe,SAASC,oBAAoBA,CAACC,KAAK,EAAEC,OAAO,EAAE;EAC5D,OAAOC,iCAAiC,CAACF,KAAK,EAAEC,OAAO,EAAEE,UAAU,EAAE,IAAI,CAAC;AAC3E;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASD,iCAAiCA,CAACF,KAAK,EAAmC;EAAA,IAAAI,IAAA,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAApB,CAAC,CAAC;IAAbG,OAAM,GAAAJ,IAAA,CAANI,MAAM;EAAA,IAASC,KAAK,GAAAJ,SAAA,CAAAC,MAAA,OAAAD,SAAA,MAAAE,SAAA;EAAA,IAAEG,OAAO,GAAAL,SAAA,CAAAC,MAAA,OAAAD,SAAA,MAAAE,SAAA;EACvF;EACA;EACA,OAAOE,KAAK,CAAC,IAAIE,UAAU,CAACX,KAAK,CAAC,EAAE;IACnC;IACAQ,MAAM,EAAE,SAAAA,OAACI,IAAI,EAAK;MACjB,IAAIJ,OAAM,EAAE;QACX,OAAOA,OAAM,CAAC;UACbK,IAAI,EAAED,IAAI,CAACE;QACZ,CAAC,CAAC;MACH;MACA,OAAO,IAAI;IACZ;EACD,CAAC,CAAC;AACH;AAEA,SAASX,UAAUA,CAACY,OAAO,EAAE;EAC3B,OAAO,IAAIC,OAAO,CAAC,UAACC,OAAO,EAAEC,MAAM,EAAK;IACxC;IACE;IACA;IACA,IAAAT,aAAK,EAACM,OAAO,EAAE,UAACI,KAAK,EAAEC,KAAK,EAAK;MAC/B,IAAID,KAAK,EAAE;QACTD,MAAM,CAACC,KAAK,CAAC;MACf,CAAC,MAAM;QACLF,OAAO,CAACG,KAAK,CAAC;MAChB;IACF,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ"}
1
+ {"version":3,"file":"unzipFromArrayBuffer.js","names":["_fflate","require","_UnzipError","unzipFromArrayBuffer","input","options","unzipFromArrayBufferUsingFunction","unzipAsync","_ref","arguments","length","undefined","filter","unzip","isAsync","Uint8Array","file","path","name","then","result","error","isFlateError","createUnzipError","archive","Promise","resolve","reject","files","code"],"sources":["../../source/zip/unzipFromArrayBuffer.js"],"sourcesContent":["// `fflate` uses \"synchronous\" decompressor on `.zip` files that're under `512KB`\r\n// (or when the compression level is too low), and an \"asynchronous\" (web worker)\r\n// decompressor otherwise, as it can be seen from the source code of the `unzip()` function.\r\n// This is because using web workers comes with an overhead of\r\n// both creating a new worker and sending data back and forth.\r\n//\r\nimport { unzip } from 'fflate'\r\n\r\nimport { createUnzipError } from './UnzipError.js'\r\n\r\n/**\r\n * Reads `*.zip` file contents. Ignores anything besides `.xml` or `.xml.rels` files.\r\n * @param {ArrayBuffer} input\r\n * @return {Promise<Record<string,Uint8Array>>} Resolves to an object holding `*.zip` file entries.\r\n */\r\nexport default function unzipFromArrayBuffer(input, options) {\r\n\treturn unzipFromArrayBufferUsingFunction(input, options, unzipAsync, true)\r\n}\r\n\r\n/**\r\n * Reads `*.zip` file contents. Ignores anything besides `.xml` or `.xml.rels` files.\r\n * @param {ArrayBuffer} input\r\n * @param {(ArrayBuffer) => Record<string, Uint8Array> | Promise<Record<string, Uint8Array>>} unzip\r\n * @param {boolean} isAsync — Should be `true` when `unzip()` returns a `Promise`, `false` otherwise.\r\n * @return {Promise<Record<string,Uint8Array>> | Record<string,Uint8Array>} Resolves to an object holding `*.zip` file entries.\r\n */\r\nexport function unzipFromArrayBufferUsingFunction(input, { filter } = {}, unzip, isAsync) {\r\n\t// Read the `.zip` archive.\r\n\t// `result` is either `object` or `Promise<object>`\r\n\treturn unzip(new Uint8Array(input), {\r\n\t\t// Ignore certain types of files.\r\n\t\tfilter: (file) => {\r\n\t\t\tif (filter) {\r\n\t\t\t\treturn filter({\r\n\t\t\t\t\tpath: file.name\r\n\t\t\t\t})\r\n\t\t\t}\r\n\t\t\treturn true\r\n\t\t}\r\n\t}).then(\r\n\t\tresult => result,\r\n\t\t(error) => {\r\n\t\t\t// If `fflate` throws its specific error then it implies that the `.zip` file is not valid.\r\n\t\t\tif (isFlateError(error)) {\r\n\t\t\t\tthrow createUnzipError(error)\r\n\t\t\t} else {\r\n\t\t\t\tthrow error\r\n\t\t\t}\r\n\t\t}\r\n\t)\r\n}\r\n\r\nfunction unzipAsync(archive) {\r\n return new Promise((resolve, reject) => {\r\n\t\t// `unzip()` will resort to \"synchronous\" decompression in two edge cases:\r\n // * When the archive size is less than `512KB`.\r\n // * When the data is barely compressed, i.e. the compression ratio is less than 20% reduction in size.\r\n unzip(archive, (error, files) => {\r\n if (error) {\r\n reject(error)\r\n } else {\r\n resolve(files)\r\n }\r\n })\r\n })\r\n}\r\n\r\n// This function attempts to guess if a given `error` was thrown by `fflate`.\r\nfunction isFlateError(error) {\r\n\t// `fflate` doesn't export a `FlateError` class.\r\n\t// https://github.com/101arrowz/fflate/issues/290\r\n\t// return error instanceof FlateError\r\n\r\n\t// Here, it attempts to guess if an `error` is a `FlateError` by checking if `error.code` is a `number`.\r\n\treturn typeof error.code === 'number'\r\n}\r\n"],"mappings":";;;;;;;AAMA,IAAAA,OAAA,GAAAC,OAAA;AAEA,IAAAC,WAAA,GAAAD,OAAA;AARA;AACA;AACA;AACA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACe,SAASE,oBAAoBA,CAACC,KAAK,EAAEC,OAAO,EAAE;EAC5D,OAAOC,iCAAiC,CAACF,KAAK,EAAEC,OAAO,EAAEE,UAAU,EAAE,IAAI,CAAC;AAC3E;;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AAK,EAAE;EAC5B;EACA;EACA;;EAEA;EACA,OAAO,OAAOA,KAAK,CAACQ,IAAI,KAAK,QAAQ;AACtC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unzipFromArrayBuffer.test.js","names":["_mocha","require","_chai","_fflate","_unzipFromArrayBuffer","_interopRequireDefault","obj","__esModule","_regeneratorRuntime","e","t","r","Object","prototype","n","hasOwnProperty","o","defineProperty","value","i","Symbol","a","iterator","c","asyncIterator","u","toStringTag","define","enumerable","configurable","writable","wrap","Generator","create","Context","makeInvokeMethod","tryCatch","type","arg","call","h","l","f","s","y","GeneratorFunction","GeneratorFunctionPrototype","p","d","getPrototypeOf","v","values","g","defineIteratorMethods","forEach","_invoke","AsyncIterator","invoke","_typeof","resolve","__await","then","callInvokeWithMethodAndArg","Error","done","method","delegate","maybeInvokeDelegate","sent","_sent","dispatchException","abrupt","TypeError","resultName","next","nextLoc","pushTryEntry","tryLoc","catchLoc","finallyLoc","afterLoc","tryEntries","push","resetTryEntry","completion","reset","isNaN","length","displayName","isGeneratorFunction","constructor","name","mark","setPrototypeOf","__proto__","awrap","async","Promise","keys","reverse","pop","prev","charAt","slice","stop","rval","handle","complete","finish","_catch","delegateYield","asyncGeneratorStep","gen","reject","_next","_throw","key","info","error","_asyncToGenerator","fn","self","args","arguments","apply","err","undefined","describe","it","_callee","zip","files","_callee$","_context","zipSync","strToU8","unzipFromArrayBuffer","expect","to","deep","equal"],"sources":["../../source/zip/unzipFromArrayBuffer.test.js"],"sourcesContent":["import { describe, it } from 'mocha'\r\nimport { expect } from 'chai'\r\n\r\nimport { zipSync, strToU8 } from 'fflate'\r\n\r\nimport unzipFromArrayBuffer from './unzipFromArrayBuffer.js'\r\n\r\ndescribe('unzipFromArrayBuffer', () => {\r\n\tit('should read a `.zip` archive', async () => {\r\n\t\tconst zip = zipSync({ 'a.xml': strToU8('<a/>') })\r\n\t\tconst files = await unzipFromArrayBuffer(zip)\r\n\t\texpect(Object.keys(files)).to.deep.equal(['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IAAA,YAAAR,MAAAhG,KAAA,IAAA6F,kBAAA,CAAAC,GAAA,EAAArD,OAAA,EAAAsD,MAAA,EAAAC,KAAA,EAAAC,MAAA,UAAAjG,KAAA,cAAAiG,OAAAU,GAAA,IAAAd,kBAAA,CAAAC,GAAA,EAAArD,OAAA,EAAAsD,MAAA,EAAAC,KAAA,EAAAC,MAAA,WAAAU,GAAA,KAAAX,KAAA,CAAAY,SAAA;AAMA,IAAAC,eAAQ,EAAC,sBAAsB,EAAE,YAAM;EACtC,IAAAC,SAAE,EAAC,8BAA8B,eAAAT,iBAAA,eAAA/G,mBAAA,GAAAoF,IAAA,CAAE,SAAAqC,QAAA;IAAA,IAAAC,GAAA,EAAAC,KAAA;IAAA,OAAA3H,mBAAA,GAAAuB,IAAA,UAAAqG,SAAAC,QAAA;MAAA,kBAAAA,QAAA,CAAAhC,IAAA,GAAAgC,QAAA,CAAA3D,IAAA;QAAA;UAC5BwD,GAAG,GAAG,IAAAI,eAAO,EAAC;YAAE,OAAO,EAAE,IAAAC,eAAO,EAAC,MAAM;UAAE,CAAC,CAAC;UAAAF,QAAA,CAAA3D,IAAA;UAAA,OAC7B,IAAA8D,gCAAoB,EAACN,GAAG,CAAC;QAAA;UAAvCC,KAAK,GAAAE,QAAA,CAAAjE,IAAA;UACX,IAAAqE,YAAM,EAAC7H,MAAM,CAACsF,IAAI,CAACiC,KAAK,CAAC,CAAC,CAACO,EAAE,CAACC,IAAI,CAACC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC;QAAA;QAAA;UAAA,OAAAP,QAAA,CAAA7B,IAAA;MAAA;IAAA,GAAAyB,OAAA;EAAA,CACnD,GAAC;AACH,CAAC,CAAC"}
@@ -3,10 +3,13 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports["default"] = unzipFromStream;
6
+ exports["default"] = unzipFromStream_;
7
7
  var _fflate = require("fflate");
8
8
  var _nodeBuffer = require("node:buffer");
9
9
  var _nodeZlib = _interopRequireDefault(require("node:zlib"));
10
+ var _UnzipError = _interopRequireWildcard(require("./UnzipError.js"));
11
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
12
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
10
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11
14
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
12
15
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -94,45 +97,29 @@ var USE_ZLIB_DECOMPRESSOR = true;
94
97
  // * When decompressing a `50 MB` `.xlsx` file, the decompression time is `3600 ms`
95
98
  // when using "sync" decompressor and `3200 ms` when using "async" decompressor.
96
99
  var USE_ASYNC_FFLATE_DECOMPRESSOR = false;
100
+ var PROMISE_RESOLVE_VALUE = undefined;
97
101
 
98
102
  /**
99
103
  * Reads `*.zip` file contents.
100
104
  * @param {Stream} stream
101
- * @return {Promise<Record<string,Buffer>>} Resolves to an object holding `*.zip` file entries. P.S. `Buffer` is a `Uint8Array`.
105
+ * @param {function} onFile
106
+ * @param {function} onFileData
107
+ * @param {function} onFileDataEnd
108
+ * @return {Promise<void>}
102
109
  */
103
- function unzipFromStream(stream) {
104
- var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
105
- filter = _ref.filter;
106
- // The `files` object stores the files and their contents.
107
- var files = {};
108
- var filesChunks = {};
109
- var onFile = function onFile(filePath) {
110
- // See if this file should be ignored.
111
- // If it should, this entry won't be processed, i.e. `Unzip` will not try
112
- // to decompress its data, and will just discard it.
113
- if (filter && !filter({
114
- path: filePath
115
- })) {
116
- return false;
117
- }
118
- filesChunks[filePath] = [];
119
- };
120
- var onFileData = function onFileData(filePath, chunk) {
121
- filesChunks[filePath].push(chunk);
122
- };
123
- var onFileDataEnd = function onFileDataEnd(filePath) {
124
- files[filePath] = _nodeBuffer.Buffer.concat(filesChunks[filePath]);
125
- delete filesChunks[filePath];
126
- };
127
- return unzipFromStream_(stream, onFile, onFileData, onFileDataEnd).then(function () {
128
- return files;
129
- });
130
- }
131
- var PROMISE_RESOLVE_VALUE = undefined;
132
110
  function unzipFromStream_(stream, onFile, onFileData, onFileDataEnd) {
133
111
  return new Promise(function (resolve, reject) {
134
112
  var errored = false;
135
113
  var onError = function onError(error) {
114
+ // If `fflate` throws its specific error then it implies that the `.zip` file is not valid.
115
+ //
116
+ // By default, `fflate` uses it's own pure-js unzipper.
117
+ // It could also be configured to use `node:zlib` native module instead.
118
+ // In that case, it could throw a `code: "Z_DATA_ERROR"` too.
119
+ //
120
+ if (isFlateError(error) || error.code === 'Z_DATA_ERROR') {
121
+ error = (0, _UnzipError.createUnzipError)(error);
122
+ }
136
123
  if (!errored) {
137
124
  errored = true;
138
125
  reject(error);
@@ -153,7 +140,7 @@ function unzipFromStream_(stream, onFile, onFileData, onFileDataEnd) {
153
140
  };
154
141
  var _createZipFileValidat = createZipFileValidator(function (isValid) {
155
142
  if (!isValid) {
156
- onError(new Error('Invalid `.zip` archive'));
143
+ onError(new _UnzipError["default"]('INVALID_ZIP'));
157
144
  }
158
145
  }),
159
146
  validateChunk = _createZipFileValidat.validateChunk;
@@ -172,7 +159,10 @@ function unzipFromStream_(stream, onFile, onFileData, onFileDataEnd) {
172
159
  if (entry.name.endsWith('/')) {
173
160
  return;
174
161
  }
175
- if (onFile(entry.name) === false) {
162
+
163
+ // `entry.originalSize` property will not be present for `.zip` archives
164
+ // that were created in a streaming fashion.
165
+ if (onFile(entry.name, entry.originalSize) === false) {
176
166
  return;
177
167
  }
178
168
  stillDecompressingEntriesCount++;
@@ -183,7 +173,17 @@ function unzipFromStream_(stream, onFile, onFileData, onFileDataEnd) {
183
173
  if (error) {
184
174
  return onError(error);
185
175
  }
186
- onFileData(entry.name, chunk);
176
+ // Sometimes, `chunk` is a `Buffer`. Other times, it's a `Uint8Array`.
177
+ // It's not really clear in which exact circumstances it's one or the other.
178
+ if (chunk instanceof _nodeBuffer.Buffer) {
179
+ onFileData(entry.name, chunk);
180
+ } else if (chunk instanceof Uint8Array) {
181
+ onFileData(entry.name, _nodeBuffer.Buffer.from(chunk));
182
+ } else {
183
+ // This error is not technically possible.
184
+ // In case it is thrown, it means that there's a bug in the code.
185
+ throw new Error('Unsupported type of chunk', chunk);
186
+ }
187
187
  if (isLast) {
188
188
  stillDecompressingEntriesCount--;
189
189
  onFileDataEnd(entry.name);
@@ -333,6 +333,14 @@ var NativeZlibInflate = /*#__PURE__*/function () {
333
333
  }
334
334
  }]);
335
335
  return NativeZlibInflate;
336
- }();
336
+ }(); // This function attempts to guess if a given `error` was thrown by `fflate`.
337
337
  _defineProperty(NativeZlibInflate, "compression", 8);
338
+ function isFlateError(error) {
339
+ // `fflate` doesn't export a `FlateError` class.
340
+ // https://github.com/101arrowz/fflate/issues/290
341
+ // return error instanceof FlateError
342
+
343
+ // Here, it attempts to guess if an `error` is a `FlateError` by checking if `error.code` is a `number`.
344
+ return typeof error.code === 'number';
345
+ }
338
346
  //# sourceMappingURL=unzipFromStream.fflate.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"unzipFromStream.fflate.js","names":["_fflate","require","_nodeBuffer","_nodeZlib","_interopRequireDefault","obj","__esModule","_typeof","o","Symbol","iterator","constructor","prototype","_classCallCheck","instance","Constructor","TypeError","_defineProperties","target","props","i","length","descriptor","enumerable","configurable","writable","Object","defineProperty","_toPropertyKey","key","_createClass","protoProps","staticProps","_defineProperty","value","arg","_toPrimitive","String","input","hint","prim","toPrimitive","undefined","res","call","Number","USE_ZLIB_DECOMPRESSOR","USE_ASYNC_FFLATE_DECOMPRESSOR","unzipFromStream","stream","_ref","arguments","filter","files","filesChunks","onFile","filePath","path","onFileData","chunk","push","onFileDataEnd","Buffer","concat","unzipFromStream_","then","PROMISE_RESOLVE_VALUE","Promise","resolve","reject","errored","onError","error","stillDecompressingEntriesCount","noMoreEntries","resolveIfDone","_createZipFileValidat","createZipFileValidator","isValid","Error","validateChunk","unzip","Unzip","entry","name","endsWith","ondata","isLast","start","register","NativeZlibInflate","AsyncUnzipInflate","UnzipInflate","on","Uint8Array","onValidationResult","firstBytesCount","firstBytes","firstBytesCheckResult","_this","inflate","zlib","createInflateRaw","write","from","end","terminate","destroy"],"sources":["../../source/zip/unzipFromStream.fflate.js"],"sourcesContent":["// Considerations:\r\n//\r\n// * `fflate` uses a pure-javascript implementation of `.zip` compression/decompression by default.\r\n// This pure-javascript implementation is about 2x slower than Node.js's \"native\" `zlib` module.\r\n// This issue is worked around by \"marrying\" `fflate` with Node.js's `zlib` \"native\" module through some tinkering.\r\n// https://github.com/101arrowz/fflate/issues/284\r\n//\r\n// * Even though `fflate` implements a \"streaming\" mode of its own,\r\n// it does not implement Node.js streams \"contract\", i.e. it just unzips the archive\r\n// as fast as it can consume it from the input stream, without throttling the data throughput\r\n// in cases when the input data flows faster than `fflate` can process it. This means that\r\n// in the \"worst case\" scenario when `fflate`'s decompressor is unable to keep up with the\r\n// data influx, it would \"buffer\" the entire `.zip` archive in RAM until it's processed.\r\n// And while this is no big deal by any means, it's still not as elegant as adhering to\r\n// Node.js streaming protocol.\r\n\r\n// This code was originally submitted by Stian Jensen.\r\n// https://github.com/catamphetamine/read-excel-file/pull/122\r\n// https://github.com/catamphetamine/read-excel-file/pull/123\r\n\r\n// A `*.zip` file consists of individual file entries with the \"total\" summary section\r\n// placed at the end of the file rather than at the start of it, which was originally done\r\n// to allow for easy append of data to a given `.zip` file.\r\n// https://en.wikipedia.org/wiki/ZIP_(file_format)\r\n//\r\n// But this also means that reading a `*.zip` file from a stream can't really be done\r\n// using the \"officially recommended\" way of first reading the \"total\" summary section\r\n// and only then reading the individual file entries specified in that summary section.\r\n//\r\n// So in order to be able to read a `*.zip` file from a stream, some corners have to be cut.\r\n// For example, the \"total\" summary section is completely ignored and instead the reader\r\n// should adopt \"data recovery\" software approach — it should proactively \"scan\" the input stream\r\n// for individual file entries and handle them one-by-one as they come.\r\n//\r\n// Such approach doesn't seem to contradict with the XLSX specification\r\n// because an `*.xlsx` files is supposed to be a normal `.zip` archive\r\n// without any \"trickery\" such as \"deleted\" files or \"garbage\" data\r\n// hiding under the hood.\r\n//\r\n// So when handling `*.xlsx` file, we assume that each such file must start\r\n// with an individual file entry followed by another individual file entry, etc.\r\n//\r\n// When the \"summary\" section is reached, we assume that the archive has ended.\r\n//\r\n// To read a `.zip` archive, the code uses `fflate`'s `Unzip` class.\r\n// The actual decompression could be performed either by using\r\n// `fflate`'s pure-javascript `UnzipInflate` implementation, which is\r\n// about 2x slower than Node.js's \"native\" module `zlib`,\r\n// or it could use the aforementioned `zlib` module as a drop-in replacement\r\n// (with some tinkering).\r\n//\r\n// The `Unzip` class doesn't speak the Node.js stream interface, and `fflate`'s readme\r\n// doesn't include a clear \"reading a `.zip` file from a Node.js stream\" section.\r\n// https://github.com/101arrowz/fflate/issues/251\r\n// Instead, the `Unzip` class has its own `push(chunk)` / `onfile` / `entry.ondata` protocol.\r\n// This code reads the binary input stream and forwards each chunk of it to `unzip.push()`,\r\n// and then collects the decompressed file entries.\r\n//\r\n// P.S. In the comments to `UnzipInflate` in `fflate` package, it says:\r\n// \"Streaming DEFLATE decompression for ZIP archives. Prefer AsyncZipInflate for better performance.\"\r\n// But there seems to be no `AsyncZipInflate` class in the `fflate` package.\r\n// https://github.com/101arrowz/fflate/issues/277\r\n// So just the regular `UnzipInflate` is used here.\r\n//\r\nimport { Unzip } from 'fflate'\r\n// import { AsyncUnzipInflate, UnzipInflate } from 'fflate'\r\n\r\nimport { Buffer } from 'node:buffer'\r\nimport zlib from 'node:zlib'\r\n\r\n// Native `zlib` is faster than `UnzipInflate`.\r\n// * When decompressing a `1 MB` `.xlsx` file, the decompression time is `100 ms`\r\n// when using `zlib` decompressor and `150 ms` when using `fflate` \"sync\" decompressor.\r\n// * When decompressing a `10 MB` `.xlsx` file, the decompression time is `500 ms`\r\n// when using `zlib` decompressor and `650 ms` when using `fflate` \"sync\" decompressor.\r\n// * When decompressing a `50 MB` `.xlsx` file, the decompression time is `2800 ms`\r\n// when using `zlib` decompressor and `3600 ms` when using `fflate` \"sync\" decompressor.\r\nconst USE_ZLIB_DECOMPRESSOR = true\r\n\r\n// `AsyncZipInflate` is faster than `UnzipInflate` for `.xlsx` files that're larger\r\n// than a few megabytes.\r\n// * When decompressing a `1 MB` `.xlsx` file, the decompression time is `150 ms`\r\n// when using \"sync\" decompressor and `170 ms` when using \"async\" decompressor.\r\n// * When decompressing a `10 MB` `.xlsx` file, the decompression time is about the same.\r\n// * When decompressing a `50 MB` `.xlsx` file, the decompression time is `3600 ms`\r\n// when using \"sync\" decompressor and `3200 ms` when using \"async\" decompressor.\r\nconst USE_ASYNC_FFLATE_DECOMPRESSOR = false\r\n\r\n/**\r\n * Reads `*.zip` file contents.\r\n * @param {Stream} stream\r\n * @return {Promise<Record<string,Buffer>>} Resolves to an object holding `*.zip` file entries. P.S. `Buffer` is a `Uint8Array`.\r\n */\r\nexport default function unzipFromStream(stream, { filter } = {}) {\r\n\t// The `files` object stores the files and their contents.\r\n\tconst files = {}\r\n\tconst filesChunks = {}\r\n\r\n\tconst onFile = (filePath) => {\r\n\t\t// See if this file should be ignored.\r\n\t\t// If it should, this entry won't be processed, i.e. `Unzip` will not try\r\n\t\t// to decompress its data, and will just discard it.\r\n\t\tif (filter && !filter({ path: filePath })) {\r\n\t\t\treturn false\r\n\t\t}\r\n\t\tfilesChunks[filePath] = []\r\n\t}\r\n\r\n\tconst onFileData = (filePath, chunk) => {\r\n\t\tfilesChunks[filePath].push(chunk)\r\n\t}\r\n\r\n\tconst onFileDataEnd = (filePath) => {\r\n\t\tfiles[filePath] = Buffer.concat(filesChunks[filePath])\r\n\t\tdelete filesChunks[filePath]\r\n\t}\r\n\r\n\treturn unzipFromStream_(stream, onFile, onFileData, onFileDataEnd).then(() => {\r\n\t\treturn files\r\n\t})\r\n}\r\n\r\nconst PROMISE_RESOLVE_VALUE = undefined\r\n\r\nfunction unzipFromStream_(stream, onFile, onFileData, onFileDataEnd) {\r\n\treturn new Promise((resolve, reject) => {\r\n\t\tlet errored = false\r\n\r\n\t\tconst onError = (error) => {\r\n\t\t\tif (!errored) {\r\n\t\t\t\terrored = true\r\n\t\t\t\treject(error)\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// The native `zlib` decoder finishes inflating an entry asynchronously, so\r\n\t\t// the archive's `end` event can fire while entries are still decompressing.\r\n\t\t// It counts \"decompression still in-progress\" entries the decompression for which\r\n\t\t// has started but not yet finished, and the main promise only resolves once\r\n\t\t// the input stream has ended *and* every entry is done decompressing.\r\n\t\tlet stillDecompressingEntriesCount = 0\r\n\t\tlet noMoreEntries = false\r\n\t\tconst resolveIfDone = () => {\r\n\t\t\tif (!errored && noMoreEntries && stillDecompressingEntriesCount === 0) {\r\n\t\t\t\tresolve(PROMISE_RESOLVE_VALUE)\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst { validateChunk } = createZipFileValidator((isValid) => {\r\n\t\t\tif (!isValid) {\r\n\t\t\t\tonError(new Error('Invalid `.zip` archive'))\r\n\t\t\t}\r\n\t\t})\r\n\r\n\t\t// `Unzip` discovers each individual file entry in the input data stream\r\n\t\t// and then calls the callback function for each such entry.\r\n\t\tconst unzip = new Unzip((entry) => {\r\n\t\t\t// If there already was an error while reading this `.zip` file,\r\n\t\t\t// ignore any follow-up entries.\r\n\t\t\tif (errored) {\r\n\t\t\t\treturn\r\n\t\t\t}\r\n\r\n\t\t\t// Skip directory entries (their names end with a slash).\r\n\t\t\t// Only files are of any interest.\r\n\t\t\tif (entry.name.endsWith('/')) {\r\n\t\t\t\treturn\r\n\t\t\t}\r\n\r\n\t\t\tif (onFile(entry.name) === false) {\r\n\t\t\t\treturn\r\n\t\t\t}\r\n\r\n\t\t\tstillDecompressingEntriesCount++\r\n\r\n\t\t\t// `entry.ondata` is called with each decompressed chunk of the entry,\r\n\t\t\t// and then a final time with `isLast === true` once the entry is complete.\r\n\t\t\tentry.ondata = (error, chunk, isLast) => {\r\n\t\t\t\tif (error) {\r\n\t\t\t\t\treturn onError(error)\r\n\t\t\t\t}\r\n\t\t\t\tonFileData(entry.name, chunk)\r\n\t\t\t\tif (isLast) {\r\n\t\t\t\t\tstillDecompressingEntriesCount--\r\n\t\t\t\t\tonFileDataEnd(entry.name)\r\n\t\t\t\t\tresolveIfDone()\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\t// Start decompressing this entry.\r\n\t\t\tentry.start()\r\n\t\t})\r\n\r\n\t\t// Register the decompressor for the data that was compressed using\r\n\t\t// `DEFLATE` compression algorithm (compression method `8`),\r\n\t\t// which is what `.xlsx` files use.\r\n\t\tunzip.register(USE_ZLIB_DECOMPRESSOR ? NativeZlibInflate : (USE_ASYNC_FFLATE_DECOMPRESSOR ? AsyncUnzipInflate : UnzipInflate))\r\n\r\n\t\tstream\r\n\t\t\t// Catch errors emitted from the input stream (for example, a file read error).\r\n\t\t\t.on('error', onError)\r\n\t\t\t// When another chunk of data is read from the input stream.\r\n\t\t\t.on('data', (chunk) => {\r\n\t\t\t\t// If there already was an error while reading this `.zip` file,\r\n\t\t\t\t// ignore any follow-up data chunks.\r\n\t\t\t\tif (errored) {\r\n\t\t\t\t\treturn\r\n\t\t\t\t}\r\n\t\t\t\t// Validate the `.zip` archive as its data comes through.\r\n\t\t\t\tvalidateChunk(chunk)\r\n\t\t\t\t// If the `.zip` archive is found to be invalid, stop any further\r\n\t\t\t\t// processing of it.\r\n\t\t\t\tif (errored) {\r\n\t\t\t\t\treturn\r\n\t\t\t\t}\r\n\t\t\t\t// Push the next data chunk to `fflate`'s `Unzip` class instance.\r\n\t\t\t\t//\r\n\t\t\t\t// The `.push()` function of `fflate`'s own `ZipInflate` decompressor is synchronous,\r\n\t\t\t\t// meaning that by the time it returns, any complete files entries encountered so far\r\n\t\t\t\t// have already been decompressed and populated in the `files` object.\r\n\t\t\t\t//\r\n\t\t\t\t// The `.push()` function of `NativeZlibInflate` decompressor is asynchronous,\r\n\t\t\t\t// so it requires hacking around with the counter of \"still being decompressed\" entries\r\n\t\t\t\t// in order to detect the actual finish of the archive's decompression process.\r\n\t\t\t\t//\r\n\t\t\t\ttry {\r\n\t\t\t\t\tunzip.push(chunk, false)\r\n\t\t\t\t} catch (error) {\r\n\t\t\t\t\tonError(error)\r\n\t\t\t\t}\r\n\t\t\t})\r\n\t\t\t// When there's no more data in the input stream to consume,\r\n\t\t\t// finish reading the `.zip` archive.\r\n\t\t\t.on('end', () => {\r\n\t\t\t\t// If there were any errors when reading the `.zip` archive,\r\n\t\t\t\t// don't `resolve()` with anything.\r\n\t\t\t\tif (errored) {\r\n\t\t\t\t\treturn\r\n\t\t\t\t}\r\n\t\t\t\ttry {\r\n\t\t\t\t\t// Signal the end of the archive to `fflate`'s `Unzip` class instance.\r\n\t\t\t\t\t// It will flush any remaining state in it.\r\n\t\t\t\t\tunzip.push(new Uint8Array(0), true)\r\n\t\t\t\t\t// The input stream has ended.\r\n\t\t\t\t\tnoMoreEntries = true\r\n\t\t\t\t\t// The entries may still be decompressing asynchronously.\r\n\t\t\t\t\t// In that case, resolve once they all finish decompresssing.\r\n\t\t\t\t\t// Or, resolve if all entries have already finished decompressing by now.\r\n\t\t\t\t\tresolveIfDone()\r\n\t\t\t\t} catch (error) {\r\n\t\t\t\t\tonError(error)\r\n\t\t\t\t}\r\n\t\t\t})\r\n\t})\r\n}\r\n\r\n// Every section in a `.zip` archive is marked with 4 bytes, the first two of which\r\n// are `0x50` and `0x4B`, which reads \"PK\", referencing the initials of the inventor Phil Katz.\r\n//\r\n// It looks like `fflate`'s `Unzip` doesn't ever complain about whatever data is thrown at it.\r\n// Due to how `.zip` file format is defined, \"garbage\" data could be placed at various\r\n// places in it and it'd still be a valid `.zip` archive. It's likely that for this reason\r\n// `fflate` doesn't ever complain and simply emits no entries when fed any kind of invalid data.\r\n//\r\n// In order to introduce some basic validation, here we specifically demand\r\n// that a `.zip` archive must at least start with an individual file entry\r\n// because an `.xlsx` file creator softwared really shouldn't attempt doing\r\n// anything \"funny\" when writing a file, hence this adherence requirement.\r\n//\r\nfunction createZipFileValidator(onValidationResult) {\r\n\tconst firstBytesCount = 2\r\n\tconst firstBytes = []\r\n\tlet firstBytesCheckResult\r\n\treturn {\r\n\t\tvalidateChunk(chunk) {\r\n\t\t\tif (firstBytes.length < 2) {\r\n\t\t\t\tlet i = 0\r\n\t\t\t\twhile (i < chunk.length && i < firstBytesCount) {\r\n\t\t\t\t\tfirstBytes.push(chunk[i])\r\n\t\t\t\t\ti++\r\n\t\t\t\t}\r\n\t\t\t\tif (firstBytes.length === 2) {\r\n\t\t\t\t\tconst isValid = firstBytes[0] === 0x50 && firstBytes[1] === 0x4B\r\n\t\t\t\t\tonValidationResult(isValid)\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n\r\n// An implemenation of a `DEFLATE` decompressor for `fflate`'s `Unzip` class\r\n// that uses Node.js's \"native\" module `zlib`.\r\n//\r\n// It implements `fflate`'s decoder interface: `Unzip` constructs one decoder\r\n// per each entry, sets `ondata(error, chunk, isLast)` callback on it, and feeds it\r\n// the entry's compressed bytes by calling `push(chunk, isLast)` method.\r\n//\r\n// Unlike `fflate`'s synchronous `UnzipInflate` decoder, `zlib` decompresses asynchronously,\r\n// so an entry only finishes some \"ticks\" after its last chunk of its data is `push()`ed\r\n// by `fflate`'s `Unzip` class. To work around this issue, pending entries counter is used\r\n// to track when the archive really finishes unpacking.\r\n//\r\nclass NativeZlibInflate {\r\n\tstatic compression = 8\r\n\r\n\tconstructor() {\r\n\t\tthis.inflate = zlib.createInflateRaw()\r\n\t\tthis.inflate.on('data', (chunk) => this.ondata(null, chunk, false))\r\n\t\tthis.inflate.on('end', () => this.ondata(null, new Uint8Array(0), true))\r\n\t\tthis.inflate.on('error', (error) => this.ondata(error, null, false))\r\n\t}\r\n\r\n\tpush(chunk, isLast) {\r\n\t\tthis.inflate.write(Buffer.from(chunk))\r\n\t\tif (isLast) {\r\n\t\t\tthis.inflate.end()\r\n\t\t}\r\n\t}\r\n\r\n\tterminate() {\r\n\t\tthis.inflate.destroy()\r\n\t}\r\n}\r\n"],"mappings":";;;;;;AAgEA,IAAAA,OAAA,GAAAC,OAAA;AAGA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAC,sBAAA,CAAAH,OAAA;AAA4B,SAAAG,uBAAAC,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,gBAAAA,GAAA;AAAA,SAAAE,QAAAC,CAAA,sCAAAD,OAAA,wBAAAE,MAAA,uBAAAA,MAAA,CAAAC,QAAA,aAAAF,CAAA,kBAAAA,CAAA,gBAAAA,CAAA,WAAAA,CAAA,yBAAAC,MAAA,IAAAD,CAAA,CAAAG,WAAA,KAAAF,MAAA,IAAAD,CAAA,KAAAC,MAAA,CAAAG,SAAA,qBAAAJ,CAAA,KAAAD,O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AzD,eAAA,CAnBIyD,iBAAiB,iBACD,CAAC"}
1
+ {"version":3,"file":"unzipFromStream.fflate.js","names":["_fflate","require","_nodeBuffer","_nodeZlib","_interopRequireDefault","_UnzipError","_interopRequireWildcard","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","_typeof","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","o","Symbol","iterator","constructor","_classCallCheck","instance","Constructor","TypeError","_defineProperties","target","props","i","length","descriptor","enumerable","configurable","writable","_toPropertyKey","_createClass","protoProps","staticProps","_defineProperty","value","arg","_toPrimitive","String","input","hint","prim","toPrimitive","undefined","res","Number","USE_ZLIB_DECOMPRESSOR","USE_ASYNC_FFLATE_DECOMPRESSOR","PROMISE_RESOLVE_VALUE","unzipFromStream_","stream","onFile","onFileData","onFileDataEnd","Promise","resolve","reject","errored","onError","error","isFlateError","code","createUnzipError","stillDecompressingEntriesCount","noMoreEntries","resolveIfDone","_createZipFileValidat","createZipFileValidator","isValid","UnzipError","validateChunk","unzip","Unzip","entry","name","endsWith","originalSize","ondata","chunk","isLast","Buffer","Uint8Array","from","Error","start","register","NativeZlibInflate","AsyncUnzipInflate","UnzipInflate","on","push","onValidationResult","firstBytesCount","firstBytes","firstBytesCheckResult","_this","inflate","zlib","createInflateRaw","write","end","terminate","destroy"],"sources":["../../source/zip/unzipFromStream.fflate.js"],"sourcesContent":["// Considerations:\r\n//\r\n// * `fflate` uses a pure-javascript implementation of `.zip` compression/decompression by default.\r\n// This pure-javascript implementation is about 2x slower than Node.js's \"native\" `zlib` module.\r\n// This issue is worked around by \"marrying\" `fflate` with Node.js's `zlib` \"native\" module through some tinkering.\r\n// https://github.com/101arrowz/fflate/issues/284\r\n//\r\n// * Even though `fflate` implements a \"streaming\" mode of its own,\r\n// it does not implement Node.js streams \"contract\", i.e. it just unzips the archive\r\n// as fast as it can consume it from the input stream, without throttling the data throughput\r\n// in cases when the input data flows faster than `fflate` can process it. This means that\r\n// in the \"worst case\" scenario when `fflate`'s decompressor is unable to keep up with the\r\n// data influx, it would \"buffer\" the entire `.zip` archive in RAM until it's processed.\r\n// And while this is no big deal by any means, it's still not as elegant as adhering to\r\n// Node.js streaming protocol.\r\n\r\n// This code was originally submitted by Stian Jensen.\r\n// https://github.com/catamphetamine/read-excel-file/pull/122\r\n// https://github.com/catamphetamine/read-excel-file/pull/123\r\n\r\n// A `*.zip` file consists of individual file entries with the \"total\" summary section\r\n// placed at the end of the file rather than at the start of it, which was originally done\r\n// to allow for easy append of data to a given `.zip` file.\r\n// https://en.wikipedia.org/wiki/ZIP_(file_format)\r\n//\r\n// But this also means that reading a `*.zip` file from a stream can't really be done\r\n// using the \"officially recommended\" way of first reading the \"total\" summary section\r\n// and only then reading the individual file entries specified in that summary section.\r\n//\r\n// So in order to be able to read a `*.zip` file from a stream, some corners have to be cut.\r\n// For example, the \"total\" summary section is completely ignored and instead the reader\r\n// should adopt \"data recovery\" software approach — it should proactively \"scan\" the input stream\r\n// for individual file entries and handle them one-by-one as they come.\r\n//\r\n// Such approach doesn't seem to contradict with the XLSX specification\r\n// because an `*.xlsx` files is supposed to be a normal `.zip` archive\r\n// without any \"trickery\" such as \"deleted\" files or \"garbage\" data\r\n// hiding under the hood.\r\n//\r\n// So when handling `*.xlsx` file, we assume that each such file must start\r\n// with an individual file entry followed by another individual file entry, etc.\r\n//\r\n// When the \"summary\" section is reached, we assume that the archive has ended.\r\n//\r\n// To read a `.zip` archive, the code uses `fflate`'s `Unzip` class.\r\n// The actual decompression could be performed either by using\r\n// `fflate`'s pure-javascript `UnzipInflate` implementation, which is\r\n// about 2x slower than Node.js's \"native\" module `zlib`,\r\n// or it could use the aforementioned `zlib` module as a drop-in replacement\r\n// (with some tinkering).\r\n//\r\n// The `Unzip` class doesn't speak the Node.js stream interface, and `fflate`'s readme\r\n// doesn't include a clear \"reading a `.zip` file from a Node.js stream\" section.\r\n// https://github.com/101arrowz/fflate/issues/251\r\n// Instead, the `Unzip` class has its own `push(chunk)` / `onfile` / `entry.ondata` protocol.\r\n// This code reads the binary input stream and forwards each chunk of it to `unzip.push()`,\r\n// and then collects the decompressed file entries.\r\n//\r\n// P.S. In the comments to `UnzipInflate` in `fflate` package, it says:\r\n// \"Streaming DEFLATE decompression for ZIP archives. Prefer AsyncZipInflate for better performance.\"\r\n// But there seems to be no `AsyncZipInflate` class in the `fflate` package.\r\n// https://github.com/101arrowz/fflate/issues/277\r\n// So just the regular `UnzipInflate` is used here.\r\n//\r\nimport { Unzip } from 'fflate'\r\n// import { AsyncUnzipInflate, UnzipInflate } from 'fflate'\r\n\r\nimport { Buffer } from 'node:buffer'\r\nimport zlib from 'node:zlib'\r\n\r\nimport UnzipError, { createUnzipError } from './UnzipError.js'\r\n\r\n// Native `zlib` is faster than `UnzipInflate`.\r\n// * When decompressing a `1 MB` `.xlsx` file, the decompression time is `100 ms`\r\n// when using `zlib` decompressor and `150 ms` when using `fflate` \"sync\" decompressor.\r\n// * When decompressing a `10 MB` `.xlsx` file, the decompression time is `500 ms`\r\n// when using `zlib` decompressor and `650 ms` when using `fflate` \"sync\" decompressor.\r\n// * When decompressing a `50 MB` `.xlsx` file, the decompression time is `2800 ms`\r\n// when using `zlib` decompressor and `3600 ms` when using `fflate` \"sync\" decompressor.\r\nconst USE_ZLIB_DECOMPRESSOR = true\r\n\r\n// `AsyncZipInflate` is faster than `UnzipInflate` for `.xlsx` files that're larger\r\n// than a few megabytes.\r\n// * When decompressing a `1 MB` `.xlsx` file, the decompression time is `150 ms`\r\n// when using \"sync\" decompressor and `170 ms` when using \"async\" decompressor.\r\n// * When decompressing a `10 MB` `.xlsx` file, the decompression time is about the same.\r\n// * When decompressing a `50 MB` `.xlsx` file, the decompression time is `3600 ms`\r\n// when using \"sync\" decompressor and `3200 ms` when using \"async\" decompressor.\r\nconst USE_ASYNC_FFLATE_DECOMPRESSOR = false\r\n\r\nconst PROMISE_RESOLVE_VALUE = undefined\r\n\r\n/**\r\n * Reads `*.zip` file contents.\r\n * @param {Stream} stream\r\n * @param {function} onFile\r\n * @param {function} onFileData\r\n * @param {function} onFileDataEnd\r\n * @return {Promise<void>}\r\n */\r\nexport default function unzipFromStream_(stream, onFile, onFileData, onFileDataEnd) {\r\n\treturn new Promise((resolve, reject) => {\r\n\t\tlet errored = false\r\n\r\n\t\tconst onError = (error) => {\r\n\t\t\t// If `fflate` throws its specific error then it implies that the `.zip` file is not valid.\r\n\t\t\t//\r\n\t\t\t// By default, `fflate` uses it's own pure-js unzipper.\r\n\t\t\t// It could also be configured to use `node:zlib` native module instead.\r\n\t\t\t// In that case, it could throw a `code: \"Z_DATA_ERROR\"` too.\r\n\t\t\t//\r\n\t\t\tif (isFlateError(error) || error.code === 'Z_DATA_ERROR') {\r\n\t\t\t\terror = createUnzipError(error)\r\n\t\t\t}\r\n\t\t\tif (!errored) {\r\n\t\t\t\terrored = true\r\n\t\t\t\treject(error)\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// The native `zlib` decoder finishes inflating an entry asynchronously, so\r\n\t\t// the archive's `end` event can fire while entries are still decompressing.\r\n\t\t// It counts \"decompression still in-progress\" entries the decompression for which\r\n\t\t// has started but not yet finished, and the main promise only resolves once\r\n\t\t// the input stream has ended *and* every entry is done decompressing.\r\n\t\tlet stillDecompressingEntriesCount = 0\r\n\t\tlet noMoreEntries = false\r\n\t\tconst resolveIfDone = () => {\r\n\t\t\tif (!errored && noMoreEntries && stillDecompressingEntriesCount === 0) {\r\n\t\t\t\tresolve(PROMISE_RESOLVE_VALUE)\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst { validateChunk } = createZipFileValidator((isValid) => {\r\n\t\t\tif (!isValid) {\r\n\t\t\t\tonError(new UnzipError('INVALID_ZIP'))\r\n\t\t\t}\r\n\t\t})\r\n\r\n\t\t// `Unzip` discovers each individual file entry in the input data stream\r\n\t\t// and then calls the callback function for each such entry.\r\n\t\tconst unzip = new Unzip((entry) => {\r\n\t\t\t// If there already was an error while reading this `.zip` file,\r\n\t\t\t// ignore any follow-up entries.\r\n\t\t\tif (errored) {\r\n\t\t\t\treturn\r\n\t\t\t}\r\n\r\n\t\t\t// Skip directory entries (their names end with a slash).\r\n\t\t\t// Only files are of any interest.\r\n\t\t\tif (entry.name.endsWith('/')) {\r\n\t\t\t\treturn\r\n\t\t\t}\r\n\r\n\t\t\t// `entry.originalSize` property will not be present for `.zip` archives\r\n\t\t\t// that were created in a streaming fashion.\r\n\t\t\tif (onFile(entry.name, entry.originalSize) === false) {\r\n\t\t\t\treturn\r\n\t\t\t}\r\n\r\n\t\t\tstillDecompressingEntriesCount++\r\n\r\n\t\t\t// `entry.ondata` is called with each decompressed chunk of the entry,\r\n\t\t\t// and then a final time with `isLast === true` once the entry is complete.\r\n\t\t\tentry.ondata = (error, chunk, isLast) => {\r\n\t\t\t\tif (error) {\r\n\t\t\t\t\treturn onError(error)\r\n\t\t\t\t}\r\n\t\t\t\t// Sometimes, `chunk` is a `Buffer`. Other times, it's a `Uint8Array`.\r\n\t\t\t\t// It's not really clear in which exact circumstances it's one or the other.\r\n\t\t\t\tif (chunk instanceof Buffer) {\r\n\t\t\t\t\tonFileData(entry.name, chunk)\r\n\t\t\t\t} else if (chunk instanceof Uint8Array) {\r\n\t\t\t\t\tonFileData(entry.name, Buffer.from(chunk))\r\n\t\t\t\t} else {\r\n\t\t\t\t\t// This error is not technically possible.\r\n\t\t\t\t\t// In case it is thrown, it means that there's a bug in the code.\r\n\t\t\t\t\tthrow new Error('Unsupported type of chunk', chunk)\r\n\t\t\t\t}\r\n\t\t\t\tif (isLast) {\r\n\t\t\t\t\tstillDecompressingEntriesCount--\r\n\t\t\t\t\tonFileDataEnd(entry.name)\r\n\t\t\t\t\tresolveIfDone()\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\t// Start decompressing this entry.\r\n\t\t\tentry.start()\r\n\t\t})\r\n\r\n\t\t// Register the decompressor for the data that was compressed using\r\n\t\t// `DEFLATE` compression algorithm (compression method `8`),\r\n\t\t// which is what `.xlsx` files use.\r\n\t\tunzip.register(USE_ZLIB_DECOMPRESSOR ? NativeZlibInflate : (USE_ASYNC_FFLATE_DECOMPRESSOR ? AsyncUnzipInflate : UnzipInflate))\r\n\r\n\t\tstream\r\n\t\t\t// Catch errors emitted from the input stream (for example, a file read error).\r\n\t\t\t.on('error', onError)\r\n\t\t\t// When another chunk of data is read from the input stream.\r\n\t\t\t.on('data', (chunk) => {\r\n\t\t\t\t// If there already was an error while reading this `.zip` file,\r\n\t\t\t\t// ignore any follow-up data chunks.\r\n\t\t\t\tif (errored) {\r\n\t\t\t\t\treturn\r\n\t\t\t\t}\r\n\t\t\t\t// Validate the `.zip` archive as its data comes through.\r\n\t\t\t\tvalidateChunk(chunk)\r\n\t\t\t\t// If the `.zip` archive is found to be invalid, stop any further\r\n\t\t\t\t// processing of it.\r\n\t\t\t\tif (errored) {\r\n\t\t\t\t\treturn\r\n\t\t\t\t}\r\n\t\t\t\t// Push the next data chunk to `fflate`'s `Unzip` class instance.\r\n\t\t\t\t//\r\n\t\t\t\t// The `.push()` function of `fflate`'s own `ZipInflate` decompressor is synchronous,\r\n\t\t\t\t// meaning that by the time it returns, any complete files entries encountered so far\r\n\t\t\t\t// have already been decompressed and populated in the `files` object.\r\n\t\t\t\t//\r\n\t\t\t\t// The `.push()` function of `NativeZlibInflate` decompressor is asynchronous,\r\n\t\t\t\t// so it requires hacking around with the counter of \"still being decompressed\" entries\r\n\t\t\t\t// in order to detect the actual finish of the archive's decompression process.\r\n\t\t\t\t//\r\n\t\t\t\ttry {\r\n\t\t\t\t\tunzip.push(chunk, false)\r\n\t\t\t\t} catch (error) {\r\n\t\t\t\t\tonError(error)\r\n\t\t\t\t}\r\n\t\t\t})\r\n\t\t\t// When there's no more data in the input stream to consume,\r\n\t\t\t// finish reading the `.zip` archive.\r\n\t\t\t.on('end', () => {\r\n\t\t\t\t// If there were any errors when reading the `.zip` archive,\r\n\t\t\t\t// don't `resolve()` with anything.\r\n\t\t\t\tif (errored) {\r\n\t\t\t\t\treturn\r\n\t\t\t\t}\r\n\t\t\t\ttry {\r\n\t\t\t\t\t// Signal the end of the archive to `fflate`'s `Unzip` class instance.\r\n\t\t\t\t\t// It will flush any remaining state in it.\r\n\t\t\t\t\tunzip.push(new Uint8Array(0), true)\r\n\t\t\t\t\t// The input stream has ended.\r\n\t\t\t\t\tnoMoreEntries = true\r\n\t\t\t\t\t// The entries may still be decompressing asynchronously.\r\n\t\t\t\t\t// In that case, resolve once they all finish decompresssing.\r\n\t\t\t\t\t// Or, resolve if all entries have already finished decompressing by now.\r\n\t\t\t\t\tresolveIfDone()\r\n\t\t\t\t} catch (error) {\r\n\t\t\t\t\tonError(error)\r\n\t\t\t\t}\r\n\t\t\t})\r\n\t})\r\n}\r\n\r\n// Every section in a `.zip` archive is marked with 4 bytes, the first two of which\r\n// are `0x50` and `0x4B`, which reads \"PK\", referencing the initials of the inventor Phil Katz.\r\n//\r\n// It looks like `fflate`'s `Unzip` doesn't ever complain about whatever data is thrown at it.\r\n// Due to how `.zip` file format is defined, \"garbage\" data could be placed at various\r\n// places in it and it'd still be a valid `.zip` archive. It's likely that for this reason\r\n// `fflate` doesn't ever complain and simply emits no entries when fed any kind of invalid data.\r\n//\r\n// In order to introduce some basic validation, here we specifically demand\r\n// that a `.zip` archive must at least start with an individual file entry\r\n// because an `.xlsx` file creator softwared really shouldn't attempt doing\r\n// anything \"funny\" when writing a file, hence this adherence requirement.\r\n//\r\nfunction createZipFileValidator(onValidationResult) {\r\n\tconst firstBytesCount = 2\r\n\tconst firstBytes = []\r\n\tlet firstBytesCheckResult\r\n\treturn {\r\n\t\tvalidateChunk(chunk) {\r\n\t\t\tif (firstBytes.length < 2) {\r\n\t\t\t\tlet i = 0\r\n\t\t\t\twhile (i < chunk.length && i < firstBytesCount) {\r\n\t\t\t\t\tfirstBytes.push(chunk[i])\r\n\t\t\t\t\ti++\r\n\t\t\t\t}\r\n\t\t\t\tif (firstBytes.length === 2) {\r\n\t\t\t\t\tconst isValid = firstBytes[0] === 0x50 && firstBytes[1] === 0x4B\r\n\t\t\t\t\tonValidationResult(isValid)\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n\r\n// An implemenation of a `DEFLATE` decompressor for `fflate`'s `Unzip` class\r\n// that uses Node.js's \"native\" module `zlib`.\r\n//\r\n// It implements `fflate`'s decoder interface: `Unzip` constructs one decoder\r\n// per each entry, sets `ondata(error, chunk, isLast)` callback on it, and feeds it\r\n// the entry's compressed bytes by calling `push(chunk, isLast)` method.\r\n//\r\n// Unlike `fflate`'s synchronous `UnzipInflate` decoder, `zlib` decompresses asynchronously,\r\n// so an entry only finishes some \"ticks\" after its last chunk of its data is `push()`ed\r\n// by `fflate`'s `Unzip` class. To work around this issue, pending entries counter is used\r\n// to track when the archive really finishes unpacking.\r\n//\r\nclass NativeZlibInflate {\r\n\tstatic compression = 8\r\n\r\n\tconstructor() {\r\n\t\tthis.inflate = zlib.createInflateRaw()\r\n\t\tthis.inflate.on('data', (chunk) => this.ondata(null, chunk, false))\r\n\t\tthis.inflate.on('end', () => this.ondata(null, new Uint8Array(0), true))\r\n\t\tthis.inflate.on('error', (error) => this.ondata(error, null, false))\r\n\t}\r\n\r\n\tpush(chunk, isLast) {\r\n\t\tthis.inflate.write(Buffer.from(chunk))\r\n\t\tif (isLast) {\r\n\t\t\tthis.inflate.end()\r\n\t\t}\r\n\t}\r\n\r\n\tterminate() {\r\n\t\tthis.inflate.destroy()\r\n\t}\r\n}\r\n\r\n// This function attempts to guess if a given `error` was thrown by `fflate`.\r\nfunction isFlateError(error) {\r\n\t// `fflate` doesn't export a `FlateError` class.\r\n\t// https://github.com/101arrowz/fflate/issues/290\r\n\t// return error instanceof FlateError\r\n\r\n\t// Here, it attempts to guess if an `error` is a `FlateError` by checking if `error.code` is a `number`.\r\n\treturn typeof error.code === 'number'\r\n}\r\n"],"mappings":";;;;;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E,IAAI,KAAK,QAAQ;AACtC"}
@@ -3,12 +3,194 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- Object.defineProperty(exports, "default", {
7
- enumerable: true,
8
- get: function get() {
9
- return _unzipFromStreamUnzipper["default"];
10
- }
11
- });
6
+ exports["default"] = unzipFromStream;
12
7
  var _unzipFromStreamUnzipper = _interopRequireDefault(require("./unzipFromStream.unzipper.js"));
13
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
+ function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
10
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
11
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } // `unzipFromStream` function reads `.zip` archive data from a Node.js stream.
12
+ //
13
+ // Even though it receives a Node.js stream as an input, it doesn't return the results
14
+ // as a Node.js output stream (with `objectMode: true` setting). The reason is that
15
+ // the result of this function is then passed to the XML parser which currently
16
+ // doesn't support consuming a Node.js stream and instead consumes the entire XML document
17
+ // as a single string. This means that implementing streaming output in this function
18
+ // wouldn't result in any performance improvements, so currently it simply returns
19
+ // a "map" of all files in the input `.zip` archive, and that seems to be enough.
20
+ //
21
+ // Currently, there're two decompressor implementations:
22
+ // * `fflate` — a pure-javascript implementation that uses `fflate` package.
23
+ // * `unzipper` — a "native" Node.js module that uses Node's `zlib` which is written in C.
24
+ //
25
+ // The implementations are compared in a benchmark:
26
+ //
27
+ // ```
28
+ // npm run test:benchmark:unzipFromStream
29
+ // ```
30
+ //
31
+ // The benchmark tells that `unzipper` is 2x faster than `fflate` with the default `ZipInflate` decompressor.
32
+ //
33
+ // However, when swapping `fflate`'s default `ZipInflate` decompressor with a custom
34
+ // "native" `zlib` one, `fflate` happens to be about 20% faster than `unzipper`.
35
+ //
36
+ // Still, when measuring the total time of parsing `.xlsx` files,
37
+ // the time difference becomes unmeasurable between `unzipper`
38
+ // and `fflate` with "native" `zlib` decompressor,
39
+ // as could be seen by running `npm run test:benchmark` command
40
+ // where `fflate` is slightly faster than `unzipper`.
41
+ //
42
+ // * When decompressing a `1 MB` `.xlsx` file, the decompression time is `90 ms`
43
+ // when using `fflate` with `zlib` decompressor and `100 ms` when using `unzipper` decompressor.
44
+ // * When decompressing a `10 MB` `.xlsx` file, the decompression time is `530 ms`
45
+ // when using `fflate` with `zlib` decompressor and `550 ms` when using `unzipper` decompressor.
46
+ // * When decompressing a `50 MB` `.xlsx` file, the decompression time is `2800 ms`
47
+ // when using `fflate` with `zlib` decompressor and `3000 ms` when using `unzipper` decompressor.
48
+ //
49
+ // So, at the end of the day, there's no substantial difference between the two
50
+ // when it comes to parsing `.xlsx` files, and one may choose depending on personal preference.
51
+ //
52
+ // And my personal preference leans towards `unzipper` because:
53
+ //
54
+ // * I personally refactored it into `unzipper-esm` in about 5-6 hours.
55
+ // https://github.com/ZJONSSON/node-unzipper/pull/356
56
+ //
57
+ // * It is designed as a Node.js-first module, i.e. it is designed around the concept
58
+ // of Node.js streams "from the ground up". Meanwhile, `fflate` is a "universal" module
59
+ // and it does not implement Node.js streams "contract", i.e. it just unzips the archive
60
+ // as fast as it can consume it from the input stream, without throttling the data throughput
61
+ // in cases when the input data flows faster than `fflate` can process it. This means that
62
+ // in the "worst case" scenario when `fflate`'s decompressor is unable to keep up with the
63
+ // data influx, it would "buffer" the entire `.zip` archive in RAM until it's processed.
64
+ // And while this is no big deal by any means, it's still not as elegant as adhering to
65
+ // Node.js streaming protocol.
66
+ //
67
+ // * `unzipper` uses native `zlib` decompressor which `fflate` doesn't officially include
68
+ // and it had to be hacked into it using a couple of tricks. That's also no big deal,
69
+ // but still a slightly weird experience.
70
+ //
71
+ // * Rumors are circulating that `fflate`'s "streaming" `Zip`/`Unzip` classes have a few
72
+ // implementation issues when compared to non-"streaming" `zipSync`/`unzipSync`/`zip`/`unzip` functions.
73
+ // Some people even suggested in the comments that `Zip`/`Unzip` classes are not really production-ready
74
+ // when compared to `zipSync`/`unzipSync`/`zip`/`unzip` functions.
75
+ // https://github.com/101arrowz/fflate/issues/282
76
+ //
77
+ /**
78
+ * Reads `*.zip` file contents.
79
+ * @param {Stream} stream
80
+ * @return {Promise<Record<string,Buffer>>} Resolves to an object holding `*.zip` file entries. P.S. `Buffer` is a `Uint8Array`.
81
+ */
82
+ function unzipFromStream(stream) {
83
+ var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
84
+ filter = _ref.filter;
85
+ // The `files` object stores the files and their contents.
86
+ var files = {};
87
+ var filesData = {};
88
+
89
+ // `fileSize` is optional and will not be present for `.zip` archives
90
+ // that were created in a streaming fashion.
91
+ var onFile = function onFile(filePath, fileSize) {
92
+ // See if this file should be ignored.
93
+ // If it should, this entry won't be processed, i.e. `Unzip` will not try
94
+ // to decompress its data, and will just discard it.
95
+ if (filter && !filter({
96
+ path: filePath
97
+ })) {
98
+ return false;
99
+ }
100
+ // filesData[filePath] = []
101
+ filesData[filePath] = {
102
+ size: fileSize,
103
+ chunks: [],
104
+ buffer: fileSize === undefined ? undefined : Buffer.alloc(fileSize),
105
+ position: 0
106
+ };
107
+ };
108
+ var onFileData = function onFileData(filePath, chunk) {
109
+ // filesData[filePath].push(chunk)
110
+ if (filesData[filePath].size === undefined) {
111
+ filesData[filePath].chunks.push(chunk);
112
+ } else {
113
+ filesData[filePath].position += chunk.copy(filesData[filePath].buffer, filesData[filePath].position);
114
+ }
115
+ };
116
+ var onFileDataEnd = function onFileDataEnd(filePath) {
117
+ if (filesData[filePath].size === undefined) {
118
+ // // `Buffer.concat()` will produce a pooled buffer if it's <= 4KB.
119
+ // let buffer = Buffer.concat(filesData[filePath].chunks)
120
+ // if (isBufferPooled(buffer)) {
121
+ // // Here it uses `Buffer.allocUnsafeSlow()` instead of the regular `Buffer.alloc()`.
122
+ // // The reason is that `Buffer.allocUnsafeSlow()` doesn't bother resetting the memory
123
+ // // that is being allocated, which is fine because it will be overwritten anyway.
124
+ // // It could also have used `Buffer.allocUnsafe()` if it wasn't returning pooled buffers,
125
+ // // which is what is being avoided here in the first place.
126
+ // const pooledBuffer = buffer
127
+ // buffer = Buffer.allocUnsafeSlow(buffer.byteLength)
128
+ // pooledBuffer.copy(buffer)
129
+ // }
130
+ // files[filePath] = buffer
131
+ files[filePath] = concatChunksToNonPooledBuffer(filesData[filePath].chunks);
132
+ } else {
133
+ files[filePath] = filesData[filePath].buffer;
134
+ }
135
+ delete filesData[filePath];
136
+ };
137
+ return (0, _unzipFromStreamUnzipper["default"])(stream, onFile, onFileData, onFileDataEnd).then(function () {
138
+ return files;
139
+ });
140
+ }
141
+
142
+ // // Node.js allocates small buffers (<= 4KB) in a shared 8KB pool.
143
+ // // This interferes with passing such buffers to another worker thread.
144
+ // // In order for a buffer to be transferrable to another worker thread,
145
+ // // it has to be non-pooled.
146
+ // function isBufferPooled(buffer) {
147
+ // // If it doesn't utilize the full underlying `ArrayBuffer`, it's sliced out of a pool.
148
+ // if (buffer.byteOffset > 0) {
149
+ // return true
150
+ // }
151
+ //
152
+ // // If it starts at `0`, but the underlying allocation is larger than the buffer itself, it's pooled/
153
+ // if (buffer.buffer.byteLength > buffer.byteLength) {
154
+ // return true
155
+ // }
156
+ //
157
+ // return false
158
+ // }
159
+
160
+ // Concatenates chunks into a non-"pooled" buffer.
161
+ //
162
+ // It could've simply used `Buffer.concat(chunks)` to concatenate chunks into a buffer.
163
+ // But, while using `Buffer.concat()` is simple, it results in a Node.js optimization
164
+ // when it uses a "shared" memory region of about `8KB` to co-locate this array buffer
165
+ // with other small array buffers if this array buffer is small too (i.e. <= `4KB`).
166
+ //
167
+ // Such co-location results in the inability to "transfer" this buffer
168
+ // to a worker thread.
169
+ //
170
+ // A workaround is to manually allocate a separate memory region of a certain size.
171
+ // This way, the resulting buffer will be non-"pooled".
172
+ //
173
+ function concatChunksToNonPooledBuffer(chunks) {
174
+ // Calculate the total byte length of all the chunks combined.
175
+ var totalLength = chunks.reduce(function (sum, chunk) {
176
+ return sum + chunk.length;
177
+ }, 0);
178
+
179
+ // Allocate a non-pooled buffer.
180
+ // Here it uses `Buffer.allocUnsafeSlow()` instead of the regular `Buffer.alloc()`.
181
+ // The reason is that `Buffer.allocUnsafeSlow()` doesn't bother resetting the memory
182
+ // that is being allocated, which is fine because it will be overwritten anyway.
183
+ // It could also have used `Buffer.allocUnsafe()` if it wasn't returning pooled buffers,
184
+ // which is what is being avoided here in the first place.
185
+ var buffer = Buffer.allocUnsafeSlow(totalLength);
186
+
187
+ // Manually copy each chunk into the buffer.
188
+ var offset = 0;
189
+ for (var _iterator = _createForOfIteratorHelperLoose(chunks), _step; !(_step = _iterator()).done;) {
190
+ var chunk = _step.value;
191
+ chunk.copy(buffer, offset);
192
+ offset += chunk.length;
193
+ }
194
+ return buffer;
195
+ }
14
196
  //# sourceMappingURL=unzipFromStream.js.map