read-excel-file 9.1.1 → 9.2.0
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.
- package/CHANGELOG.md +9 -0
- package/commonjs/zip/unzipFromStream.fflate.js +209 -0
- package/commonjs/zip/unzipFromStream.fflate.js.map +1 -0
- package/commonjs/zip/unzipFromStream.js +8 -200
- package/commonjs/zip/unzipFromStream.js.map +1 -1
- package/commonjs/zip/unzipFromStream.unzipper.js +127 -0
- package/commonjs/zip/unzipFromStream.unzipper.js.map +1 -0
- package/modules/zip/unzipFromStream.fflate.js +203 -0
- package/modules/zip/unzipFromStream.fflate.js.map +1 -0
- package/modules/zip/unzipFromStream.js +9 -195
- package/modules/zip/unzipFromStream.js.map +1 -1
- package/modules/zip/unzipFromStream.unzipper.js +121 -0
- package/modules/zip/unzipFromStream.unzipper.js.map +1 -0
- package/package.json +10 -28
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
// `fflate` uses a javascript-only implementation of `.zip` compression/decompression.
|
|
2
|
+
// This means that it could likely be less performant than Node.js's "native" `zlib` module`.
|
|
3
|
+
|
|
4
|
+
// This code was originally submitted by Stian Jensen.
|
|
5
|
+
// https://github.com/catamphetamine/read-excel-file/pull/122
|
|
6
|
+
|
|
7
|
+
// A `*.zip` file consists of individual file entries with the "total" summary section
|
|
8
|
+
// placed at the end of the file rather than at the start of it, which was originally done
|
|
9
|
+
// to allow for easy append of data to a given `.zip` file.
|
|
10
|
+
// https://en.wikipedia.org/wiki/ZIP_(file_format)
|
|
11
|
+
//
|
|
12
|
+
// But this also means that reading a `*.zip` file from a stream can't really be done
|
|
13
|
+
// using the "officially recommended" way of first reading the "total" summary section
|
|
14
|
+
// and only then reading the individual file entries specified in that summary section.
|
|
15
|
+
//
|
|
16
|
+
// So in order to be able to read a `*.zip` file from a stream, some corners have to be cut.
|
|
17
|
+
// For example, the "total" summary section is completely ignored and instead the reader
|
|
18
|
+
// should adopt "data recovery" software approach — it should proactively "scan" the input stream
|
|
19
|
+
// for individual file entries and handle them one-by-one as they come.
|
|
20
|
+
//
|
|
21
|
+
// Such approach doesn't seem to contradict with the XLSX specification
|
|
22
|
+
// because an `*.xlsx` files is supposed to be a normal `.zip` archive
|
|
23
|
+
// without any "trickery" such as "deleted" files or "garbage" data
|
|
24
|
+
// hiding under the hood.
|
|
25
|
+
//
|
|
26
|
+
// So when handling `*.xlsx` file, we assume that each such file must start
|
|
27
|
+
// with an individual file entry followed by another individual file entry, etc.
|
|
28
|
+
//
|
|
29
|
+
// When the "summary" section is reached, we assume that the archive has ended.
|
|
30
|
+
//
|
|
31
|
+
// To read a `.zip` archive, the code uses `fflate`'s `Unzip` class
|
|
32
|
+
// with `UnzipInflate` decompression implementation to decompress the data
|
|
33
|
+
// that was previously compressed using `DEFLATE` compressing algorithm,
|
|
34
|
+
// which is what `*.xlsx` files use.
|
|
35
|
+
//
|
|
36
|
+
// The `Unzip` class doesn't speak the Node.js stream interface, and `fflate`'s readme
|
|
37
|
+
// doesn't include a clear "reading a `.zip` file from a Node.js stream" section.
|
|
38
|
+
// https://github.com/101arrowz/fflate/issues/251
|
|
39
|
+
// Instead, the `Unzip` class has its own `push(chunk)` / `onfile` / `entry.ondata` protocol.
|
|
40
|
+
// This code reads the binary input stream and forwards each chunk of it to `unzip.push()`,
|
|
41
|
+
// and then collects the decompressed file entries.
|
|
42
|
+
//
|
|
43
|
+
// P.S. In the comments to `UnzipInflate` in `fflate` package, it says:
|
|
44
|
+
// "Streaming DEFLATE decompression for ZIP archives. Prefer AsyncZipInflate for better performance."
|
|
45
|
+
// But there seems to be no `AsyncZipInflate` class in the `fflate` package.
|
|
46
|
+
// https://github.com/101arrowz/fflate/issues/277
|
|
47
|
+
// So just the regular `UnzipInflate` is used here.
|
|
48
|
+
//
|
|
49
|
+
import { Unzip, UnzipInflate } from 'fflate';
|
|
50
|
+
import { Buffer } from 'node:buffer';
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Reads `*.zip` file contents.
|
|
54
|
+
* @param {Stream} stream
|
|
55
|
+
* @return {Promise<Record<string,Buffer>>} Resolves to an object holding `*.zip` file entries. P.S. `Buffer` is a `Uint8Array`.
|
|
56
|
+
*/
|
|
57
|
+
export default function unzipFromStream(stream) {
|
|
58
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
59
|
+
filter = _ref.filter;
|
|
60
|
+
// The `files` object stores the files and their contents.
|
|
61
|
+
var files = {};
|
|
62
|
+
return new Promise(function (resolve, reject) {
|
|
63
|
+
var errored = false;
|
|
64
|
+
var onError = function onError(error) {
|
|
65
|
+
if (!errored) {
|
|
66
|
+
errored = true;
|
|
67
|
+
reject(error);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
var _createZipFileValidat = createZipFileValidator(function (isValid) {
|
|
71
|
+
if (!isValid) {
|
|
72
|
+
onError(new Error('Invalid `.zip` archive'));
|
|
73
|
+
}
|
|
74
|
+
}),
|
|
75
|
+
validateChunk = _createZipFileValidat.validateChunk;
|
|
76
|
+
|
|
77
|
+
// `Unzip` discovers each individual file entry in the input data stream
|
|
78
|
+
// and then calls the callback function for each such entry.
|
|
79
|
+
var unzip = new Unzip(function (entry) {
|
|
80
|
+
// If there already was an error while reading this `.zip` file,
|
|
81
|
+
// ignore any follow-up entries.
|
|
82
|
+
if (errored) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Skip directory entries (their names end with a slash).
|
|
87
|
+
// Only files are of any interest.
|
|
88
|
+
if (entry.name.endsWith('/')) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
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: entry.name
|
|
97
|
+
})) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
var chunks = [];
|
|
101
|
+
|
|
102
|
+
// `entry.ondata` is called with each decompressed chunk of the entry,
|
|
103
|
+
// and a final time with `isLast === true` once the entry is complete.
|
|
104
|
+
entry.ondata = function (error, chunk, isLast) {
|
|
105
|
+
if (error) {
|
|
106
|
+
return onError(error);
|
|
107
|
+
}
|
|
108
|
+
chunks.push(chunk);
|
|
109
|
+
if (isLast) {
|
|
110
|
+
files[entry.name] = Buffer.concat(chunks);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// Start decompressing this entry.
|
|
115
|
+
entry.start();
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// Register the decompressor for the data that was compressed using
|
|
119
|
+
// `DEFLATE` compression algorithm (compression method `8`),
|
|
120
|
+
// which is what `.xlsx` files use.
|
|
121
|
+
unzip.register(UnzipInflate);
|
|
122
|
+
stream
|
|
123
|
+
// Catch errors emitted from the input stream (for example, a file read error).
|
|
124
|
+
.on('error', onError)
|
|
125
|
+
// When another chunk of data is read from the input stream.
|
|
126
|
+
.on('data', function (chunk) {
|
|
127
|
+
// If there already was an error while reading this `.zip` file,
|
|
128
|
+
// ignore any follow-up data chunks.
|
|
129
|
+
if (errored) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
// Validate the `.zip` archive as its data comes through.
|
|
133
|
+
validateChunk(chunk);
|
|
134
|
+
// If the `.zip` archive is found to be invalid, stop any further
|
|
135
|
+
// processing of it.
|
|
136
|
+
if (errored) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
// Push the next data chunk to `fflate`'s `Unzip` class instance.
|
|
140
|
+
// The `.push()` function is synchronous, meaning that by the time it returns,
|
|
141
|
+
// any complete files entries encountered so far have already been decompressed
|
|
142
|
+
// and populated in the `files` object.
|
|
143
|
+
try {
|
|
144
|
+
unzip.push(chunk, false);
|
|
145
|
+
} catch (error) {
|
|
146
|
+
onError(error);
|
|
147
|
+
}
|
|
148
|
+
})
|
|
149
|
+
// When there's no more data in the input stream to consume,
|
|
150
|
+
// finish reading the `.zip` archive.
|
|
151
|
+
.on('end', function () {
|
|
152
|
+
// If there were any errors when reading the `.zip` archive,
|
|
153
|
+
// don't `resolve()` with anything.
|
|
154
|
+
if (errored) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
try {
|
|
158
|
+
// Signal the end of the archive to `fflate`'s `Unzip` class instance.
|
|
159
|
+
// It will flush any remaining state in it.
|
|
160
|
+
unzip.push(new Uint8Array(0), true);
|
|
161
|
+
// Resolve with the unzipped files.
|
|
162
|
+
resolve(files);
|
|
163
|
+
} catch (error) {
|
|
164
|
+
onError(error);
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Every section in a `.zip` archive is marked with 4 bytes, the first two of which
|
|
171
|
+
// are `0x50` and `0x4B`, which reads "PK", referencing the initials of the inventor Phil Katz.
|
|
172
|
+
//
|
|
173
|
+
// It looks like `fflate`'s `Unzip` doesn't ever complain about whatever data is thrown at it.
|
|
174
|
+
// Due to how `.zip` file format is defined, "garbage" data could be placed at various
|
|
175
|
+
// places in it and it'd still be a valid `.zip` archive. It's likely that for this reason
|
|
176
|
+
// `fflate` doesn't ever complain and simply emits no entries when fed any kind of invalid data.
|
|
177
|
+
//
|
|
178
|
+
// In order to introduce some basic validation, here we specifically demand
|
|
179
|
+
// that a `.zip` archive must at least start with an individual file entry
|
|
180
|
+
// because an `.xlsx` file creator softwared really shouldn't attempt doing
|
|
181
|
+
// anything "funny" when writing a file, hence this adherence requirement.
|
|
182
|
+
//
|
|
183
|
+
function createZipFileValidator(onValidationResult) {
|
|
184
|
+
var firstBytesCount = 2;
|
|
185
|
+
var firstBytes = [];
|
|
186
|
+
var firstBytesCheckResult;
|
|
187
|
+
return {
|
|
188
|
+
validateChunk: function validateChunk(chunk) {
|
|
189
|
+
if (firstBytes.length < 2) {
|
|
190
|
+
var i = 0;
|
|
191
|
+
while (i < chunk.length && i < firstBytesCount) {
|
|
192
|
+
firstBytes.push(chunk[i]);
|
|
193
|
+
i++;
|
|
194
|
+
}
|
|
195
|
+
if (firstBytes.length === 2) {
|
|
196
|
+
var isValid = firstBytes[0] === 0x50 && firstBytes[1] === 0x4B;
|
|
197
|
+
onValidationResult(isValid);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
//# sourceMappingURL=unzipFromStream.fflate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unzipFromStream.fflate.js","names":["Unzip","UnzipInflate","Buffer","unzipFromStream","stream","_ref","arguments","length","undefined","filter","files","Promise","resolve","reject","errored","onError","error","_createZipFileValidat","createZipFileValidator","isValid","Error","validateChunk","unzip","entry","name","endsWith","path","chunks","ondata","chunk","isLast","push","concat","start","register","on","Uint8Array","onValidationResult","firstBytesCount","firstBytes","firstBytesCheckResult","i"],"sources":["../../source/zip/unzipFromStream.fflate.js"],"sourcesContent":["// `fflate` uses a javascript-only implementation of `.zip` compression/decompression.\r\n// This means that it could likely be less performant than Node.js's \"native\" `zlib` module`.\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\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// with `UnzipInflate` decompression implementation to decompress the data\r\n// that was previously compressed using `DEFLATE` compressing algorithm,\r\n// which is what `*.xlsx` files use.\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, UnzipInflate } from 'fflate'\r\n\r\nimport { Buffer } from 'node:buffer'\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\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\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\t// See if this file should be ignored.\r\n\t\t\t// If it should, this entry won't be processed, i.e. `Unzip` will not try\r\n\t\t\t// to decompress its data, and will just discard it.\r\n\t\t\tif (filter && !filter({ path: entry.name })) {\r\n\t\t\t\treturn\r\n\t\t\t}\r\n\r\n\t\t\tconst chunks = []\r\n\r\n\t\t\t// `entry.ondata` is called with each decompressed chunk of the entry,\r\n\t\t\t// and 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\tchunks.push(chunk)\r\n\t\t\t\tif (isLast) {\r\n\t\t\t\t\tfiles[entry.name] = Buffer.concat(chunks)\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(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// The `.push()` function is synchronous, meaning that by the time it returns,\r\n\t\t\t\t// any complete files entries encountered so far have already been decompressed\r\n\t\t\t\t// and populated in the `files` object.\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// Resolve with the unzipped files.\r\n\t\t\t\t\tresolve(files)\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}"],"mappings":"AAAA;AACA;;AAEA;AACA;;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;AACA;AACA;AACA;AACA,SAASA,KAAK,EAAEC,YAAY,QAAQ,QAAQ;AAE5C,SAASC,MAAM,QAAQ,aAAa;;AAEpC;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,eAAeA,CAACC,MAAM,EAAmB;EAAA,IAAAC,IAAA,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,S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;QAC1B,IAAIkC,CAAC,GAAG,CAAC;QACT,OAAOA,CAAC,GAAGZ,KAAK,CAACtB,MAAM,IAAIkC,CAAC,GAAGH,eAAe,EAAE;UAC/CC,UAAU,CAACR,IAAI,CAACF,KAAK,CAACY,CAAC,CAAC,CAAC;UACzBA,CAAC,EAAE;QACJ;QACA,IAAIF,UAAU,CAAChC,MAAM,KAAK,CAAC,EAAE;UAC5B,IAAMY,OAAO,GAAGoB,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI,IAAIA,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI;UAChEF,kBAAkB,CAAClB,OAAO,CAAC;QAC5B;MACD;IACD;EACD,CAAC;AACF"}
|
|
@@ -1,200 +1,14 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
|
|
4
|
-
// A `*.zip` file consists of individual file entries with the "total" summary section
|
|
5
|
-
// placed at the end of the file rather than at the start of it, which was originally done
|
|
6
|
-
// to allow for easy append of data to a given `.zip` file.
|
|
7
|
-
// https://en.wikipedia.org/wiki/ZIP_(file_format)
|
|
1
|
+
// Currently, there're two implementations:
|
|
2
|
+
// * `fflate` — a pure-javascript implementation that uses `fflate` package.
|
|
3
|
+
// * `unzipper` — a "native" Node.js module that uses Node's `zlib` which is written in C.
|
|
8
4
|
//
|
|
9
|
-
//
|
|
10
|
-
// using the "officially recommended" way of first reading the "total" summary section
|
|
11
|
-
// and only then reading the individual file entries specified in that summary section.
|
|
5
|
+
// The implementations are compared in a benchmark:
|
|
12
6
|
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
// for individual file entries and handle them one-by-one as they come.
|
|
7
|
+
// ```
|
|
8
|
+
// npm run test:benchmark:unzipFromStream
|
|
9
|
+
// ```
|
|
17
10
|
//
|
|
18
|
-
//
|
|
19
|
-
// because an `*.xlsx` files is supposed to be a normal `.zip` archive
|
|
20
|
-
// without any "trickery" such as "deleted" files or "garbage" data
|
|
21
|
-
// hiding under the hood.
|
|
11
|
+
// The benchmark tells that `unzipper` is 2x faster than `fflate`.
|
|
22
12
|
//
|
|
23
|
-
|
|
24
|
-
// with an individual file entry followed by another individual file entry, etc.
|
|
25
|
-
//
|
|
26
|
-
// When the "summary" section is reached, we assume that the archive has ended.
|
|
27
|
-
//
|
|
28
|
-
// To read a `.zip` archive, the code uses `fflate`'s `Unzip` class
|
|
29
|
-
// with `UnzipInflate` decompression implementation to decompress the data
|
|
30
|
-
// that was previously compressed using `DEFLATE` compressing algorithm,
|
|
31
|
-
// which is what `*.xlsx` files use.
|
|
32
|
-
//
|
|
33
|
-
// The `Unzip` class doesn't speak the Node.js stream interface, and `fflate`'s readme
|
|
34
|
-
// doesn't include a clear "reading a `.zip` file from a Node.js stream" section.
|
|
35
|
-
// https://github.com/101arrowz/fflate/issues/251
|
|
36
|
-
// Instead, the `Unzip` class has its own `push(chunk)` / `onfile` / `entry.ondata` protocol.
|
|
37
|
-
// This code reads the binary input stream and forwards each chunk of it to `unzip.push()`,
|
|
38
|
-
// and then collects the decompressed file entries.
|
|
39
|
-
//
|
|
40
|
-
// P.S. In the comments to `UnzipInflate` in `fflate` package, it says:
|
|
41
|
-
// "Streaming DEFLATE decompression for ZIP archives. Prefer AsyncZipInflate for better performance."
|
|
42
|
-
// But there seems to be no `AsyncZipInflate` class in the `fflate` package.
|
|
43
|
-
// https://github.com/101arrowz/fflate/issues/277
|
|
44
|
-
// So just the regular `UnzipInflate` is used here.
|
|
45
|
-
//
|
|
46
|
-
import { Unzip, UnzipInflate } from 'fflate';
|
|
47
|
-
import { Buffer } from 'node:buffer';
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Reads `*.zip` file contents.
|
|
51
|
-
* @param {Stream} stream
|
|
52
|
-
* @return {Promise<Record<string,Buffer>>} Resolves to an object holding `*.zip` file entries. P.S. `Buffer` is a `Uint8Array`.
|
|
53
|
-
*/
|
|
54
|
-
export default function unzipFromStream(stream) {
|
|
55
|
-
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
56
|
-
filter = _ref.filter;
|
|
57
|
-
// The `files` object stores the files and their contents.
|
|
58
|
-
var files = {};
|
|
59
|
-
return new Promise(function (resolve, reject) {
|
|
60
|
-
var errored = false;
|
|
61
|
-
var onError = function onError(error) {
|
|
62
|
-
if (!errored) {
|
|
63
|
-
errored = true;
|
|
64
|
-
reject(error);
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
var _createZipFileValidat = createZipFileValidator(function (isValid) {
|
|
68
|
-
if (!isValid) {
|
|
69
|
-
onError(new Error('Invalid `.zip` archive'));
|
|
70
|
-
}
|
|
71
|
-
}),
|
|
72
|
-
validateChunk = _createZipFileValidat.validateChunk;
|
|
73
|
-
|
|
74
|
-
// `Unzip` discovers each individual file entry in the input data stream
|
|
75
|
-
// and then calls the callback function for each such entry.
|
|
76
|
-
var unzip = new Unzip(function (entry) {
|
|
77
|
-
// If there already was an error while reading this `.zip` file,
|
|
78
|
-
// ignore any follow-up entries.
|
|
79
|
-
if (errored) {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Skip directory entries (their names end with a slash).
|
|
84
|
-
// Only files are of any interest.
|
|
85
|
-
if (entry.name.endsWith('/')) {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// See if this file should be ignored.
|
|
90
|
-
// If it should, this entry won't be processed, i.e. `Unzip` will not try
|
|
91
|
-
// to decompress its data, and will just discard it.
|
|
92
|
-
if (filter && !filter({
|
|
93
|
-
path: entry.name
|
|
94
|
-
})) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
var chunks = [];
|
|
98
|
-
|
|
99
|
-
// `entry.ondata` is called with each decompressed chunk of the entry,
|
|
100
|
-
// and a final time with `isLast === true` once the entry is complete.
|
|
101
|
-
entry.ondata = function (error, chunk, isLast) {
|
|
102
|
-
if (error) {
|
|
103
|
-
return onError(error);
|
|
104
|
-
}
|
|
105
|
-
chunks.push(chunk);
|
|
106
|
-
if (isLast) {
|
|
107
|
-
files[entry.name] = Buffer.concat(chunks);
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
// Start decompressing this entry.
|
|
112
|
-
entry.start();
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
// Register the decompressor for the data that was compressed using
|
|
116
|
-
// `DEFLATE` compression algorithm (compression method `8`),
|
|
117
|
-
// which is what `.xlsx` files use.
|
|
118
|
-
unzip.register(UnzipInflate);
|
|
119
|
-
stream
|
|
120
|
-
// Catch errors emitted from the input stream (for example, a file read error).
|
|
121
|
-
.on('error', onError)
|
|
122
|
-
// When another chunk of data is read from the input stream.
|
|
123
|
-
.on('data', function (chunk) {
|
|
124
|
-
// If there already was an error while reading this `.zip` file,
|
|
125
|
-
// ignore any follow-up data chunks.
|
|
126
|
-
if (errored) {
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
// Validate the `.zip` archive as its data comes through.
|
|
130
|
-
validateChunk(chunk);
|
|
131
|
-
// If the `.zip` archive is found to be invalid, stop any further
|
|
132
|
-
// processing of it.
|
|
133
|
-
if (errored) {
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
// Push the next data chunk to `fflate`'s `Unzip` class instance.
|
|
137
|
-
// The `.push()` function is synchronous, meaning that by the time it returns,
|
|
138
|
-
// any complete files entries encountered so far have already been decompressed
|
|
139
|
-
// and populated in the `files` object.
|
|
140
|
-
try {
|
|
141
|
-
unzip.push(chunk, false);
|
|
142
|
-
} catch (error) {
|
|
143
|
-
onError(error);
|
|
144
|
-
}
|
|
145
|
-
})
|
|
146
|
-
// When there's no more data in the input stream to consume,
|
|
147
|
-
// finish reading the `.zip` archive.
|
|
148
|
-
.on('end', function () {
|
|
149
|
-
// If there were any errors when reading the `.zip` archive,
|
|
150
|
-
// don't `resolve()` with anything.
|
|
151
|
-
if (errored) {
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
try {
|
|
155
|
-
// Signal the end of the archive to `fflate`'s `Unzip` class instance.
|
|
156
|
-
// It will flush any remaining state in it.
|
|
157
|
-
unzip.push(new Uint8Array(0), true);
|
|
158
|
-
// Resolve with the unzipped files.
|
|
159
|
-
resolve(files);
|
|
160
|
-
} catch (error) {
|
|
161
|
-
onError(error);
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// Every section in a `.zip` archive is marked with 4 bytes, the first two of which
|
|
168
|
-
// are `0x50` and `0x4B`, which reads "PK", referencing the initials of the inventor Phil Katz.
|
|
169
|
-
//
|
|
170
|
-
// It looks like `fflate`'s `Unzip` doesn't ever complain about whatever data is thrown at it.
|
|
171
|
-
// Due to how `.zip` file format is defined, "garbage" data could be placed at various
|
|
172
|
-
// places in it and it'd still be a valid `.zip` archive. It's likely that for this reason
|
|
173
|
-
// `fflate` doesn't ever complain and simply emits no entries when fed any kind of invalid data.
|
|
174
|
-
//
|
|
175
|
-
// In order to introduce some basic validation, here we specifically demand
|
|
176
|
-
// that a `.zip` archive must at least start with an individual file entry
|
|
177
|
-
// because an `.xlsx` file creator softwared really shouldn't attempt doing
|
|
178
|
-
// anything "funny" when writing a file, hence this adherence requirement.
|
|
179
|
-
//
|
|
180
|
-
function createZipFileValidator(onValidationResult) {
|
|
181
|
-
var firstBytesCount = 2;
|
|
182
|
-
var firstBytes = [];
|
|
183
|
-
var firstBytesCheckResult;
|
|
184
|
-
return {
|
|
185
|
-
validateChunk: function validateChunk(chunk) {
|
|
186
|
-
if (firstBytes.length < 2) {
|
|
187
|
-
var i = 0;
|
|
188
|
-
while (i < chunk.length && i < firstBytesCount) {
|
|
189
|
-
firstBytes.push(chunk[i]);
|
|
190
|
-
i++;
|
|
191
|
-
}
|
|
192
|
-
if (firstBytes.length === 2) {
|
|
193
|
-
var isValid = firstBytes[0] === 0x50 && firstBytes[1] === 0x4B;
|
|
194
|
-
onValidationResult(isValid);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
};
|
|
199
|
-
}
|
|
13
|
+
export { default } from './unzipFromStream.unzipper.js';
|
|
200
14
|
//# sourceMappingURL=unzipFromStream.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unzipFromStream.js","names":["Unzip","UnzipInflate","Buffer","unzipFromStream","stream","_ref","arguments","length","undefined","filter","files","Promise","resolve","reject","errored","onError","error","_createZipFileValidat","createZipFileValidator","isValid","Error","validateChunk","unzip","entry","name","endsWith","path","chunks","ondata","chunk","isLast","push","concat","start","register","on","Uint8Array","onValidationResult","firstBytesCount","firstBytes","firstBytesCheckResult","i"],"sources":["../../source/zip/unzipFromStream.js"],"sourcesContent":["// This code was originally submitted by Stian Jensen.\r\n// https://github.com/catamphetamine/read-excel-file/pull/122\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// with `UnzipInflate` decompression implementation to decompress the data\r\n// that was previously compressed using `DEFLATE` compressing algorithm,\r\n// which is what `*.xlsx` files use.\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, UnzipInflate } from 'fflate'\r\n\r\nimport { Buffer } from 'node:buffer'\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\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\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\t// See if this file should be ignored.\r\n\t\t\t// If it should, this entry won't be processed, i.e. `Unzip` will not try\r\n\t\t\t// to decompress its data, and will just discard it.\r\n\t\t\tif (filter && !filter({ path: entry.name })) {\r\n\t\t\t\treturn\r\n\t\t\t}\r\n\r\n\t\t\tconst chunks = []\r\n\r\n\t\t\t// `entry.ondata` is called with each decompressed chunk of the entry,\r\n\t\t\t// and 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\tchunks.push(chunk)\r\n\t\t\t\tif (isLast) {\r\n\t\t\t\t\tfiles[entry.name] = Buffer.concat(chunks)\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(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// The `.push()` function is synchronous, meaning that by the time it returns,\r\n\t\t\t\t// any complete files entries encountered so far have already been decompressed\r\n\t\t\t\t// and populated in the `files` object.\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// Resolve with the unzipped files.\r\n\t\t\t\t\tresolve(files)\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}"],"mappings":"AAAA;AACA;;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;AACA;AACA;AACA;AACA,SAASA,KAAK,EAAEC,YAAY,QAAQ,QAAQ;AAE5C,SAASC,MAAM,QAAQ,aAAa;;AAEpC;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,eAAeA,CAACC,MAAM,EAAmB;EAAA,IAAAC,IAAA,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAJ,CAAC,CAAC;IAAbG,MAAM,GAAAJ,IAAA,CAANI,MAAM;EACvD;EACA,IAAMC,KAAK,GAAG,CAAC,CAAC;EAEhB,OAAO,IAAIC,OAAO,CAAC,UAACC,OAAO,EAAEC,MAAM,EAAK;IACvC,IAAIC,OAAO,GAAG,KAAK;IAEnB,IAAMC,OAAO,GAAG,SAAVA,OAAOA,CAAIC,KAAK,EAAK;MAC1B,IAA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GAAGoB,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI,IAAIA,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI;UAChEF,kBAAkB,CAAClB,OAAO,CAAC;QAC5B;MACD;IACD;EACD,CAAC;AACF"}
|
|
1
|
+
{"version":3,"file":"unzipFromStream.js","names":["default"],"sources":["../../source/zip/unzipFromStream.js"],"sourcesContent":["// Currently, there're two implementations:\r\n// * `fflate` — a pure-javascript implementation that uses `fflate` package.\r\n// * `unzipper` — a \"native\" Node.js module that uses Node's `zlib` which is written in C.\r\n//\r\n// The implementations are compared in a benchmark:\r\n//\r\n// ```\r\n// npm run test:benchmark:unzipFromStream\r\n// ```\r\n//\r\n// The benchmark tells that `unzipper` is 2x faster than `fflate`.\r\n//\r\nexport { default as default } from './unzipFromStream.unzipper.js'"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,OAAkB,QAAQ,+BAA+B"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// `unzipper` uses Node.js native `zlib` module.
|
|
2
|
+
// This means that most likely it's more performant than an equivalent javascript-only implementation.
|
|
3
|
+
|
|
4
|
+
// `unzipper` has a bug — it is written in CommonJS and uses a conditional `require()` call
|
|
5
|
+
// to create an AWS S3 client instance: `require('@aws-sdk/client-s3')`.
|
|
6
|
+
// https://github.com/ZJONSSON/node-unzipper/issues/330
|
|
7
|
+
// The author of the package refuses to acknowledge the issue and apply a simple fix.
|
|
8
|
+
// The package, therefore, looks like an "abandonware".
|
|
9
|
+
// Someone could easily fix the issue though by forking the package.
|
|
10
|
+
//
|
|
11
|
+
// When not forking to apply the fix, a workaround could be to install "@aws-sdk/client-s3"
|
|
12
|
+
// package manually, which introduces unnecessary complexity and "esoteric knowledge" to the application setup.
|
|
13
|
+
//
|
|
14
|
+
// Another workaround could be to "alias" "@aws-sdk/client-s3" package in a "bundler" configuration file
|
|
15
|
+
// with a path to a `*.js` file containing just "export default null". But that kind of a workaround would also
|
|
16
|
+
// result in errors when using other packages that happen to `import` anything from "@aws-sdk/client-s3" package,
|
|
17
|
+
// so it's not really a workaround but more of a ticking bomb. Not to mention that it introduces
|
|
18
|
+
// unnecessary complexity and "esoteric knowledge" to the application setup.
|
|
19
|
+
//
|
|
20
|
+
import { Parse } from 'unzipper-esm';
|
|
21
|
+
import { Buffer } from 'buffer';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Reads `*.zip` file contents.
|
|
25
|
+
* @param {Stream} stream
|
|
26
|
+
* @return {Promise<Record<string,Buffer>>} Resolves to an object holding `*.zip` file entries. P.S. `Buffer` is a `Uint8Array`.
|
|
27
|
+
*/
|
|
28
|
+
export default function unzipFromStream(stream) {
|
|
29
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
30
|
+
filter = _ref.filter;
|
|
31
|
+
// The `files` object stores the files and their contents.
|
|
32
|
+
var files = {};
|
|
33
|
+
return new Promise(function (resolve, reject) {
|
|
34
|
+
var promises = [];
|
|
35
|
+
var errored = false;
|
|
36
|
+
var onError = function onError(error) {
|
|
37
|
+
if (!errored) {
|
|
38
|
+
errored = true;
|
|
39
|
+
reject(error);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
stream
|
|
43
|
+
// This first "error" listener catches the original stream errors.
|
|
44
|
+
//
|
|
45
|
+
// That's because the .pipe() method does not automatically propagate errors
|
|
46
|
+
// from a source (input) stream to the destination stream or the end of the pipeline.
|
|
47
|
+
// You would need to attach an 'error' event handler to each stream in the chain.
|
|
48
|
+
//
|
|
49
|
+
// A more convenient alternative would be to use `stream.pipeline()` function:
|
|
50
|
+
// `pipeline(stream1, stream2, (error) => { ... })`
|
|
51
|
+
//
|
|
52
|
+
.on('error', onError)
|
|
53
|
+
// Pipe the input stream through the unzipper stream.
|
|
54
|
+
.pipe(Parse())
|
|
55
|
+
// This second "error" listener catches the unzipper stream errors.
|
|
56
|
+
//
|
|
57
|
+
// That's because the .pipe() method does not automatically propagate errors
|
|
58
|
+
// from a source (input) stream to the destination stream or the end of the pipeline.
|
|
59
|
+
// You would need to attach an 'error' event handler to each stream in the chain.
|
|
60
|
+
//
|
|
61
|
+
// A more convenient alternative would be to use `stream.pipeline()` function:
|
|
62
|
+
// `pipeline(stream1, stream2, (error) => { ... })`
|
|
63
|
+
//
|
|
64
|
+
.on('error', onError)
|
|
65
|
+
// The unzipper stream is closed when all `entries` have been reported.
|
|
66
|
+
.on('finish', function () {
|
|
67
|
+
if (!errored) {
|
|
68
|
+
// Wait for all `entries` to be read.
|
|
69
|
+
// The second argument of `.then()` function is not required
|
|
70
|
+
// but I didn't remove it just to potentially prevent any potential silly bugs
|
|
71
|
+
// in case of some potential changes in some potential future.
|
|
72
|
+
Promise.all(promises).then(function () {
|
|
73
|
+
resolve(files);
|
|
74
|
+
}, onError);
|
|
75
|
+
}
|
|
76
|
+
}).on('entry', function (entry) {
|
|
77
|
+
// See if this file should be ignored.
|
|
78
|
+
var ignore = false;
|
|
79
|
+
// `entry.type` could be 'Directory' or 'File'.
|
|
80
|
+
// Ignore anything except files.
|
|
81
|
+
if (entry.type === 'Directory') {
|
|
82
|
+
ignore = true;
|
|
83
|
+
}
|
|
84
|
+
if (errored) {
|
|
85
|
+
ignore = true;
|
|
86
|
+
}
|
|
87
|
+
if (filter) {
|
|
88
|
+
if (!filter({
|
|
89
|
+
path: entry.path
|
|
90
|
+
})) {
|
|
91
|
+
ignore = true;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// If this file should be ignored.
|
|
96
|
+
if (ignore) {
|
|
97
|
+
// Call `entry.autodrain()` when you do not intend to process a specific `entry`'s raw data.
|
|
98
|
+
// Otherwise, if an `entry` is not consumed (via .pipe(), .buffer(), or .autodrain()),
|
|
99
|
+
// the stream will halt, preventing further file processing.
|
|
100
|
+
entry.autodrain().on('error', onError);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
var chunks = [];
|
|
104
|
+
promises.push(new Promise(function (resolve) {
|
|
105
|
+
// `entry` seems to be a generic Node.js stream.
|
|
106
|
+
// `entry.pipe()` pipes the file contents to a stream.
|
|
107
|
+
// `entry.stream()` returns a readable stream.
|
|
108
|
+
// `entry.buffer()` returns a promise that resolves to a `Buffer` with the file contents.
|
|
109
|
+
entry.on('data', function (data) {
|
|
110
|
+
chunks.push(data);
|
|
111
|
+
}).on('error', function (error) {
|
|
112
|
+
onError(error);
|
|
113
|
+
}).on('finish', function () {
|
|
114
|
+
files[entry.path] = Buffer.concat(chunks);
|
|
115
|
+
resolve();
|
|
116
|
+
});
|
|
117
|
+
}));
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=unzipFromStream.unzipper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unzipFromStream.unzipper.js","names":["Parse","Buffer","unzipFromStream","stream","_ref","arguments","length","undefined","filter","files","Promise","resolve","reject","promises","errored","onError","error","on","pipe","all","then","entry","ignore","type","path","autodrain","chunks","push","data","concat"],"sources":["../../source/zip/unzipFromStream.unzipper.js"],"sourcesContent":["// `unzipper` uses Node.js native `zlib` module.\r\n// This means that most likely it's more performant than an equivalent javascript-only implementation.\r\n\r\n// `unzipper` has a bug — it is written in CommonJS and uses a conditional `require()` call\r\n// to create an AWS S3 client instance: `require('@aws-sdk/client-s3')`.\r\n// https://github.com/ZJONSSON/node-unzipper/issues/330\r\n// The author of the package refuses to acknowledge the issue and apply a simple fix.\r\n// The package, therefore, looks like an \"abandonware\".\r\n// Someone could easily fix the issue though by forking the package.\r\n//\r\n// When not forking to apply the fix, a workaround could be to install \"@aws-sdk/client-s3\"\r\n// package manually, which introduces unnecessary complexity and \"esoteric knowledge\" to the application setup.\r\n//\r\n// Another workaround could be to \"alias\" \"@aws-sdk/client-s3\" package in a \"bundler\" configuration file\r\n// with a path to a `*.js` file containing just \"export default null\". But that kind of a workaround would also\r\n// result in errors when using other packages that happen to `import` anything from \"@aws-sdk/client-s3\" package,\r\n// so it's not really a workaround but more of a ticking bomb. Not to mention that it introduces\r\n// unnecessary complexity and \"esoteric knowledge\" to the application setup.\r\n//\r\nimport { Parse } from 'unzipper-esm'\r\n\r\nimport { Buffer } from 'buffer'\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\r\n\treturn new Promise((resolve, reject) => {\r\n\t\tconst promises = []\r\n\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\tstream\r\n\t\t\t// This first \"error\" listener catches the original stream errors.\r\n\t\t\t//\r\n\t\t\t// That's because the .pipe() method does not automatically propagate errors\r\n\t\t\t// from a source (input) stream to the destination stream or the end of the pipeline.\r\n\t\t\t// You would need to attach an 'error' event handler to each stream in the chain.\r\n\t\t\t//\r\n\t\t\t// A more convenient alternative would be to use `stream.pipeline()` function:\r\n\t\t\t// `pipeline(stream1, stream2, (error) => { ... })`\r\n\t\t\t//\r\n\t\t\t.on('error', onError)\r\n\t\t\t// Pipe the input stream through the unzipper stream.\r\n\t\t\t.pipe(Parse())\r\n\t\t\t// This second \"error\" listener catches the unzipper stream errors.\r\n\t\t\t//\r\n\t\t\t// That's because the .pipe() method does not automatically propagate errors\r\n\t\t\t// from a source (input) stream to the destination stream or the end of the pipeline.\r\n\t\t\t// You would need to attach an 'error' event handler to each stream in the chain.\r\n\t\t\t//\r\n\t\t\t// A more convenient alternative would be to use `stream.pipeline()` function:\r\n\t\t\t// `pipeline(stream1, stream2, (error) => { ... })`\r\n\t\t\t//\r\n\t\t\t.on('error', onError)\r\n\t\t\t// The unzipper stream is closed when all `entries` have been reported.\r\n\t\t\t.on('finish', () => {\r\n\t\t\t\tif (!errored) {\r\n\t\t\t\t\t// Wait for all `entries` to be read.\r\n\t\t\t\t\t// The second argument of `.then()` function is not required\r\n\t\t\t\t\t// but I didn't remove it just to potentially prevent any potential silly bugs\r\n\t\t\t\t\t// in case of some potential changes in some potential future.\r\n\t\t\t\t\tPromise.all(promises).then(() => {\r\n\t\t\t\t\t\tresolve(files)\r\n\t\t\t\t\t}, onError)\r\n\t\t\t\t}\r\n\t\t\t})\r\n\t\t\t.on('entry', (entry) => {\r\n\t\t\t\t// See if this file should be ignored.\r\n\t\t\t\tlet ignore = false\r\n\t\t\t\t// `entry.type` could be 'Directory' or 'File'.\r\n\t\t\t\t// Ignore anything except files.\r\n\t\t\t\tif (entry.type === 'Directory') {\r\n\t\t\t\t\tignore = true\r\n\t\t\t\t}\r\n\t\t\t\tif (errored) {\r\n\t\t\t\t\tignore = true\r\n\t\t\t\t}\r\n\t\t\t\tif (filter) {\r\n\t\t\t\t\tif (!filter({ path: entry.path })) {\r\n\t\t\t\t\t\tignore = true\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// If this file should be ignored.\r\n\t\t\t\tif (ignore) {\r\n\t\t\t\t\t// Call `entry.autodrain()` when you do not intend to process a specific `entry`'s raw data.\r\n\t\t\t\t\t// Otherwise, if an `entry` is not consumed (via .pipe(), .buffer(), or .autodrain()),\r\n\t\t\t\t\t// the stream will halt, preventing further file processing.\r\n\t\t\t\t\tentry.autodrain().on('error', onError)\r\n\t\t\t\t\treturn\r\n\t\t\t\t}\r\n\r\n\t\t\t\tconst chunks = []\r\n\r\n\t\t\t\tpromises.push(new Promise((resolve) => {\r\n\t\t\t\t\t// `entry` seems to be a generic Node.js stream.\r\n\t\t\t\t\t// `entry.pipe()` pipes the file contents to a stream.\r\n\t\t\t\t\t// `entry.stream()` returns a readable stream.\r\n\t\t\t\t\t// `entry.buffer()` returns a promise that resolves to a `Buffer` with the file contents.\r\n\t\t\t\t\tentry\r\n\t\t\t\t\t\t.on('data', (data) => {\r\n\t\t\t\t\t\t\tchunks.push(data)\r\n\t\t\t\t\t\t})\r\n\t\t\t\t\t\t.on('error', (error) => {\r\n\t\t\t\t\t\t\tonError(error)\r\n\t\t\t\t\t\t})\r\n\t\t\t\t\t\t.on('finish', () => {\r\n\t\t\t\t\t\t\tfiles[entry.path] = Buffer.concat(chunks)\r\n\t\t\t\t\t\t\tresolve()\r\n\t\t\t\t\t\t})\r\n\t\t\t\t}))\r\n\t\t\t})\r\n\t})\r\n}"],"mappings":"AAAA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,KAAK,QAAQ,cAAc;AAEpC,SAASC,MAAM,QAAQ,QAAQ;;AAE/B;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,eAAeA,CAACC,MAAM,EAAmB;EAAA,IAAAC,IAAA,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAJ,CAAC,CAAC;IAAbG,MAAM,GAAAJ,IAAA,CAANI,MAAM;EACvD;EACA,IAAMC,KAAK,GAAG,CAAC,CAAC;EAEhB,OAAO,IAAIC,OAAO,CAAC,UAACC,OAAO,EAAEC,MAAM,EAAK;IACvC,IAAMC,QAAQ,GAAG,EAAE;IAEnB,IAAIC,OAAO,GAAG,KAAK;IAEnB,IAAMC,OAAO,GAAG,SAAVA,OAAOA,CAAIC,KAAK,EAAK;MAC1B,IAAI,CAACF,OAAO,EAAE;QACbA,OAAO,GAAG,IAAI;QACdF,MAAM,CAACI,KAAK,CAAC;MACd;IACD,CAAC;IAEDb;IACC;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IAAA,CACCc,EAAE,CAAC,OAAO,EAAEF,OAAO;IACpB;IAAA,CACCG,IAAI,CAAClB,KAAK,C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