@cj-tech-master/excelts 4.2.1-canary.20260111102127.f808a37 → 4.2.1
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/THIRD_PARTY_NOTICES.md +31 -0
- package/dist/browser/index.browser.d.ts +0 -1
- package/dist/browser/index.browser.js +0 -12
- package/dist/browser/modules/archive/byte-queue.d.ts +18 -0
- package/dist/browser/modules/archive/byte-queue.js +125 -0
- package/dist/browser/modules/archive/{compression/compress.base.js → compress.base.js} +1 -1
- package/dist/browser/modules/archive/{compression/compress.browser.d.ts → compress.browser.d.ts} +8 -2
- package/dist/{esm/modules/archive/compression → browser/modules/archive}/compress.browser.js +11 -3
- package/dist/browser/modules/archive/{compression/compress.d.ts → compress.d.ts} +2 -2
- package/dist/{esm/modules/archive/compression → browser/modules/archive}/compress.js +1 -1
- package/dist/browser/modules/archive/{compression/crc32.browser.d.ts → crc32.browser.d.ts} +1 -1
- package/dist/browser/modules/archive/{compression/crc32.d.ts → crc32.d.ts} +1 -1
- package/dist/browser/modules/archive/{compression/crc32.js → crc32.js} +1 -1
- package/dist/browser/modules/archive/defaults.d.ts +0 -1
- package/dist/browser/modules/archive/defaults.js +3 -6
- package/dist/browser/modules/archive/{compression/deflate-fallback.js → deflate-fallback.js} +1 -1
- package/dist/browser/modules/archive/{unzip/extract.d.ts → extract.d.ts} +2 -2
- package/dist/browser/modules/archive/index.base.d.ts +4 -4
- package/dist/browser/modules/archive/index.base.js +6 -3
- package/dist/browser/modules/archive/index.browser.d.ts +4 -3
- package/dist/browser/modules/archive/index.browser.js +7 -3
- package/dist/browser/modules/archive/index.d.ts +4 -3
- package/dist/browser/modules/archive/index.js +5 -3
- package/dist/browser/modules/archive/{unzip/stream.base.d.ts → parse.base.d.ts} +2 -36
- package/dist/browser/modules/archive/parse.base.js +644 -0
- package/dist/browser/modules/archive/{unzip/stream.browser.d.ts → parse.browser.d.ts} +1 -1
- package/dist/{esm/modules/archive/unzip/stream.browser.js → browser/modules/archive/parse.browser.js} +110 -371
- package/dist/browser/modules/archive/{unzip/stream.d.ts → parse.d.ts} +2 -2
- package/dist/{esm/modules/archive/unzip/stream.js → browser/modules/archive/parse.js} +5 -6
- package/dist/browser/modules/archive/{compression/streaming-compress.browser.d.ts → streaming-compress.browser.d.ts} +2 -2
- package/dist/browser/modules/archive/{compression/streaming-compress.browser.js → streaming-compress.browser.js} +3 -3
- package/dist/browser/modules/archive/{compression/streaming-compress.d.ts → streaming-compress.d.ts} +2 -2
- package/dist/browser/modules/archive/{compression/streaming-compress.js → streaming-compress.js} +2 -2
- package/dist/browser/modules/archive/{zip/stream.d.ts → streaming-zip.d.ts} +5 -28
- package/dist/{esm/modules/archive/zip/stream.js → browser/modules/archive/streaming-zip.js} +48 -192
- package/dist/browser/modules/archive/utils/bytes.js +16 -16
- package/dist/browser/modules/archive/utils/parse-buffer.js +23 -21
- package/dist/browser/modules/archive/utils/timestamps.js +1 -62
- package/dist/browser/modules/archive/utils/zip-extra-fields.d.ts +1 -1
- package/dist/browser/modules/archive/utils/zip-extra-fields.js +14 -26
- package/dist/browser/modules/archive/utils/zip-extra.d.ts +18 -0
- package/dist/browser/modules/archive/utils/zip-extra.js +68 -0
- package/dist/browser/modules/archive/zip-builder.d.ts +117 -0
- package/dist/browser/modules/archive/zip-builder.js +292 -0
- package/dist/browser/modules/archive/zip-constants.d.ts +18 -0
- package/dist/browser/modules/archive/zip-constants.js +23 -0
- package/dist/{esm/modules/archive/zip → browser/modules/archive}/zip-entry-metadata.js +3 -3
- package/dist/{types/modules/archive/unzip → browser/modules/archive}/zip-parser.d.ts +1 -1
- package/dist/{esm/modules/archive/unzip → browser/modules/archive}/zip-parser.js +24 -38
- package/dist/browser/modules/archive/{zip-spec/zip-records.d.ts → zip-records.d.ts} +0 -20
- package/dist/browser/modules/archive/zip-records.js +84 -0
- package/dist/browser/modules/excel/stream/workbook-reader.browser.js +1 -1
- package/dist/browser/modules/excel/stream/workbook-writer.browser.d.ts +1 -1
- package/dist/browser/modules/excel/stream/workbook-writer.browser.js +1 -1
- package/dist/browser/modules/excel/xlsx/xlsx.browser.js +6 -3
- package/dist/browser/modules/excel/xlsx/xlsx.js +1 -1
- package/dist/browser/modules/stream/streams.browser.d.ts +30 -28
- package/dist/browser/modules/stream/streams.browser.js +710 -830
- package/dist/browser/modules/stream/streams.js +58 -140
- package/dist/cjs/modules/archive/byte-queue.js +129 -0
- package/dist/cjs/modules/archive/{compression/compress.base.js → compress.base.js} +1 -1
- package/dist/cjs/modules/archive/{compression/compress.browser.js → compress.browser.js} +11 -3
- package/dist/cjs/modules/archive/{compression/compress.js → compress.js} +1 -1
- package/dist/cjs/modules/archive/{compression/crc32.js → crc32.js} +1 -1
- package/dist/cjs/modules/archive/defaults.js +4 -7
- package/dist/cjs/modules/archive/{compression/deflate-fallback.js → deflate-fallback.js} +1 -1
- package/dist/cjs/modules/archive/index.base.js +19 -9
- package/dist/cjs/modules/archive/index.browser.js +10 -4
- package/dist/cjs/modules/archive/index.js +8 -4
- package/dist/cjs/modules/archive/parse.base.js +666 -0
- package/dist/cjs/modules/archive/{unzip/stream.browser.js → parse.browser.js} +111 -372
- package/dist/cjs/modules/archive/{unzip/stream.js → parse.js} +8 -9
- package/dist/cjs/modules/archive/{compression/streaming-compress.browser.js → streaming-compress.browser.js} +3 -3
- package/dist/cjs/modules/archive/{compression/streaming-compress.js → streaming-compress.js} +2 -2
- package/dist/cjs/modules/archive/{zip/stream.js → streaming-zip.js} +50 -194
- package/dist/cjs/modules/archive/utils/bytes.js +16 -16
- package/dist/cjs/modules/archive/utils/parse-buffer.js +23 -21
- package/dist/cjs/modules/archive/utils/timestamps.js +3 -64
- package/dist/cjs/modules/archive/utils/zip-extra-fields.js +14 -26
- package/dist/cjs/modules/archive/utils/zip-extra.js +74 -0
- package/dist/cjs/modules/archive/zip-builder.js +297 -0
- package/dist/cjs/modules/archive/zip-constants.js +26 -0
- package/dist/cjs/modules/archive/{zip/zip-entry-metadata.js → zip-entry-metadata.js} +5 -5
- package/dist/cjs/modules/archive/{unzip/zip-parser.js → zip-parser.js} +33 -47
- package/dist/cjs/modules/archive/zip-records.js +90 -0
- package/dist/cjs/modules/excel/stream/workbook-reader.browser.js +2 -2
- package/dist/cjs/modules/excel/stream/workbook-writer.browser.js +4 -4
- package/dist/cjs/modules/excel/xlsx/xlsx.browser.js +9 -6
- package/dist/cjs/modules/excel/xlsx/xlsx.js +2 -2
- package/dist/cjs/modules/stream/streams.browser.js +710 -830
- package/dist/cjs/modules/stream/streams.js +58 -140
- package/dist/esm/index.browser.js +0 -12
- package/dist/esm/modules/archive/byte-queue.js +125 -0
- package/dist/esm/modules/archive/{compression/compress.base.js → compress.base.js} +1 -1
- package/dist/{browser/modules/archive/compression → esm/modules/archive}/compress.browser.js +11 -3
- package/dist/{browser/modules/archive/compression → esm/modules/archive}/compress.js +1 -1
- package/dist/esm/modules/archive/{compression/crc32.js → crc32.js} +1 -1
- package/dist/esm/modules/archive/defaults.js +3 -6
- package/dist/esm/modules/archive/{compression/deflate-fallback.js → deflate-fallback.js} +1 -1
- package/dist/esm/modules/archive/index.base.js +6 -3
- package/dist/esm/modules/archive/index.browser.js +7 -3
- package/dist/esm/modules/archive/index.js +5 -3
- package/dist/esm/modules/archive/parse.base.js +644 -0
- package/dist/{browser/modules/archive/unzip/stream.browser.js → esm/modules/archive/parse.browser.js} +110 -371
- package/dist/{browser/modules/archive/unzip/stream.js → esm/modules/archive/parse.js} +5 -6
- package/dist/esm/modules/archive/{compression/streaming-compress.browser.js → streaming-compress.browser.js} +3 -3
- package/dist/esm/modules/archive/{compression/streaming-compress.js → streaming-compress.js} +2 -2
- package/dist/{browser/modules/archive/zip/stream.js → esm/modules/archive/streaming-zip.js} +48 -192
- package/dist/esm/modules/archive/utils/bytes.js +16 -16
- package/dist/esm/modules/archive/utils/parse-buffer.js +23 -21
- package/dist/esm/modules/archive/utils/timestamps.js +1 -62
- package/dist/esm/modules/archive/utils/zip-extra-fields.js +14 -26
- package/dist/esm/modules/archive/utils/zip-extra.js +68 -0
- package/dist/esm/modules/archive/zip-builder.js +292 -0
- package/dist/esm/modules/archive/zip-constants.js +23 -0
- package/dist/{browser/modules/archive/zip → esm/modules/archive}/zip-entry-metadata.js +3 -3
- package/dist/{browser/modules/archive/unzip → esm/modules/archive}/zip-parser.js +24 -38
- package/dist/esm/modules/archive/zip-records.js +84 -0
- package/dist/esm/modules/excel/stream/workbook-reader.browser.js +1 -1
- package/dist/esm/modules/excel/stream/workbook-writer.browser.js +1 -1
- package/dist/esm/modules/excel/xlsx/xlsx.browser.js +6 -3
- package/dist/esm/modules/excel/xlsx/xlsx.js +1 -1
- package/dist/esm/modules/stream/streams.browser.js +710 -830
- package/dist/esm/modules/stream/streams.js +58 -140
- package/dist/iife/THIRD_PARTY_NOTICES.md +31 -0
- package/dist/iife/excelts.iife.js +4425 -6215
- package/dist/iife/excelts.iife.js.map +1 -1
- package/dist/iife/excelts.iife.min.js +31 -103
- package/dist/types/index.browser.d.ts +0 -1
- package/dist/types/modules/archive/byte-queue.d.ts +18 -0
- package/dist/types/modules/archive/{compression/compress.browser.d.ts → compress.browser.d.ts} +8 -2
- package/dist/types/modules/archive/defaults.d.ts +0 -1
- package/dist/types/modules/archive/index.base.d.ts +4 -4
- package/dist/types/modules/archive/index.browser.d.ts +4 -3
- package/dist/types/modules/archive/index.d.ts +4 -3
- package/dist/types/modules/archive/{unzip/stream.base.d.ts → parse.base.d.ts} +4 -38
- package/dist/types/modules/archive/{unzip/stream.browser.d.ts → parse.browser.d.ts} +2 -2
- package/dist/types/modules/archive/{unzip/stream.d.ts → parse.d.ts} +3 -3
- package/dist/types/modules/archive/{compression/streaming-compress.browser.d.ts → streaming-compress.browser.d.ts} +1 -1
- package/dist/types/modules/archive/{zip/stream.d.ts → streaming-zip.d.ts} +6 -29
- package/dist/types/modules/archive/utils/zip-extra-fields.d.ts +1 -1
- package/dist/types/modules/archive/utils/zip-extra.d.ts +18 -0
- package/dist/types/modules/archive/zip-builder.d.ts +117 -0
- package/dist/types/modules/archive/zip-constants.d.ts +18 -0
- package/dist/types/modules/archive/{zip/zip-entry-metadata.d.ts → zip-entry-metadata.d.ts} +1 -1
- package/dist/{browser/modules/archive/unzip → types/modules/archive}/zip-parser.d.ts +1 -1
- package/dist/types/modules/archive/{zip-spec/zip-records.d.ts → zip-records.d.ts} +0 -20
- package/dist/types/modules/excel/stream/workbook-writer.browser.d.ts +1 -1
- package/dist/types/modules/stream/streams.browser.d.ts +30 -28
- package/package.json +1 -5
- package/dist/browser/modules/archive/internal/byte-queue.d.ts +0 -33
- package/dist/browser/modules/archive/internal/byte-queue.js +0 -407
- package/dist/browser/modules/archive/io/archive-sink.d.ts +0 -9
- package/dist/browser/modules/archive/io/archive-sink.js +0 -77
- package/dist/browser/modules/archive/io/archive-source.d.ts +0 -8
- package/dist/browser/modules/archive/io/archive-source.js +0 -107
- package/dist/browser/modules/archive/unzip/index.d.ts +0 -40
- package/dist/browser/modules/archive/unzip/index.js +0 -164
- package/dist/browser/modules/archive/unzip/stream.base.js +0 -1022
- package/dist/browser/modules/archive/utils/async-queue.d.ts +0 -7
- package/dist/browser/modules/archive/utils/async-queue.js +0 -103
- package/dist/browser/modules/archive/utils/compressibility.d.ts +0 -10
- package/dist/browser/modules/archive/utils/compressibility.js +0 -57
- package/dist/browser/modules/archive/utils/pattern-scanner.d.ts +0 -21
- package/dist/browser/modules/archive/utils/pattern-scanner.js +0 -27
- package/dist/browser/modules/archive/zip/index.d.ts +0 -42
- package/dist/browser/modules/archive/zip/index.js +0 -157
- package/dist/browser/modules/archive/zip/zip-bytes.d.ts +0 -73
- package/dist/browser/modules/archive/zip/zip-bytes.js +0 -239
- package/dist/browser/modules/archive/zip-spec/zip-records.js +0 -126
- package/dist/cjs/modules/archive/internal/byte-queue.js +0 -411
- package/dist/cjs/modules/archive/io/archive-sink.js +0 -82
- package/dist/cjs/modules/archive/io/archive-source.js +0 -114
- package/dist/cjs/modules/archive/unzip/index.js +0 -170
- package/dist/cjs/modules/archive/unzip/stream.base.js +0 -1044
- package/dist/cjs/modules/archive/utils/async-queue.js +0 -106
- package/dist/cjs/modules/archive/utils/compressibility.js +0 -60
- package/dist/cjs/modules/archive/utils/pattern-scanner.js +0 -31
- package/dist/cjs/modules/archive/zip/index.js +0 -162
- package/dist/cjs/modules/archive/zip/zip-bytes.js +0 -242
- package/dist/cjs/modules/archive/zip-spec/zip-records.js +0 -136
- package/dist/esm/modules/archive/internal/byte-queue.js +0 -407
- package/dist/esm/modules/archive/io/archive-sink.js +0 -77
- package/dist/esm/modules/archive/io/archive-source.js +0 -107
- package/dist/esm/modules/archive/unzip/index.js +0 -164
- package/dist/esm/modules/archive/unzip/stream.base.js +0 -1022
- package/dist/esm/modules/archive/utils/async-queue.js +0 -103
- package/dist/esm/modules/archive/utils/compressibility.js +0 -57
- package/dist/esm/modules/archive/utils/pattern-scanner.js +0 -27
- package/dist/esm/modules/archive/zip/index.js +0 -157
- package/dist/esm/modules/archive/zip/zip-bytes.js +0 -239
- package/dist/esm/modules/archive/zip-spec/zip-records.js +0 -126
- package/dist/types/modules/archive/internal/byte-queue.d.ts +0 -33
- package/dist/types/modules/archive/io/archive-sink.d.ts +0 -9
- package/dist/types/modules/archive/io/archive-source.d.ts +0 -8
- package/dist/types/modules/archive/unzip/index.d.ts +0 -40
- package/dist/types/modules/archive/utils/async-queue.d.ts +0 -7
- package/dist/types/modules/archive/utils/compressibility.d.ts +0 -10
- package/dist/types/modules/archive/utils/pattern-scanner.d.ts +0 -21
- package/dist/types/modules/archive/zip/index.d.ts +0 -42
- package/dist/types/modules/archive/zip/zip-bytes.d.ts +0 -73
- /package/dist/browser/modules/archive/{compression/compress.base.d.ts → compress.base.d.ts} +0 -0
- /package/dist/browser/modules/archive/{compression/crc32.base.d.ts → crc32.base.d.ts} +0 -0
- /package/dist/browser/modules/archive/{compression/crc32.base.js → crc32.base.js} +0 -0
- /package/dist/browser/modules/archive/{compression/crc32.browser.js → crc32.browser.js} +0 -0
- /package/dist/browser/modules/archive/{compression/deflate-fallback.d.ts → deflate-fallback.d.ts} +0 -0
- /package/dist/browser/modules/archive/{unzip/extract.js → extract.js} +0 -0
- /package/dist/browser/modules/archive/{compression/streaming-compress.base.d.ts → streaming-compress.base.d.ts} +0 -0
- /package/dist/browser/modules/archive/{compression/streaming-compress.base.js → streaming-compress.base.js} +0 -0
- /package/dist/browser/modules/archive/{zip-spec/zip-entry-info.d.ts → zip-entry-info.d.ts} +0 -0
- /package/dist/browser/modules/archive/{zip-spec/zip-entry-info.js → zip-entry-info.js} +0 -0
- /package/dist/browser/modules/archive/{zip/zip-entry-metadata.d.ts → zip-entry-metadata.d.ts} +0 -0
- /package/dist/cjs/modules/archive/{compression/crc32.base.js → crc32.base.js} +0 -0
- /package/dist/cjs/modules/archive/{compression/crc32.browser.js → crc32.browser.js} +0 -0
- /package/dist/cjs/modules/archive/{unzip/extract.js → extract.js} +0 -0
- /package/dist/cjs/modules/archive/{compression/streaming-compress.base.js → streaming-compress.base.js} +0 -0
- /package/dist/cjs/modules/archive/{zip-spec/zip-entry-info.js → zip-entry-info.js} +0 -0
- /package/dist/esm/modules/archive/{compression/crc32.base.js → crc32.base.js} +0 -0
- /package/dist/esm/modules/archive/{compression/crc32.browser.js → crc32.browser.js} +0 -0
- /package/dist/esm/modules/archive/{unzip/extract.js → extract.js} +0 -0
- /package/dist/esm/modules/archive/{compression/streaming-compress.base.js → streaming-compress.base.js} +0 -0
- /package/dist/esm/modules/archive/{zip-spec/zip-entry-info.js → zip-entry-info.js} +0 -0
- /package/dist/types/modules/archive/{compression/compress.base.d.ts → compress.base.d.ts} +0 -0
- /package/dist/types/modules/archive/{compression/compress.d.ts → compress.d.ts} +0 -0
- /package/dist/types/modules/archive/{compression/crc32.base.d.ts → crc32.base.d.ts} +0 -0
- /package/dist/types/modules/archive/{compression/crc32.browser.d.ts → crc32.browser.d.ts} +0 -0
- /package/dist/types/modules/archive/{compression/crc32.d.ts → crc32.d.ts} +0 -0
- /package/dist/types/modules/archive/{compression/deflate-fallback.d.ts → deflate-fallback.d.ts} +0 -0
- /package/dist/types/modules/archive/{unzip/extract.d.ts → extract.d.ts} +0 -0
- /package/dist/types/modules/archive/{compression/streaming-compress.base.d.ts → streaming-compress.base.d.ts} +0 -0
- /package/dist/types/modules/archive/{compression/streaming-compress.d.ts → streaming-compress.d.ts} +0 -0
- /package/dist/types/modules/archive/{zip-spec/zip-entry-info.d.ts → zip-entry-info.d.ts} +0 -0
|
@@ -7,16 +7,18 @@ exports.Parse = void 0;
|
|
|
7
7
|
exports.createParseClass = createParseClass;
|
|
8
8
|
exports.createParse = createParse;
|
|
9
9
|
const zlib_1 = __importDefault(require("zlib"));
|
|
10
|
-
const
|
|
10
|
+
const binary_1 = require("./utils/binary.js");
|
|
11
|
+
const parse_base_1 = require("./parse.base.js");
|
|
12
|
+
const zip_constants_1 = require("./zip-constants.js");
|
|
11
13
|
/**
|
|
12
14
|
* Creates an InflateRaw stream using Node.js native zlib.
|
|
13
15
|
*/
|
|
14
16
|
function createInflateRaw() {
|
|
15
17
|
return zlib_1.default.createInflateRaw();
|
|
16
18
|
}
|
|
17
|
-
const dataDescriptorSignature =
|
|
19
|
+
const dataDescriptorSignature = (0, binary_1.writeUint32LE)(zip_constants_1.DATA_DESCRIPTOR_SIG);
|
|
18
20
|
function createParseClass(createInflateRawFn) {
|
|
19
|
-
return class Parse extends
|
|
21
|
+
return class Parse extends parse_base_1.PullStream {
|
|
20
22
|
constructor(opts = {}) {
|
|
21
23
|
super();
|
|
22
24
|
this._driverState = {};
|
|
@@ -56,7 +58,7 @@ function createParseClass(createInflateRawFn) {
|
|
|
56
58
|
}
|
|
57
59
|
};
|
|
58
60
|
// Parse records as data arrives. Only emit `close` when parsing is complete.
|
|
59
|
-
(0,
|
|
61
|
+
(0, parse_base_1.runParseLoop)(this._opts, io, emitter, createInflateRawFn, this._driverState, (data) => zlib_1.default.inflateRawSync(data)).catch((e) => {
|
|
60
62
|
if (!this.__emittedError || this.__emittedError !== e) {
|
|
61
63
|
this.emit("error", e);
|
|
62
64
|
}
|
|
@@ -67,14 +69,11 @@ function createParseClass(createInflateRawFn) {
|
|
|
67
69
|
* Stream file data until we reach a DATA_DESCRIPTOR record boundary.
|
|
68
70
|
*/
|
|
69
71
|
_streamUntilValidatedDataDescriptor() {
|
|
70
|
-
return (0,
|
|
72
|
+
return (0, parse_base_1.streamUntilValidatedDataDescriptor)({
|
|
71
73
|
source: {
|
|
74
|
+
getView: () => this._queue.view(),
|
|
72
75
|
getLength: () => this._queue.length,
|
|
73
76
|
read: (length) => this._queue.read(length),
|
|
74
|
-
peekChunks: (length) => this._queue.peekChunks(length),
|
|
75
|
-
discard: (length) => this._queue.discard(length),
|
|
76
|
-
indexOfPattern: (pattern, startIndex) => this._queue.indexOfPattern(pattern, startIndex),
|
|
77
|
-
peekUint32LE: (offset) => this._queue.peekUint32LE(offset),
|
|
78
77
|
isFinished: () => this.finished,
|
|
79
78
|
onDataAvailable: (cb) => {
|
|
80
79
|
this.on("chunk", cb);
|
|
@@ -11,11 +11,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
11
11
|
exports.hasDeflateRaw = hasDeflateRaw;
|
|
12
12
|
exports.createDeflateStream = createDeflateStream;
|
|
13
13
|
exports.createInflateStream = createInflateStream;
|
|
14
|
-
const _stream_1 = require("
|
|
14
|
+
const _stream_1 = require("../stream/index.js");
|
|
15
15
|
const deflate_fallback_1 = require("./deflate-fallback.js");
|
|
16
16
|
const compress_base_1 = require("./compress.base.js");
|
|
17
|
-
const bytes_1 = require("
|
|
18
|
-
const defaults_1 = require("
|
|
17
|
+
const bytes_1 = require("./utils/bytes.js");
|
|
18
|
+
const defaults_1 = require("./defaults.js");
|
|
19
19
|
const streaming_compress_base_1 = require("./streaming-compress.base.js");
|
|
20
20
|
/**
|
|
21
21
|
* Check if deflate-raw streaming compression is supported by this library.
|
package/dist/cjs/modules/archive/{compression/streaming-compress.js → streaming-compress.js}
RENAMED
|
@@ -10,8 +10,8 @@ exports.createDeflateStream = createDeflateStream;
|
|
|
10
10
|
exports.createInflateStream = createInflateStream;
|
|
11
11
|
exports.hasDeflateRaw = hasDeflateRaw;
|
|
12
12
|
const zlib_1 = require("zlib");
|
|
13
|
-
const _stream_1 = require("
|
|
14
|
-
const defaults_1 = require("
|
|
13
|
+
const _stream_1 = require("../stream/index.js");
|
|
14
|
+
const defaults_1 = require("./defaults.js");
|
|
15
15
|
/**
|
|
16
16
|
* Wrapper around zlib DeflateRaw that flushes after every write
|
|
17
17
|
* This ensures true streaming behavior - data is emitted immediately, not buffered
|
|
@@ -3,18 +3,17 @@
|
|
|
3
3
|
* True Streaming ZIP creator - shared implementation.
|
|
4
4
|
*
|
|
5
5
|
* This module is intentionally platform-agnostic.
|
|
6
|
-
* - In Node builds it uses `./
|
|
6
|
+
* - In Node builds it uses `./crc32` + `./streaming-compress` (zlib-backed).
|
|
7
7
|
* - In browser builds the bundler aliases those imports to their browser variants.
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.ZipDeflate = exports.Zip = exports.StreamingZip = exports.ZipDeflateFile = void 0;
|
|
11
|
-
const crc32_1 = require("
|
|
12
|
-
const streaming_compress_1 = require("
|
|
13
|
-
const defaults_1 = require("
|
|
11
|
+
const crc32_1 = require("./crc32.js");
|
|
12
|
+
const streaming_compress_1 = require("./streaming-compress.js");
|
|
13
|
+
const defaults_1 = require("./defaults.js");
|
|
14
14
|
const zip_entry_metadata_1 = require("./zip-entry-metadata.js");
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const zip_records_1 = require("../zip-spec/zip-records.js");
|
|
15
|
+
const zip_records_1 = require("./zip-records.js");
|
|
16
|
+
const zip_constants_1 = require("./zip-constants.js");
|
|
18
17
|
/**
|
|
19
18
|
* True Streaming ZIP File - compresses chunk by chunk
|
|
20
19
|
*/
|
|
@@ -27,15 +26,9 @@ class ZipDeflateFile {
|
|
|
27
26
|
this._finalized = false;
|
|
28
27
|
this._headerEmitted = false;
|
|
29
28
|
this._ondata = null;
|
|
30
|
-
this._onerror = null;
|
|
31
29
|
this._centralDirEntryInfo = null;
|
|
32
30
|
this._pendingEnd = false;
|
|
33
31
|
this._emittedDataDescriptor = false;
|
|
34
|
-
this._localHeader = null;
|
|
35
|
-
// Smart STORE: delay method selection until we sample data.
|
|
36
|
-
this._deflateWanted = null;
|
|
37
|
-
this._pendingChunks = [];
|
|
38
|
-
this._sampleLen = 0;
|
|
39
32
|
// Promise resolution for completion (including data descriptor)
|
|
40
33
|
this._completeResolve = null;
|
|
41
34
|
this._completeReject = null;
|
|
@@ -44,70 +37,46 @@ class ZipDeflateFile {
|
|
|
44
37
|
// Queue for incoming data before ondata is set
|
|
45
38
|
this._dataQueue = [];
|
|
46
39
|
this._finalQueued = false;
|
|
47
|
-
// Serialize push() calls so callers don't need to await to preserve ordering.
|
|
48
|
-
this._pushChain = Promise.resolve();
|
|
49
40
|
this.name = name;
|
|
50
41
|
const modTime = options?.modTime ?? new Date();
|
|
51
42
|
this._modTime = modTime;
|
|
52
43
|
this.level = options?.level ?? defaults_1.DEFAULT_ZIP_LEVEL;
|
|
53
|
-
this._smartStore = options?.smartStore ?? true;
|
|
54
|
-
this._sampleBuffer = this._smartStore ? new Uint8Array(64 * 1024) : new Uint8Array(0);
|
|
55
44
|
const metadata = (0, zip_entry_metadata_1.buildZipEntryMetadata)({
|
|
56
45
|
name,
|
|
57
|
-
comment:
|
|
46
|
+
comment: "",
|
|
58
47
|
modTime,
|
|
59
48
|
timestamps: options?.timestamps ?? defaults_1.DEFAULT_ZIP_TIMESTAMPS,
|
|
60
49
|
useDataDescriptor: true,
|
|
61
|
-
deflate:
|
|
50
|
+
deflate: this.level > 0
|
|
62
51
|
});
|
|
63
52
|
this.nameBytes = metadata.nameBytes;
|
|
64
|
-
this.commentBytes = metadata.commentBytes;
|
|
65
53
|
this.dosTime = metadata.dosTime;
|
|
66
54
|
this.dosDate = metadata.dosDate;
|
|
67
55
|
this.extraField = metadata.extraField;
|
|
68
56
|
this._flags = metadata.flags;
|
|
69
57
|
this._compressionMethod = metadata.compressionMethod;
|
|
70
|
-
//
|
|
71
|
-
if (
|
|
72
|
-
|
|
73
|
-
this.
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (this._deflate) {
|
|
91
|
-
return;
|
|
58
|
+
// Create deflate stream for compression
|
|
59
|
+
if (this.level > 0) {
|
|
60
|
+
this._deflate = (0, streaming_compress_1.createDeflateStream)({ level: this.level });
|
|
61
|
+
this._deflate.on("error", (err) => {
|
|
62
|
+
this._rejectComplete(err);
|
|
63
|
+
});
|
|
64
|
+
// Handle compressed output - this is true streaming!
|
|
65
|
+
this._deflate.on("data", (chunk) => {
|
|
66
|
+
this._compressedSize += chunk.length;
|
|
67
|
+
this._enqueueData(chunk, false);
|
|
68
|
+
});
|
|
69
|
+
// Handle end - emit data descriptor
|
|
70
|
+
// IMPORTANT: Only use 'end' event, NOT 'finish'!
|
|
71
|
+
// Node.js zlib emits events in order: finish -> data -> end
|
|
72
|
+
this._deflate.on("end", () => {
|
|
73
|
+
if (this._pendingEnd && !this._emittedDataDescriptor) {
|
|
74
|
+
this._emittedDataDescriptor = true;
|
|
75
|
+
this._emitDataDescriptor();
|
|
76
|
+
}
|
|
77
|
+
});
|
|
92
78
|
}
|
|
93
|
-
this.
|
|
94
|
-
this._deflate.on("error", (err) => {
|
|
95
|
-
this._rejectComplete(err);
|
|
96
|
-
});
|
|
97
|
-
// Handle compressed output - this is true streaming!
|
|
98
|
-
this._deflate.on("data", (chunk) => {
|
|
99
|
-
this._compressedSize += chunk.length;
|
|
100
|
-
this._enqueueData(chunk, false);
|
|
101
|
-
});
|
|
102
|
-
// Handle end - emit data descriptor
|
|
103
|
-
// IMPORTANT: Only use 'end' event, NOT 'finish'!
|
|
104
|
-
// Node.js zlib emits events in order: finish -> data -> end
|
|
105
|
-
this._deflate.on("end", () => {
|
|
106
|
-
if (this._pendingEnd && !this._emittedDataDescriptor) {
|
|
107
|
-
this._emittedDataDescriptor = true;
|
|
108
|
-
this._emitDataDescriptor();
|
|
109
|
-
}
|
|
110
|
-
});
|
|
79
|
+
this._localHeader = this._buildLocalHeader();
|
|
111
80
|
}
|
|
112
81
|
_buildLocalHeader() {
|
|
113
82
|
// CRC + sizes are written via data descriptor for true streaming.
|
|
@@ -121,66 +90,9 @@ class ZipDeflateFile {
|
|
|
121
90
|
crc32: 0,
|
|
122
91
|
compressedSize: 0,
|
|
123
92
|
uncompressedSize: 0,
|
|
124
|
-
versionNeeded:
|
|
93
|
+
versionNeeded: zip_constants_1.VERSION_NEEDED
|
|
125
94
|
});
|
|
126
95
|
}
|
|
127
|
-
_accumulateSample(data) {
|
|
128
|
-
if (this._deflateWanted !== null) {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
if (this._sampleLen >= this._sampleBuffer.length) {
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
const take = Math.min(this._sampleBuffer.length - this._sampleLen, data.length);
|
|
135
|
-
if (take <= 0) {
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
this._sampleBuffer.set(data.subarray(0, take), this._sampleLen);
|
|
139
|
-
this._sampleLen += take;
|
|
140
|
-
}
|
|
141
|
-
_shouldDecide(final) {
|
|
142
|
-
if (this._deflateWanted !== null) {
|
|
143
|
-
return false;
|
|
144
|
-
}
|
|
145
|
-
return final || this._sampleLen >= 16 * 1024;
|
|
146
|
-
}
|
|
147
|
-
_decideCompressionIfNeeded(final) {
|
|
148
|
-
if (this._deflateWanted !== null) {
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
// Match non-streaming builder semantics: empty files never need DEFLATE.
|
|
152
|
-
if (final && this._sampleLen === 0) {
|
|
153
|
-
this._deflateWanted = false;
|
|
154
|
-
this._compressionMethod = this._buildCompressionMethod(false);
|
|
155
|
-
this._localHeader = null;
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
// Default to DEFLATE unless heuristic says STORE.
|
|
159
|
-
const sample = this._sampleBuffer.subarray(0, this._sampleLen);
|
|
160
|
-
const store = (0, compressibility_1.isProbablyIncompressible)(sample);
|
|
161
|
-
this._deflateWanted = !store;
|
|
162
|
-
this._compressionMethod = this._buildCompressionMethod(this._deflateWanted);
|
|
163
|
-
this._localHeader = null;
|
|
164
|
-
if (this._deflateWanted) {
|
|
165
|
-
this._initDeflateStream();
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
_emitHeaderIfNeeded() {
|
|
169
|
-
if (this._headerEmitted) {
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
this._emitHeader();
|
|
173
|
-
this._headerEmitted = true;
|
|
174
|
-
}
|
|
175
|
-
async _flushPendingChunks() {
|
|
176
|
-
if (this._pendingChunks.length === 0) {
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
for (const chunk of this._pendingChunks) {
|
|
180
|
-
await this._writeData(chunk);
|
|
181
|
-
}
|
|
182
|
-
this._pendingChunks = [];
|
|
183
|
-
}
|
|
184
96
|
_enqueueData(data, final) {
|
|
185
97
|
if (this._ondata) {
|
|
186
98
|
this._ondata(data, final);
|
|
@@ -212,29 +124,13 @@ class ZipDeflateFile {
|
|
|
212
124
|
// Flush any queued data
|
|
213
125
|
this._flushQueue();
|
|
214
126
|
}
|
|
215
|
-
get onerror() {
|
|
216
|
-
return this._onerror ?? undefined;
|
|
217
|
-
}
|
|
218
|
-
set onerror(cb) {
|
|
219
|
-
this._onerror = cb;
|
|
220
|
-
// If an error already occurred, surface it immediately.
|
|
221
|
-
if (this._completeError) {
|
|
222
|
-
cb(this._completeError);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
127
|
_resolveComplete() {
|
|
226
128
|
if (this._completeResolve) {
|
|
227
129
|
this._completeResolve();
|
|
228
130
|
}
|
|
229
131
|
}
|
|
230
132
|
_rejectComplete(err) {
|
|
231
|
-
if (this._completeError) {
|
|
232
|
-
return;
|
|
233
|
-
}
|
|
234
133
|
this._completeError = err;
|
|
235
|
-
if (this._onerror) {
|
|
236
|
-
this._onerror(err);
|
|
237
|
-
}
|
|
238
134
|
if (this._completeReject) {
|
|
239
135
|
this._completeReject(err);
|
|
240
136
|
}
|
|
@@ -260,6 +156,13 @@ class ZipDeflateFile {
|
|
|
260
156
|
}
|
|
261
157
|
promise.then(() => callback()).catch(err => callback(err));
|
|
262
158
|
}
|
|
159
|
+
_emitHeaderIfNeeded() {
|
|
160
|
+
if (this._headerEmitted) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
this._emitHeader();
|
|
164
|
+
this._headerEmitted = true;
|
|
165
|
+
}
|
|
263
166
|
_writeData(data) {
|
|
264
167
|
if (data.length === 0) {
|
|
265
168
|
return Promise.resolve();
|
|
@@ -317,60 +220,27 @@ class ZipDeflateFile {
|
|
|
317
220
|
this._emitDataDescriptor();
|
|
318
221
|
return completePromise;
|
|
319
222
|
}
|
|
320
|
-
|
|
223
|
+
/**
|
|
224
|
+
* Push data - immediately compresses and outputs
|
|
225
|
+
* Returns a Promise that resolves when the write is complete.
|
|
226
|
+
* If final=true, it resolves after the data descriptor is emitted.
|
|
227
|
+
*/
|
|
228
|
+
push(data, final = false, callback) {
|
|
321
229
|
if (this._finalized) {
|
|
322
230
|
const promise = Promise.reject(new Error("Cannot push to finalized ZipDeflateFile"));
|
|
323
231
|
this._tapCallback(promise, callback);
|
|
324
232
|
return promise;
|
|
325
233
|
}
|
|
326
|
-
if (this._deflateWanted === null) {
|
|
327
|
-
this._accumulateSample(data);
|
|
328
|
-
if (!this._shouldDecide(final)) {
|
|
329
|
-
if (data.length > 0) {
|
|
330
|
-
this._pendingChunks.push(data);
|
|
331
|
-
}
|
|
332
|
-
const promise = Promise.resolve();
|
|
333
|
-
this._tapCallback(promise, callback);
|
|
334
|
-
return promise;
|
|
335
|
-
}
|
|
336
|
-
this._decideCompressionIfNeeded(final);
|
|
337
|
-
this._emitHeaderIfNeeded();
|
|
338
|
-
const hadPendingChunks = this._pendingChunks.length > 0;
|
|
339
|
-
const flushPromise = this._flushPendingChunks();
|
|
340
|
-
let writePromise = flushPromise;
|
|
341
|
-
if (data.length > 0) {
|
|
342
|
-
writePromise = hadPendingChunks
|
|
343
|
-
? flushPromise.then(() => this._writeData(data))
|
|
344
|
-
: this._writeData(data);
|
|
345
|
-
}
|
|
346
|
-
const promise = final ? this._finalizeAfterWrite(writePromise) : writePromise;
|
|
347
|
-
this._tapCallback(promise, callback);
|
|
348
|
-
return promise;
|
|
349
|
-
}
|
|
350
234
|
this._emitHeaderIfNeeded();
|
|
351
235
|
const writePromise = this._writeData(data);
|
|
352
236
|
const promise = final ? this._finalizeAfterWrite(writePromise) : writePromise;
|
|
353
237
|
this._tapCallback(promise, callback);
|
|
354
238
|
return promise;
|
|
355
239
|
}
|
|
356
|
-
/**
|
|
357
|
-
* Push data - immediately compresses and outputs
|
|
358
|
-
* Returns a Promise that resolves when the write is complete.
|
|
359
|
-
* If final=true, it resolves after the data descriptor is emitted.
|
|
360
|
-
*/
|
|
361
|
-
push(data, final = false, callback) {
|
|
362
|
-
const promise = (this._pushChain = this._pushChain.then(() => this._pushUnchained(data, final, callback)));
|
|
363
|
-
// Prevent unhandled rejection when callers intentionally ignore the Promise.
|
|
364
|
-
promise.catch(() => { });
|
|
365
|
-
return promise;
|
|
366
|
-
}
|
|
367
240
|
/**
|
|
368
241
|
* Emit local file header with Data Descriptor flag
|
|
369
242
|
*/
|
|
370
243
|
_emitHeader() {
|
|
371
|
-
if (!this._localHeader) {
|
|
372
|
-
this._localHeader = this._buildLocalHeader();
|
|
373
|
-
}
|
|
374
244
|
this._enqueueData(this._localHeader, false);
|
|
375
245
|
}
|
|
376
246
|
/**
|
|
@@ -383,7 +253,6 @@ class ZipDeflateFile {
|
|
|
383
253
|
this._centralDirEntryInfo = {
|
|
384
254
|
name: this.nameBytes,
|
|
385
255
|
extraField: this.extraField,
|
|
386
|
-
comment: this.commentBytes,
|
|
387
256
|
flags: this._flags,
|
|
388
257
|
crc: crcValue,
|
|
389
258
|
compressedSize: this._compressedSize,
|
|
@@ -422,7 +291,7 @@ class ZipDeflateFile {
|
|
|
422
291
|
crc32: this._centralDirEntryInfo.crc,
|
|
423
292
|
lastModified: this._modTime,
|
|
424
293
|
localHeaderOffset: this._centralDirEntryInfo.offset,
|
|
425
|
-
comment:
|
|
294
|
+
comment: "",
|
|
426
295
|
externalAttributes: 0,
|
|
427
296
|
isEncrypted: false
|
|
428
297
|
};
|
|
@@ -441,7 +310,7 @@ exports.ZipDeflate = ZipDeflateFile;
|
|
|
441
310
|
* Streaming ZIP Creator - processes files sequentially
|
|
442
311
|
*/
|
|
443
312
|
class StreamingZip {
|
|
444
|
-
constructor(callback
|
|
313
|
+
constructor(callback) {
|
|
445
314
|
this.entries = [];
|
|
446
315
|
this.currentOffset = 0;
|
|
447
316
|
this.ended = false;
|
|
@@ -451,12 +320,10 @@ class StreamingZip {
|
|
|
451
320
|
this.fileQueueIndex = 0;
|
|
452
321
|
this.activeFile = null;
|
|
453
322
|
this.callback = callback;
|
|
454
|
-
// Avoid per-instance TextEncoder allocations.
|
|
455
|
-
this.zipComment = options?.comment ? (0, text_1.encodeUtf8)(options.comment) : new Uint8Array(0);
|
|
456
323
|
}
|
|
457
324
|
add(file) {
|
|
458
325
|
if (this.ended) {
|
|
459
|
-
throw new Error("Cannot add files after calling end()
|
|
326
|
+
throw new Error("Cannot add files after calling end()");
|
|
460
327
|
}
|
|
461
328
|
this.fileQueue.push(file);
|
|
462
329
|
// If no active file, process this one
|
|
@@ -479,18 +346,7 @@ class StreamingZip {
|
|
|
479
346
|
const file = this.fileQueue[this.fileQueueIndex++];
|
|
480
347
|
this.activeFile = file;
|
|
481
348
|
const startOffset = this.currentOffset;
|
|
482
|
-
const empty = new Uint8Array(0);
|
|
483
|
-
file.onerror = (err) => {
|
|
484
|
-
if (this.ended) {
|
|
485
|
-
return;
|
|
486
|
-
}
|
|
487
|
-
this.ended = true;
|
|
488
|
-
this.callback(err, empty, true);
|
|
489
|
-
};
|
|
490
349
|
file.ondata = (data, final) => {
|
|
491
|
-
if (this.ended) {
|
|
492
|
-
return;
|
|
493
|
-
}
|
|
494
350
|
this.currentOffset += data.length;
|
|
495
351
|
this.callback(null, data, false);
|
|
496
352
|
if (final) {
|
|
@@ -516,7 +372,7 @@ class StreamingZip {
|
|
|
516
372
|
const header = (0, zip_records_1.buildCentralDirectoryHeader)({
|
|
517
373
|
fileName: entry.name,
|
|
518
374
|
extraField: entry.extraField,
|
|
519
|
-
comment:
|
|
375
|
+
comment: empty,
|
|
520
376
|
flags: entry.flags,
|
|
521
377
|
compressionMethod: entry.compressionMethod,
|
|
522
378
|
dosTime: entry.dosTime,
|
|
@@ -525,8 +381,8 @@ class StreamingZip {
|
|
|
525
381
|
compressedSize: entry.compressedSize,
|
|
526
382
|
uncompressedSize: entry.uncompressedSize,
|
|
527
383
|
localHeaderOffset: entry.offset,
|
|
528
|
-
versionMadeBy:
|
|
529
|
-
versionNeeded:
|
|
384
|
+
versionMadeBy: zip_constants_1.VERSION_MADE_BY,
|
|
385
|
+
versionNeeded: zip_constants_1.VERSION_NEEDED
|
|
530
386
|
});
|
|
531
387
|
centralDirSize += header.length;
|
|
532
388
|
this.callback(null, header, false);
|
|
@@ -535,7 +391,7 @@ class StreamingZip {
|
|
|
535
391
|
entryCount: this.entries.length,
|
|
536
392
|
centralDirSize,
|
|
537
393
|
centralDirOffset,
|
|
538
|
-
comment:
|
|
394
|
+
comment: empty
|
|
539
395
|
});
|
|
540
396
|
this.callback(null, eocd, true);
|
|
541
397
|
}
|
|
@@ -50,18 +50,21 @@ function indexOfUint8ArrayPattern(buffer, pattern, startIndex = 0) {
|
|
|
50
50
|
}
|
|
51
51
|
// Fast paths for small patterns (very common in ZIP parsing: 2/3/4-byte signatures).
|
|
52
52
|
if (patLen === 1) {
|
|
53
|
-
|
|
53
|
+
const p0 = pattern[0];
|
|
54
|
+
for (let i = start; i < bufLen; i++) {
|
|
55
|
+
if (buffer[i] === p0) {
|
|
56
|
+
return i;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return -1;
|
|
54
60
|
}
|
|
55
61
|
if (patLen === 2) {
|
|
56
62
|
const p0 = pattern[0];
|
|
57
63
|
const p1 = pattern[1];
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
while (i !== -1 && i <= last) {
|
|
61
|
-
if (buffer[i + 1] === p1) {
|
|
64
|
+
for (let i = start; i <= bufLen - 2; i++) {
|
|
65
|
+
if (buffer[i] === p0 && buffer[i + 1] === p1) {
|
|
62
66
|
return i;
|
|
63
67
|
}
|
|
64
|
-
i = buffer.indexOf(p0, i + 1);
|
|
65
68
|
}
|
|
66
69
|
return -1;
|
|
67
70
|
}
|
|
@@ -69,13 +72,10 @@ function indexOfUint8ArrayPattern(buffer, pattern, startIndex = 0) {
|
|
|
69
72
|
const p0 = pattern[0];
|
|
70
73
|
const p1 = pattern[1];
|
|
71
74
|
const p2 = pattern[2];
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
while (i !== -1 && i <= last) {
|
|
75
|
-
if (buffer[i + 1] === p1 && buffer[i + 2] === p2) {
|
|
75
|
+
for (let i = start; i <= bufLen - 3; i++) {
|
|
76
|
+
if (buffer[i] === p0 && buffer[i + 1] === p1 && buffer[i + 2] === p2) {
|
|
76
77
|
return i;
|
|
77
78
|
}
|
|
78
|
-
i = buffer.indexOf(p0, i + 1);
|
|
79
79
|
}
|
|
80
80
|
return -1;
|
|
81
81
|
}
|
|
@@ -84,13 +84,13 @@ function indexOfUint8ArrayPattern(buffer, pattern, startIndex = 0) {
|
|
|
84
84
|
const p1 = pattern[1];
|
|
85
85
|
const p2 = pattern[2];
|
|
86
86
|
const p3 = pattern[3];
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
87
|
+
for (let i = start; i <= bufLen - 4; i++) {
|
|
88
|
+
if (buffer[i] === p0 &&
|
|
89
|
+
buffer[i + 1] === p1 &&
|
|
90
|
+
buffer[i + 2] === p2 &&
|
|
91
|
+
buffer[i + 3] === p3) {
|
|
91
92
|
return i;
|
|
92
93
|
}
|
|
93
|
-
i = buffer.indexOf(p0, i + 1);
|
|
94
94
|
}
|
|
95
95
|
return -1;
|
|
96
96
|
}
|
|
@@ -2,6 +2,28 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parse = parse;
|
|
4
4
|
exports.parseTyped = parseTyped;
|
|
5
|
+
/**
|
|
6
|
+
* Read unsigned little-endian integer from Uint8Array
|
|
7
|
+
*/
|
|
8
|
+
function readUIntLE(buffer, offset, size) {
|
|
9
|
+
const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
10
|
+
switch (size) {
|
|
11
|
+
case 1:
|
|
12
|
+
return view.getUint8(offset);
|
|
13
|
+
case 2:
|
|
14
|
+
return view.getUint16(offset, true);
|
|
15
|
+
case 4:
|
|
16
|
+
return view.getUint32(offset, true);
|
|
17
|
+
case 8: {
|
|
18
|
+
// Read as BigUint64 and convert to Number
|
|
19
|
+
const low = view.getUint32(offset, true);
|
|
20
|
+
const high = view.getUint32(offset + 4, true);
|
|
21
|
+
return high * 0x100000000 + low;
|
|
22
|
+
}
|
|
23
|
+
default:
|
|
24
|
+
throw new Error("Unsupported UInt LE size!");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
5
27
|
/**
|
|
6
28
|
* Parses sequential unsigned little endian numbers from the head of the passed buffer according to
|
|
7
29
|
* the specified format passed. If the buffer is not large enough to satisfy the full format,
|
|
@@ -20,30 +42,10 @@ exports.parseTyped = parseTyped;
|
|
|
20
42
|
*/
|
|
21
43
|
function parse(buffer, format) {
|
|
22
44
|
const result = {};
|
|
23
|
-
const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
24
45
|
let offset = 0;
|
|
25
46
|
for (const [key, size] of format) {
|
|
26
47
|
if (buffer.length >= offset + size) {
|
|
27
|
-
|
|
28
|
-
case 1:
|
|
29
|
-
result[key] = view.getUint8(offset);
|
|
30
|
-
break;
|
|
31
|
-
case 2:
|
|
32
|
-
result[key] = view.getUint16(offset, true);
|
|
33
|
-
break;
|
|
34
|
-
case 4:
|
|
35
|
-
result[key] = view.getUint32(offset, true);
|
|
36
|
-
break;
|
|
37
|
-
case 8: {
|
|
38
|
-
// Keep behavior (Number) while avoiding BigInt costs.
|
|
39
|
-
const low = view.getUint32(offset, true);
|
|
40
|
-
const high = view.getUint32(offset + 4, true);
|
|
41
|
-
result[key] = high * 0x100000000 + low;
|
|
42
|
-
break;
|
|
43
|
-
}
|
|
44
|
-
default:
|
|
45
|
-
throw new Error("Unsupported UInt LE size!");
|
|
46
|
-
}
|
|
48
|
+
result[key] = readUIntLE(buffer, offset, size);
|
|
47
49
|
}
|
|
48
50
|
else {
|
|
49
51
|
result[key] = null;
|