@loaders.gl/archives 0.0.0-stage → 5.0.0-alpha.14
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/LICENSE +52 -0
- package/README.md +4 -2
- package/dist/dist.dev.js +5101 -0
- package/dist/dist.min.js +9 -0
- package/dist/index.cjs +2982 -0
- package/dist/index.cjs.map +6 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/tar/index.cjs +576 -0
- package/dist/tar/index.cjs.map +6 -0
- package/dist/tar/index.d.ts +8 -0
- package/dist/tar/index.d.ts.map +1 -0
- package/dist/tar/index.js +9 -0
- package/dist/tar/index.js.map +1 -0
- package/dist/tar/lib/header.d.ts +9 -0
- package/dist/tar/lib/header.d.ts.map +1 -0
- package/dist/tar/lib/header.js +76 -0
- package/dist/tar/lib/header.js.map +1 -0
- package/dist/tar/lib/tar.d.ts +29 -0
- package/dist/tar/lib/tar.d.ts.map +1 -0
- package/dist/tar/lib/tar.js +136 -0
- package/dist/tar/lib/tar.js.map +1 -0
- package/dist/tar/lib/types.d.ts +48 -0
- package/dist/tar/lib/types.d.ts.map +1 -0
- package/dist/tar/lib/types.js +5 -0
- package/dist/tar/lib/types.js.map +1 -0
- package/dist/tar/lib/utils.d.ts +23 -0
- package/dist/tar/lib/utils.d.ts.map +1 -0
- package/dist/tar/lib/utils.js +52 -0
- package/dist/tar/lib/utils.js.map +1 -0
- package/dist/tar/tar-archive.d.ts +4 -0
- package/dist/tar/tar-archive.d.ts.map +1 -0
- package/dist/tar/tar-archive.js +97 -0
- package/dist/tar/tar-archive.js.map +1 -0
- package/dist/tar/tar-builder.d.ts +28 -0
- package/dist/tar/tar-builder.d.ts.map +1 -0
- package/dist/tar/tar-builder.js +38 -0
- package/dist/tar/tar-builder.js.map +1 -0
- package/dist/tar/tar-format.d.ts +12 -0
- package/dist/tar/tar-format.d.ts.map +1 -0
- package/dist/tar/tar-format.js +15 -0
- package/dist/tar/tar-format.js.map +1 -0
- package/dist/tar/tar-loader-types.d.ts +15 -0
- package/dist/tar/tar-loader-types.d.ts.map +1 -0
- package/dist/tar/tar-loader-types.js +20 -0
- package/dist/tar/tar-loader-types.js.map +1 -0
- package/dist/tar/tar-loader.cjs +285 -0
- package/dist/tar/tar-loader.cjs.map +6 -0
- package/dist/tar/tar-loader.d.ts +3 -0
- package/dist/tar/tar-loader.d.ts.map +1 -0
- package/dist/tar/tar-loader.js +12 -0
- package/dist/tar/tar-loader.js.map +1 -0
- package/dist/tar/tar-writer.cjs +114 -0
- package/dist/tar/tar-writer.cjs.map +6 -0
- package/dist/tar/tar-writer.d.ts +20 -0
- package/dist/tar/tar-writer.d.ts.map +1 -0
- package/dist/tar/tar-writer.js +94 -0
- package/dist/tar/tar-writer.js.map +1 -0
- package/dist/zip/filesystems/IndexedArchive.d.ts +40 -0
- package/dist/zip/filesystems/IndexedArchive.d.ts.map +1 -0
- package/dist/zip/filesystems/IndexedArchive.js +99 -0
- package/dist/zip/filesystems/IndexedArchive.js.map +1 -0
- package/dist/zip/filesystems/zip-filesystem.d.ts +53 -0
- package/dist/zip/filesystems/zip-filesystem.d.ts.map +1 -0
- package/dist/zip/filesystems/zip-filesystem.js +231 -0
- package/dist/zip/filesystems/zip-filesystem.js.map +1 -0
- package/dist/zip/hash-file-utility.d.ts +20 -0
- package/dist/zip/hash-file-utility.d.ts.map +1 -0
- package/dist/zip/hash-file-utility.js +83 -0
- package/dist/zip/hash-file-utility.js.map +1 -0
- package/dist/zip/index.cjs +4614 -0
- package/dist/zip/index.cjs.map +6 -0
- package/dist/zip/index.d.ts +18 -0
- package/dist/zip/index.d.ts.map +1 -0
- package/dist/zip/index.js +14 -0
- package/dist/zip/index.js.map +1 -0
- package/dist/zip/indexed-zip-writer.cjs +1211 -0
- package/dist/zip/indexed-zip-writer.cjs.map +6 -0
- package/dist/zip/indexed-zip-writer.d.ts +46 -0
- package/dist/zip/indexed-zip-writer.d.ts.map +1 -0
- package/dist/zip/indexed-zip-writer.js +229 -0
- package/dist/zip/indexed-zip-writer.js.map +1 -0
- package/dist/zip/lib/zip-composition.d.ts +37 -0
- package/dist/zip/lib/zip-composition.d.ts.map +1 -0
- package/dist/zip/lib/zip-composition.js +157 -0
- package/dist/zip/lib/zip-composition.js.map +1 -0
- package/dist/zip/lib/zip-entry-metadata.d.ts +34 -0
- package/dist/zip/lib/zip-entry-metadata.d.ts.map +1 -0
- package/dist/zip/lib/zip-entry-metadata.js +132 -0
- package/dist/zip/lib/zip-entry-metadata.js.map +1 -0
- package/dist/zip/lib/zip-serialization.d.ts +36 -0
- package/dist/zip/lib/zip-serialization.d.ts.map +1 -0
- package/dist/zip/lib/zip-serialization.js +148 -0
- package/dist/zip/lib/zip-serialization.js.map +1 -0
- package/dist/zip/lib/zip64-extra-field.d.ts +20 -0
- package/dist/zip/lib/zip64-extra-field.d.ts.map +1 -0
- package/dist/zip/lib/zip64-extra-field.js +53 -0
- package/dist/zip/lib/zip64-extra-field.js.map +1 -0
- package/dist/zip/zip-archive-types.d.ts +56 -0
- package/dist/zip/zip-archive-types.d.ts.map +1 -0
- package/dist/zip/zip-archive-types.js +5 -0
- package/dist/zip/zip-archive-types.js.map +1 -0
- package/dist/zip/zip-archive.d.ts +101 -0
- package/dist/zip/zip-archive.d.ts.map +1 -0
- package/dist/zip/zip-archive.js +593 -0
- package/dist/zip/zip-archive.js.map +1 -0
- package/dist/zip/zip-encode-types.d.ts +41 -0
- package/dist/zip/zip-encode-types.d.ts.map +1 -0
- package/dist/zip/zip-encode-types.js +5 -0
- package/dist/zip/zip-encode-types.js.map +1 -0
- package/dist/zip/zip-encode.cjs +1154 -0
- package/dist/zip/zip-encode.cjs.map +6 -0
- package/dist/zip/zip-encode.d.ts +15 -0
- package/dist/zip/zip-encode.d.ts.map +1 -0
- package/dist/zip/zip-encode.js +312 -0
- package/dist/zip/zip-encode.js.map +1 -0
- package/dist/zip/zip-format.d.ts +14 -0
- package/dist/zip/zip-format.d.ts.map +1 -0
- package/dist/zip/zip-format.js +17 -0
- package/dist/zip/zip-format.js.map +1 -0
- package/dist/zip/zip-loader-types.d.ts +15 -0
- package/dist/zip/zip-loader-types.d.ts.map +1 -0
- package/dist/zip/zip-loader-types.js +20 -0
- package/dist/zip/zip-loader-types.js.map +1 -0
- package/dist/zip/zip-loader.cjs +2681 -0
- package/dist/zip/zip-loader.cjs.map +6 -0
- package/dist/zip/zip-loader.d.ts +3 -0
- package/dist/zip/zip-loader.d.ts.map +1 -0
- package/dist/zip/zip-loader.js +38 -0
- package/dist/zip/zip-loader.js.map +1 -0
- package/dist/zip/zip-writer.cjs +1208 -0
- package/dist/zip/zip-writer.cjs.map +6 -0
- package/dist/zip/zip-writer.d.ts +40 -0
- package/dist/zip/zip-writer.d.ts.map +1 -0
- package/dist/zip/zip-writer.js +48 -0
- package/dist/zip/zip-writer.js.map +1 -0
- package/package.json +88 -4
- package/src/index.ts +14 -0
- package/src/tar/index.ts +11 -0
- package/src/tar/lib/header.ts +82 -0
- package/src/tar/lib/tar.ts +160 -0
- package/src/tar/lib/types.ts +51 -0
- package/src/tar/lib/utils.ts +55 -0
- package/src/tar/tar-archive.ts +98 -0
- package/src/tar/tar-builder.ts +47 -0
- package/src/tar/tar-format.ts +17 -0
- package/src/tar/tar-loader-types.ts +36 -0
- package/src/tar/tar-loader.ts +17 -0
- package/src/tar/tar-writer.ts +102 -0
- package/src/zip/filesystems/IndexedArchive.ts +110 -0
- package/src/zip/filesystems/zip-filesystem.ts +244 -0
- package/src/zip/hash-file-utility.ts +109 -0
- package/src/zip/index.ts +38 -0
- package/src/zip/indexed-zip-writer.ts +345 -0
- package/src/zip/lib/zip-composition.ts +243 -0
- package/src/zip/lib/zip-entry-metadata.ts +157 -0
- package/src/zip/lib/zip-serialization.ts +206 -0
- package/src/zip/lib/zip64-extra-field.ts +84 -0
- package/src/zip/zip-archive-types.ts +64 -0
- package/src/zip/zip-archive.ts +733 -0
- package/src/zip/zip-encode-types.ts +53 -0
- package/src/zip/zip-encode.ts +370 -0
- package/src/zip/zip-format.ts +19 -0
- package/src/zip/zip-loader-types.ts +36 -0
- package/src/zip/zip-loader.ts +43 -0
- package/src/zip/zip-writer.ts +73 -0
|
@@ -0,0 +1,1154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// dist/zip/zip-encode.js
|
|
31
|
+
var zip_encode_exports = {};
|
|
32
|
+
__export(zip_encode_exports, {
|
|
33
|
+
encodeZip: () => encodeZip,
|
|
34
|
+
encodeZipInBatches: () => encodeZipInBatches
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(zip_encode_exports);
|
|
37
|
+
|
|
38
|
+
// ../core/src/loader-utils/lib/module-utils/js-module-utils.ts
|
|
39
|
+
function registerJSModules(modules) {
|
|
40
|
+
globalThis.loaders ||= {};
|
|
41
|
+
globalThis.loaders.modules ||= {};
|
|
42
|
+
Object.assign(globalThis.loaders.modules, modules);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// ../core/src/loader-utils/lib/binary-utils/array-buffer-utils.ts
|
|
46
|
+
function concatenateArrayBuffers(...sources) {
|
|
47
|
+
return concatenateArrayBuffersFromArray(sources);
|
|
48
|
+
}
|
|
49
|
+
function concatenateArrayBuffersFromArray(sources) {
|
|
50
|
+
const sourceArrays = sources.map(
|
|
51
|
+
(source2) => source2 instanceof ArrayBuffer ? new Uint8Array(source2) : source2
|
|
52
|
+
);
|
|
53
|
+
const byteLength = sourceArrays.reduce((length, typedArray) => length + typedArray.byteLength, 0);
|
|
54
|
+
const result = new Uint8Array(byteLength);
|
|
55
|
+
let offset = 0;
|
|
56
|
+
for (const sourceArray of sourceArrays) {
|
|
57
|
+
result.set(sourceArray, offset);
|
|
58
|
+
offset += sourceArray.byteLength;
|
|
59
|
+
}
|
|
60
|
+
return result.buffer;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// ../core/src/loader-utils/lib/iterators/async-iteration.ts
|
|
64
|
+
async function concatenateArrayBuffersAsync(asyncIterator) {
|
|
65
|
+
const arrayBuffers = [];
|
|
66
|
+
for await (const chunk of asyncIterator) {
|
|
67
|
+
arrayBuffers.push(copyToArrayBuffer(chunk));
|
|
68
|
+
}
|
|
69
|
+
return concatenateArrayBuffers(...arrayBuffers);
|
|
70
|
+
}
|
|
71
|
+
function copyToArrayBuffer(chunk) {
|
|
72
|
+
if (chunk instanceof ArrayBuffer) {
|
|
73
|
+
return chunk;
|
|
74
|
+
}
|
|
75
|
+
if (ArrayBuffer.isView(chunk)) {
|
|
76
|
+
const { buffer, byteOffset, byteLength } = chunk;
|
|
77
|
+
return copyFromBuffer(buffer, byteOffset, byteLength);
|
|
78
|
+
}
|
|
79
|
+
return copyFromBuffer(chunk);
|
|
80
|
+
}
|
|
81
|
+
function copyFromBuffer(buffer, byteOffset = 0, byteLength = buffer.byteLength - byteOffset) {
|
|
82
|
+
const view = new Uint8Array(buffer, byteOffset, byteLength);
|
|
83
|
+
const copy = new Uint8Array(view.length);
|
|
84
|
+
copy.set(view);
|
|
85
|
+
return copy.buffer;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// ../compression/src/lib/compression.ts
|
|
89
|
+
var CompressionTransform = class {
|
|
90
|
+
/** Preloads any dynamic libraries. May enable sync functions */
|
|
91
|
+
async preload(modules = {}) {
|
|
92
|
+
registerJSModules(modules);
|
|
93
|
+
return void 0;
|
|
94
|
+
}
|
|
95
|
+
// HELPERS
|
|
96
|
+
concatenate(asyncIterator) {
|
|
97
|
+
return concatenateArrayBuffersAsync(asyncIterator);
|
|
98
|
+
}
|
|
99
|
+
improveError(error) {
|
|
100
|
+
if (!error.message.includes(this.name)) {
|
|
101
|
+
error.message = `${this.name} ${error.message}`;
|
|
102
|
+
}
|
|
103
|
+
return error;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
var Compressor = class extends CompressionTransform {
|
|
107
|
+
constructor(options) {
|
|
108
|
+
super();
|
|
109
|
+
this.compressBatches = this.compressBatches.bind(this);
|
|
110
|
+
}
|
|
111
|
+
/** Asynchronously compresses data. */
|
|
112
|
+
async compress(input) {
|
|
113
|
+
await this.preload();
|
|
114
|
+
return this.compressSync(input);
|
|
115
|
+
}
|
|
116
|
+
/** Synchronously compresses data. */
|
|
117
|
+
compressSync(input) {
|
|
118
|
+
throw new Error(`${this.name}: sync compression not supported`);
|
|
119
|
+
}
|
|
120
|
+
/** Compresses batches. */
|
|
121
|
+
async *compressBatches(asyncIterator) {
|
|
122
|
+
const input = await this.concatenate(asyncIterator);
|
|
123
|
+
yield this.compress(input);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// ../compression/src/lib/compress-utils-compression.ts
|
|
128
|
+
var CompressUtilsCompressor = class extends Compressor {
|
|
129
|
+
name;
|
|
130
|
+
extensions;
|
|
131
|
+
contentEncodings;
|
|
132
|
+
isSupported = true;
|
|
133
|
+
options;
|
|
134
|
+
loadModule;
|
|
135
|
+
/** Module initialized for synchronous operations. */
|
|
136
|
+
module = null;
|
|
137
|
+
/** Shared import and WASM initialization for concurrent callers. */
|
|
138
|
+
modulePromise = null;
|
|
139
|
+
/** Creates a format-specific compress-utils encoder. */
|
|
140
|
+
constructor(metadata, loadModule, options = {}) {
|
|
141
|
+
super(options);
|
|
142
|
+
this.name = metadata.name;
|
|
143
|
+
this.extensions = metadata.extensions || [];
|
|
144
|
+
this.contentEncodings = metadata.contentEncodings || [];
|
|
145
|
+
this.loadModule = loadModule;
|
|
146
|
+
this.options = options;
|
|
147
|
+
}
|
|
148
|
+
/** Imports and initializes the codec without loading the opposite direction. */
|
|
149
|
+
async preload(modules = {}) {
|
|
150
|
+
await super.preload(modules);
|
|
151
|
+
this.modulePromise ||= this.loadModule().then(async (module2) => {
|
|
152
|
+
var _a;
|
|
153
|
+
await ((_a = module2.preload) == null ? void 0 : _a.call(module2));
|
|
154
|
+
this.module = module2;
|
|
155
|
+
});
|
|
156
|
+
try {
|
|
157
|
+
await this.modulePromise;
|
|
158
|
+
} catch (error) {
|
|
159
|
+
this.modulePromise = null;
|
|
160
|
+
throw error;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/** Runs synchronously after preload has initialized the WASM codec. */
|
|
164
|
+
compressSync(input) {
|
|
165
|
+
var _a;
|
|
166
|
+
if (!((_a = this.module) == null ? void 0 : _a.compressSync))
|
|
167
|
+
throw new Error(`${this.name}: call preload() before compressSync()`);
|
|
168
|
+
return copyArrayBuffer(
|
|
169
|
+
this.module.compressSync(new Uint8Array(input), this.options.compressUtils)
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
/** Compresses one buffer with the selected compress-utils encoder. */
|
|
173
|
+
async compress(input) {
|
|
174
|
+
await this.preload();
|
|
175
|
+
const module2 = this.module;
|
|
176
|
+
const output = await module2.compress(new Uint8Array(input), this.options.compressUtils);
|
|
177
|
+
return copyArrayBuffer(output);
|
|
178
|
+
}
|
|
179
|
+
/** Incrementally compresses input batches with compress-utils. */
|
|
180
|
+
async *compressBatches(inputBatches) {
|
|
181
|
+
await this.preload();
|
|
182
|
+
const module2 = this.module;
|
|
183
|
+
if (!module2.createCompressStream) {
|
|
184
|
+
yield await this.compress(await this.concatenate(inputBatches));
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
const stream = await module2.createCompressStream(this.options.compressUtils);
|
|
188
|
+
yield* transformBatches(stream, inputBatches);
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
async function* transformBatches(stream, inputBatches, maximumOutputByteLength = Number.POSITIVE_INFINITY) {
|
|
192
|
+
let outputByteLength = 0;
|
|
193
|
+
try {
|
|
194
|
+
for await (const input of inputBatches) {
|
|
195
|
+
const output2 = stream.write(new Uint8Array(input));
|
|
196
|
+
if (output2.byteLength > maximumOutputByteLength - outputByteLength)
|
|
197
|
+
throw new RangeError("Decompressed output exceeds maxOutputByteLength");
|
|
198
|
+
outputByteLength += output2.byteLength;
|
|
199
|
+
if (output2.byteLength > 0) yield copyArrayBuffer(output2);
|
|
200
|
+
}
|
|
201
|
+
const output = stream.finish();
|
|
202
|
+
if (output.byteLength > maximumOutputByteLength - outputByteLength)
|
|
203
|
+
throw new RangeError("Decompressed output exceeds maxOutputByteLength");
|
|
204
|
+
if (output.byteLength > 0) yield copyArrayBuffer(output);
|
|
205
|
+
} finally {
|
|
206
|
+
stream.destroy();
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
function copyArrayBuffer(bytes) {
|
|
210
|
+
return bytes.slice().buffer;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// ../compression/src/deflate-compressor-compress-utils.ts
|
|
214
|
+
var DeflateCompressUtilsCompressor = class extends CompressUtilsCompressor {
|
|
215
|
+
constructor(options = {}) {
|
|
216
|
+
super(
|
|
217
|
+
{ name: "deflate", contentEncodings: ["deflate"] },
|
|
218
|
+
() => options.raw ? import("compress-utils/deflate/compress") : import("compress-utils/zlib/compress"),
|
|
219
|
+
options
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
// ../compression/src/lib/compression-stream.ts
|
|
225
|
+
async function compressWithNativeCompressionStream(input, format) {
|
|
226
|
+
const outputBatches = compressBatchesWithNativeCompressionStream([input], format);
|
|
227
|
+
return outputBatches ? await concatenateBatches(outputBatches) : null;
|
|
228
|
+
}
|
|
229
|
+
function compressBatchesWithNativeCompressionStream(inputBatches, format) {
|
|
230
|
+
const compressionStream = createNativeCompressionStream(format);
|
|
231
|
+
return compressionStream ? transformBatches2(inputBatches, compressionStream) : null;
|
|
232
|
+
}
|
|
233
|
+
function createNativeCompressionStream(format) {
|
|
234
|
+
if (typeof globalThis.CompressionStream === "undefined") {
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
try {
|
|
238
|
+
const CompressionStreamConstructor = globalThis.CompressionStream;
|
|
239
|
+
return new CompressionStreamConstructor(format);
|
|
240
|
+
} catch (error) {
|
|
241
|
+
if (error instanceof TypeError || (error == null ? void 0 : error.name) === "TypeError") {
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
throw error;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
async function* transformBatches2(inputBatches, compressionStream) {
|
|
248
|
+
const writer = compressionStream.writable.getWriter();
|
|
249
|
+
const reader = compressionStream.readable.getReader();
|
|
250
|
+
const writePromise = writeBatches(inputBatches, writer);
|
|
251
|
+
writePromise.catch(() => {
|
|
252
|
+
});
|
|
253
|
+
let outputCompleted = false;
|
|
254
|
+
try {
|
|
255
|
+
while (true) {
|
|
256
|
+
const { done, value } = await reader.read();
|
|
257
|
+
if (done) {
|
|
258
|
+
outputCompleted = true;
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
yield new Uint8Array(value).buffer;
|
|
262
|
+
}
|
|
263
|
+
await writePromise;
|
|
264
|
+
} finally {
|
|
265
|
+
if (!outputCompleted) {
|
|
266
|
+
await reader.cancel().catch(() => {
|
|
267
|
+
});
|
|
268
|
+
await writer.abort().catch(() => {
|
|
269
|
+
});
|
|
270
|
+
await writePromise.catch(() => {
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
reader.releaseLock();
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
async function writeBatches(inputBatches, writer) {
|
|
277
|
+
try {
|
|
278
|
+
for await (const inputBatch of inputBatches) {
|
|
279
|
+
await writer.write(new Uint8Array(inputBatch));
|
|
280
|
+
}
|
|
281
|
+
await writer.close();
|
|
282
|
+
} catch (error) {
|
|
283
|
+
await writer.abort(error).catch(() => {
|
|
284
|
+
});
|
|
285
|
+
throw error;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
async function concatenateBatches(batches) {
|
|
289
|
+
const output = [];
|
|
290
|
+
let byteLength = 0;
|
|
291
|
+
for await (const batch of batches) {
|
|
292
|
+
const bytes = new Uint8Array(batch);
|
|
293
|
+
output.push(bytes);
|
|
294
|
+
byteLength += bytes.byteLength;
|
|
295
|
+
}
|
|
296
|
+
const result = new Uint8Array(byteLength);
|
|
297
|
+
let offset = 0;
|
|
298
|
+
for (const batch of output) {
|
|
299
|
+
result.set(batch, offset);
|
|
300
|
+
offset += batch.byteLength;
|
|
301
|
+
}
|
|
302
|
+
return result.buffer;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// ../compression/src/deflate-compressor.ts
|
|
306
|
+
var DeflateCompressor = class extends DeflateCompressUtilsCompressor {
|
|
307
|
+
/** Compresses with native streams when available, otherwise lazily initializes WASM. */
|
|
308
|
+
async compress(input) {
|
|
309
|
+
if (this.options.useNative !== false && !this.options.raw) {
|
|
310
|
+
const output = await compressWithNativeCompressionStream(input, "deflate");
|
|
311
|
+
if (output) return output;
|
|
312
|
+
}
|
|
313
|
+
return super.compress(input);
|
|
314
|
+
}
|
|
315
|
+
/** Streams native batches when available, otherwise uses the WASM stream. */
|
|
316
|
+
async *compressBatches(inputBatches) {
|
|
317
|
+
if (this.options.useNative !== false && !this.options.raw) {
|
|
318
|
+
const output = compressBatchesWithNativeCompressionStream(inputBatches, "deflate");
|
|
319
|
+
if (output) {
|
|
320
|
+
yield* output;
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
yield* super.compressBatches(inputBatches);
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
// ../crypto/src/lib/hash.ts
|
|
329
|
+
var Hash = class {
|
|
330
|
+
constructor(options = {}) {
|
|
331
|
+
this.hashBatches = this.hashBatches.bind(this);
|
|
332
|
+
}
|
|
333
|
+
async preload() {
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
async *hashBatches(asyncIterator, encoding = "base64") {
|
|
337
|
+
var _a, _b;
|
|
338
|
+
const arrayBuffers = [];
|
|
339
|
+
for await (const arrayBuffer of asyncIterator) {
|
|
340
|
+
arrayBuffers.push(arrayBuffer);
|
|
341
|
+
yield arrayBuffer;
|
|
342
|
+
}
|
|
343
|
+
const output = await this.concatenate(arrayBuffers);
|
|
344
|
+
const hash = await this.hash(output, encoding);
|
|
345
|
+
(_b = (_a = this.options.crypto) == null ? void 0 : _a.onEnd) == null ? void 0 : _b.call(_a, { hash });
|
|
346
|
+
}
|
|
347
|
+
// HELPERS
|
|
348
|
+
async concatenate(asyncIterator) {
|
|
349
|
+
return await concatenateArrayBuffersAsync(asyncIterator);
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
// ../crypto/src/lib/algorithms/crc32.ts
|
|
354
|
+
var CRC32 = class {
|
|
355
|
+
crc;
|
|
356
|
+
constructor() {
|
|
357
|
+
this.crc = ~0;
|
|
358
|
+
}
|
|
359
|
+
update(arrayBuffer) {
|
|
360
|
+
const CRC32_TABLE = getCRC32Table();
|
|
361
|
+
const byteArray = new Uint8Array(arrayBuffer);
|
|
362
|
+
for (let i = 0; i < byteArray.byteLength; i++) {
|
|
363
|
+
this.crc = this.crc >>> 8 ^ CRC32_TABLE[(this.crc ^ byteArray[i]) & 255];
|
|
364
|
+
}
|
|
365
|
+
return this;
|
|
366
|
+
}
|
|
367
|
+
finalize() {
|
|
368
|
+
this.crc = (this.crc ^ -1) >>> 0;
|
|
369
|
+
return this.crc;
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
var CRC32TAB = Uint32Array.of(
|
|
373
|
+
0,
|
|
374
|
+
1996959894,
|
|
375
|
+
3993919788,
|
|
376
|
+
2567524794,
|
|
377
|
+
124634137,
|
|
378
|
+
1886057615,
|
|
379
|
+
3915621685,
|
|
380
|
+
2657392035,
|
|
381
|
+
249268274,
|
|
382
|
+
2044508324,
|
|
383
|
+
3772115230,
|
|
384
|
+
2547177864,
|
|
385
|
+
162941995,
|
|
386
|
+
2125561021,
|
|
387
|
+
3887607047,
|
|
388
|
+
2428444049,
|
|
389
|
+
498536548,
|
|
390
|
+
1789927666,
|
|
391
|
+
4089016648,
|
|
392
|
+
2227061214,
|
|
393
|
+
450548861,
|
|
394
|
+
1843258603,
|
|
395
|
+
4107580753,
|
|
396
|
+
2211677639,
|
|
397
|
+
325883990,
|
|
398
|
+
1684777152,
|
|
399
|
+
4251122042,
|
|
400
|
+
2321926636,
|
|
401
|
+
335633487,
|
|
402
|
+
1661365465,
|
|
403
|
+
4195302755,
|
|
404
|
+
2366115317,
|
|
405
|
+
997073096,
|
|
406
|
+
1281953886,
|
|
407
|
+
3579855332,
|
|
408
|
+
2724688242,
|
|
409
|
+
1006888145,
|
|
410
|
+
1258607687,
|
|
411
|
+
3524101629,
|
|
412
|
+
2768942443,
|
|
413
|
+
901097722,
|
|
414
|
+
1119000684,
|
|
415
|
+
3686517206,
|
|
416
|
+
2898065728,
|
|
417
|
+
853044451,
|
|
418
|
+
1172266101,
|
|
419
|
+
3705015759,
|
|
420
|
+
2882616665,
|
|
421
|
+
651767980,
|
|
422
|
+
1373503546,
|
|
423
|
+
3369554304,
|
|
424
|
+
3218104598,
|
|
425
|
+
565507253,
|
|
426
|
+
1454621731,
|
|
427
|
+
3485111705,
|
|
428
|
+
3099436303,
|
|
429
|
+
671266974,
|
|
430
|
+
1594198024,
|
|
431
|
+
3322730930,
|
|
432
|
+
2970347812,
|
|
433
|
+
795835527,
|
|
434
|
+
1483230225,
|
|
435
|
+
3244367275,
|
|
436
|
+
3060149565,
|
|
437
|
+
1994146192,
|
|
438
|
+
31158534,
|
|
439
|
+
2563907772,
|
|
440
|
+
4023717930,
|
|
441
|
+
1907459465,
|
|
442
|
+
112637215,
|
|
443
|
+
2680153253,
|
|
444
|
+
3904427059,
|
|
445
|
+
2013776290,
|
|
446
|
+
251722036,
|
|
447
|
+
2517215374,
|
|
448
|
+
3775830040,
|
|
449
|
+
2137656763,
|
|
450
|
+
141376813,
|
|
451
|
+
2439277719,
|
|
452
|
+
3865271297,
|
|
453
|
+
1802195444,
|
|
454
|
+
476864866,
|
|
455
|
+
2238001368,
|
|
456
|
+
4066508878,
|
|
457
|
+
1812370925,
|
|
458
|
+
453092731,
|
|
459
|
+
2181625025,
|
|
460
|
+
4111451223,
|
|
461
|
+
1706088902,
|
|
462
|
+
314042704,
|
|
463
|
+
2344532202,
|
|
464
|
+
4240017532,
|
|
465
|
+
1658658271,
|
|
466
|
+
366619977,
|
|
467
|
+
2362670323,
|
|
468
|
+
4224994405,
|
|
469
|
+
1303535960,
|
|
470
|
+
984961486,
|
|
471
|
+
2747007092,
|
|
472
|
+
3569037538,
|
|
473
|
+
1256170817,
|
|
474
|
+
1037604311,
|
|
475
|
+
2765210733,
|
|
476
|
+
3554079995,
|
|
477
|
+
1131014506,
|
|
478
|
+
879679996,
|
|
479
|
+
2909243462,
|
|
480
|
+
3663771856,
|
|
481
|
+
1141124467,
|
|
482
|
+
855842277,
|
|
483
|
+
2852801631,
|
|
484
|
+
3708648649,
|
|
485
|
+
1342533948,
|
|
486
|
+
654459306,
|
|
487
|
+
3188396048,
|
|
488
|
+
3373015174,
|
|
489
|
+
1466479909,
|
|
490
|
+
544179635,
|
|
491
|
+
3110523913,
|
|
492
|
+
3462522015,
|
|
493
|
+
1591671054,
|
|
494
|
+
702138776,
|
|
495
|
+
2966460450,
|
|
496
|
+
3352799412,
|
|
497
|
+
1504918807,
|
|
498
|
+
783551873,
|
|
499
|
+
3082640443,
|
|
500
|
+
3233442989,
|
|
501
|
+
3988292384,
|
|
502
|
+
2596254646,
|
|
503
|
+
62317068,
|
|
504
|
+
1957810842,
|
|
505
|
+
3939845945,
|
|
506
|
+
2647816111,
|
|
507
|
+
81470997,
|
|
508
|
+
1943803523,
|
|
509
|
+
3814918930,
|
|
510
|
+
2489596804,
|
|
511
|
+
225274430,
|
|
512
|
+
2053790376,
|
|
513
|
+
3826175755,
|
|
514
|
+
2466906013,
|
|
515
|
+
167816743,
|
|
516
|
+
2097651377,
|
|
517
|
+
4027552580,
|
|
518
|
+
2265490386,
|
|
519
|
+
503444072,
|
|
520
|
+
1762050814,
|
|
521
|
+
4150417245,
|
|
522
|
+
2154129355,
|
|
523
|
+
426522225,
|
|
524
|
+
1852507879,
|
|
525
|
+
4275313526,
|
|
526
|
+
2312317920,
|
|
527
|
+
282753626,
|
|
528
|
+
1742555852,
|
|
529
|
+
4189708143,
|
|
530
|
+
2394877945,
|
|
531
|
+
397917763,
|
|
532
|
+
1622183637,
|
|
533
|
+
3604390888,
|
|
534
|
+
2714866558,
|
|
535
|
+
953729732,
|
|
536
|
+
1340076626,
|
|
537
|
+
3518719985,
|
|
538
|
+
2797360999,
|
|
539
|
+
1068828381,
|
|
540
|
+
1219638859,
|
|
541
|
+
3624741850,
|
|
542
|
+
2936675148,
|
|
543
|
+
906185462,
|
|
544
|
+
1090812512,
|
|
545
|
+
3747672003,
|
|
546
|
+
2825379669,
|
|
547
|
+
829329135,
|
|
548
|
+
1181335161,
|
|
549
|
+
3412177804,
|
|
550
|
+
3160834842,
|
|
551
|
+
628085408,
|
|
552
|
+
1382605366,
|
|
553
|
+
3423369109,
|
|
554
|
+
3138078467,
|
|
555
|
+
570562233,
|
|
556
|
+
1426400815,
|
|
557
|
+
3317316542,
|
|
558
|
+
2998733608,
|
|
559
|
+
733239954,
|
|
560
|
+
1555261956,
|
|
561
|
+
3268935591,
|
|
562
|
+
3050360625,
|
|
563
|
+
752459403,
|
|
564
|
+
1541320221,
|
|
565
|
+
2607071920,
|
|
566
|
+
3965973030,
|
|
567
|
+
1969922972,
|
|
568
|
+
40735498,
|
|
569
|
+
2617837225,
|
|
570
|
+
3943577151,
|
|
571
|
+
1913087877,
|
|
572
|
+
83908371,
|
|
573
|
+
2512341634,
|
|
574
|
+
3803740692,
|
|
575
|
+
2075208622,
|
|
576
|
+
213261112,
|
|
577
|
+
2463272603,
|
|
578
|
+
3855990285,
|
|
579
|
+
2094854071,
|
|
580
|
+
198958881,
|
|
581
|
+
2262029012,
|
|
582
|
+
4057260610,
|
|
583
|
+
1759359992,
|
|
584
|
+
534414190,
|
|
585
|
+
2176718541,
|
|
586
|
+
4139329115,
|
|
587
|
+
1873836001,
|
|
588
|
+
414664567,
|
|
589
|
+
2282248934,
|
|
590
|
+
4279200368,
|
|
591
|
+
1711684554,
|
|
592
|
+
285281116,
|
|
593
|
+
2405801727,
|
|
594
|
+
4167216745,
|
|
595
|
+
1634467795,
|
|
596
|
+
376229701,
|
|
597
|
+
2685067896,
|
|
598
|
+
3608007406,
|
|
599
|
+
1308918612,
|
|
600
|
+
956543938,
|
|
601
|
+
2808555105,
|
|
602
|
+
3495958263,
|
|
603
|
+
1231636301,
|
|
604
|
+
1047427035,
|
|
605
|
+
2932959818,
|
|
606
|
+
3654703836,
|
|
607
|
+
1088359270,
|
|
608
|
+
936918e3,
|
|
609
|
+
2847714899,
|
|
610
|
+
3736837829,
|
|
611
|
+
1202900863,
|
|
612
|
+
817233897,
|
|
613
|
+
3183342108,
|
|
614
|
+
3401237130,
|
|
615
|
+
1404277552,
|
|
616
|
+
615818150,
|
|
617
|
+
3134207493,
|
|
618
|
+
3453421203,
|
|
619
|
+
1423857449,
|
|
620
|
+
601450431,
|
|
621
|
+
3009837614,
|
|
622
|
+
3294710456,
|
|
623
|
+
1567103746,
|
|
624
|
+
711928724,
|
|
625
|
+
3020668471,
|
|
626
|
+
3272380065,
|
|
627
|
+
1510334235,
|
|
628
|
+
755167117
|
|
629
|
+
);
|
|
630
|
+
function getCRC32Table() {
|
|
631
|
+
return CRC32TAB;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
// ../crypto/src/lib/utils/base64-utils.ts
|
|
635
|
+
function asciiToBase64(string) {
|
|
636
|
+
string = `${string}`;
|
|
637
|
+
for (let i = 0; i < string.length; i++) {
|
|
638
|
+
if (string.charCodeAt(i) > 255) {
|
|
639
|
+
return null;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
let out = "";
|
|
643
|
+
for (let i = 0; i < string.length; i += 3) {
|
|
644
|
+
const groupsOfSix = [void 0, void 0, void 0, void 0];
|
|
645
|
+
groupsOfSix[0] = string.charCodeAt(i) >> 2;
|
|
646
|
+
groupsOfSix[1] = (string.charCodeAt(i) & 3) << 4;
|
|
647
|
+
if (string.length > i + 1) {
|
|
648
|
+
groupsOfSix[1] |= string.charCodeAt(i + 1) >> 4;
|
|
649
|
+
groupsOfSix[2] = (string.charCodeAt(i + 1) & 15) << 2;
|
|
650
|
+
}
|
|
651
|
+
if (string.length > i + 2) {
|
|
652
|
+
groupsOfSix[2] |= string.charCodeAt(i + 2) >> 6;
|
|
653
|
+
groupsOfSix[3] = string.charCodeAt(i + 2) & 63;
|
|
654
|
+
}
|
|
655
|
+
for (let j = 0; j < groupsOfSix.length; j++) {
|
|
656
|
+
if (typeof groupsOfSix[j] === "undefined") {
|
|
657
|
+
out += "=";
|
|
658
|
+
} else {
|
|
659
|
+
out += btoaLookup(groupsOfSix[j]);
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
return out;
|
|
664
|
+
}
|
|
665
|
+
function btoaLookup(idx) {
|
|
666
|
+
if (idx < 26) {
|
|
667
|
+
return String.fromCharCode(idx + "A".charCodeAt(0));
|
|
668
|
+
}
|
|
669
|
+
if (idx < 52) {
|
|
670
|
+
return String.fromCharCode(idx - 26 + "a".charCodeAt(0));
|
|
671
|
+
}
|
|
672
|
+
if (idx < 62) {
|
|
673
|
+
return String.fromCharCode(idx - 52 + "0".charCodeAt(0));
|
|
674
|
+
}
|
|
675
|
+
if (idx === 62) {
|
|
676
|
+
return "+";
|
|
677
|
+
}
|
|
678
|
+
if (idx === 63) {
|
|
679
|
+
return "/";
|
|
680
|
+
}
|
|
681
|
+
return void 0;
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
// ../crypto/src/lib/utils/digest-utils.ts
|
|
685
|
+
function encodeNumber(number, encoding) {
|
|
686
|
+
switch (encoding) {
|
|
687
|
+
case "hex":
|
|
688
|
+
return convertNumberToHex(number);
|
|
689
|
+
case "base64":
|
|
690
|
+
return convertHexToBase64(convertNumberToHex(number));
|
|
691
|
+
default:
|
|
692
|
+
throw new Error(encoding);
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
function convertHexToBase64(hexstring) {
|
|
696
|
+
if (hexstring.length % 2 !== 0) {
|
|
697
|
+
hexstring = `0${hexstring}`;
|
|
698
|
+
}
|
|
699
|
+
const matches = hexstring.match(/\w{2}/g) || [];
|
|
700
|
+
const string = matches.map((a) => String.fromCharCode(parseInt(a, 16))).join("");
|
|
701
|
+
return asciiToBase64(string) || "";
|
|
702
|
+
}
|
|
703
|
+
function convertNumberToHex(cipher) {
|
|
704
|
+
const hexString = cipher.toString(16);
|
|
705
|
+
return hexString === "0" ? `0${hexString}` : hexString;
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
// ../crypto/src/lib/crc32-hash.ts
|
|
709
|
+
var CRC32Hash = class extends Hash {
|
|
710
|
+
name = "crc32";
|
|
711
|
+
options;
|
|
712
|
+
constructor(options = {}) {
|
|
713
|
+
super();
|
|
714
|
+
this.options = { crypto: {}, ...options };
|
|
715
|
+
this.hashBatches = this.hashBatches.bind(this);
|
|
716
|
+
}
|
|
717
|
+
/**
|
|
718
|
+
* Atomic hash calculation
|
|
719
|
+
* @returns base64 encoded hash
|
|
720
|
+
*/
|
|
721
|
+
async hash(input, encoding) {
|
|
722
|
+
return this.hashSync(input, encoding);
|
|
723
|
+
}
|
|
724
|
+
hashSync(input, encoding) {
|
|
725
|
+
const hash = new CRC32();
|
|
726
|
+
hash.update(input);
|
|
727
|
+
const digest = hash.finalize();
|
|
728
|
+
return encodeNumber(digest, encoding);
|
|
729
|
+
}
|
|
730
|
+
async *hashBatches(asyncIterator, encoding = "base64") {
|
|
731
|
+
var _a, _b;
|
|
732
|
+
const hash = new CRC32();
|
|
733
|
+
for await (const chunk of asyncIterator) {
|
|
734
|
+
hash.update(chunk);
|
|
735
|
+
yield chunk;
|
|
736
|
+
}
|
|
737
|
+
const digest = hash.finalize();
|
|
738
|
+
(_b = (_a = this.options.crypto) == null ? void 0 : _a.onEnd) == null ? void 0 : _b.call(_a, { hash: encodeNumber(digest, encoding) });
|
|
739
|
+
}
|
|
740
|
+
};
|
|
741
|
+
|
|
742
|
+
// dist/zip/lib/zip-entry-metadata.js
|
|
743
|
+
var CP437_HIGH = "\xC7\xFC\xE9\xE2\xE4\xE0\xE5\xE7\xEA\xEB\xE8\xEF\xEE\xEC\xC4\xC5\xC9\xE6\xC6\xF4\xF6\xF2\xFB\xF9\xFF\xD6\xDC\xA2\xA3\xA5\u20A7\u0192\xE1\xED\xF3\xFA\xF1\xD1\xAA\xBA\xBF\u2310\xAC\xBD\xBC\xA1\xAB\xBB\u2591\u2592\u2593\u2502\u2524\u2561\u2562\u2556\u2555\u2563\u2551\u2557\u255D\u255C\u255B\u2510\u2514\u2534\u252C\u251C\u2500\u253C\u255E\u255F\u255A\u2554\u2569\u2566\u2560\u2550\u256C\u2567\u2568\u2564\u2565\u2559\u2558\u2552\u2553\u256B\u256A\u2518\u250C\u2588\u2584\u258C\u2590\u2580\u03B1\xDF\u0393\u03C0\u03A3\u03C3\xB5\u03C4\u03A6\u0398\u03A9\u03B4\u221E\u03C6\u03B5\u2229\u2261\xB1\u2265\u2264\u2320\u2321\xF7\u2248\xB0\u2219\xB7\u221A\u207F\xB2\u25A0\xA0";
|
|
744
|
+
function decodeZipText(bytes, utf8) {
|
|
745
|
+
if (utf8)
|
|
746
|
+
return new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(bytes);
|
|
747
|
+
return Array.from(bytes, (value) => value < 128 ? String.fromCharCode(value) : CP437_HIGH[value - 128]).join("");
|
|
748
|
+
}
|
|
749
|
+
function validateZipPath(path) {
|
|
750
|
+
const segments = path.endsWith("/") ? path.slice(0, -1).split("/") : path.split("/");
|
|
751
|
+
if (!path || path.includes("\\") || path.includes("\0") || /^[A-Za-z]:/.test(path) || segments.some((segment) => !segment || segment === "." || segment === ".."))
|
|
752
|
+
throw new Error("Invalid ZIP archive: noncanonical relative path");
|
|
753
|
+
}
|
|
754
|
+
function encodeUtf8Text(value) {
|
|
755
|
+
const bytes = new TextEncoder().encode(value);
|
|
756
|
+
if (new TextDecoder("utf-8", { ignoreBOM: true }).decode(bytes) !== value)
|
|
757
|
+
throw new TypeError("ZIP names and entry comments must be well-formed Unicode");
|
|
758
|
+
return bytes;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
// dist/zip/lib/zip-serialization.js
|
|
762
|
+
var ZIP32_SENTINEL = 0xffffffffn;
|
|
763
|
+
function encodeZipLocalHeader(entry) {
|
|
764
|
+
validateHeaderEntry(entry);
|
|
765
|
+
const bytes = new Uint8Array(30 + entry.nameBytes.length + (entry.zip64 ? 20 : 0));
|
|
766
|
+
const view = new DataView(bytes.buffer);
|
|
767
|
+
view.setUint32(0, 67324752, true);
|
|
768
|
+
view.setUint16(4, getZipVersion(entry), true);
|
|
769
|
+
view.setUint16(6, entry.flags, true);
|
|
770
|
+
view.setUint16(8, entry.method, true);
|
|
771
|
+
view.setUint32(10, encodeZipTimestamp(entry.date), true);
|
|
772
|
+
const descriptor = Boolean(entry.flags & 8);
|
|
773
|
+
view.setUint32(14, descriptor ? 0 : entry.crc32, true);
|
|
774
|
+
view.setUint32(18, entry.zip64 ? Number(ZIP32_SENTINEL) : descriptor ? 0 : Number(entry.compressedSize), true);
|
|
775
|
+
view.setUint32(22, entry.zip64 ? Number(ZIP32_SENTINEL) : descriptor ? 0 : Number(entry.size), true);
|
|
776
|
+
view.setUint16(26, entry.nameBytes.length, true);
|
|
777
|
+
view.setUint16(28, entry.zip64 ? 20 : 0, true);
|
|
778
|
+
bytes.set(entry.nameBytes, 30);
|
|
779
|
+
if (entry.zip64) {
|
|
780
|
+
const extraOffset = 30 + entry.nameBytes.length;
|
|
781
|
+
view.setUint16(extraOffset, 1, true);
|
|
782
|
+
view.setUint16(extraOffset + 2, 16, true);
|
|
783
|
+
view.setBigUint64(extraOffset + 4, descriptor ? 0n : entry.size, true);
|
|
784
|
+
view.setBigUint64(extraOffset + 12, descriptor ? 0n : entry.compressedSize, true);
|
|
785
|
+
}
|
|
786
|
+
return bytes;
|
|
787
|
+
}
|
|
788
|
+
function encodeZipCentralHeader(entry) {
|
|
789
|
+
validateHeaderEntry(entry);
|
|
790
|
+
const comment = entry.commentBytes ?? new Uint8Array();
|
|
791
|
+
const extraBytes = entry.zip64 ? 28 : 0;
|
|
792
|
+
const bytes = new Uint8Array(46 + entry.nameBytes.length + extraBytes + comment.length);
|
|
793
|
+
const view = new DataView(bytes.buffer);
|
|
794
|
+
view.setUint32(0, 33639248, true);
|
|
795
|
+
view.setUint16(4, entry.zip64 ? 45 : 20, true);
|
|
796
|
+
view.setUint16(6, getZipVersion(entry), true);
|
|
797
|
+
view.setUint16(8, entry.flags, true);
|
|
798
|
+
view.setUint16(10, entry.method, true);
|
|
799
|
+
view.setUint32(12, encodeZipTimestamp(entry.date), true);
|
|
800
|
+
view.setUint32(16, entry.crc32, true);
|
|
801
|
+
view.setUint32(20, entry.zip64 ? Number(ZIP32_SENTINEL) : Number(entry.compressedSize), true);
|
|
802
|
+
view.setUint32(24, entry.zip64 ? Number(ZIP32_SENTINEL) : Number(entry.size), true);
|
|
803
|
+
view.setUint16(28, entry.nameBytes.length, true);
|
|
804
|
+
view.setUint16(30, extraBytes, true);
|
|
805
|
+
view.setUint16(32, comment.length, true);
|
|
806
|
+
view.setUint32(38, entry.directory ? 16 : 0, true);
|
|
807
|
+
view.setUint32(42, entry.zip64 ? Number(ZIP32_SENTINEL) : Number(entry.localHeaderOffset), true);
|
|
808
|
+
bytes.set(entry.nameBytes, 46);
|
|
809
|
+
if (entry.zip64) {
|
|
810
|
+
const extraOffset = 46 + entry.nameBytes.length;
|
|
811
|
+
view.setUint16(extraOffset, 1, true);
|
|
812
|
+
view.setUint16(extraOffset + 2, 24, true);
|
|
813
|
+
view.setBigUint64(extraOffset + 4, entry.size, true);
|
|
814
|
+
view.setBigUint64(extraOffset + 12, entry.compressedSize, true);
|
|
815
|
+
view.setBigUint64(extraOffset + 20, entry.localHeaderOffset, true);
|
|
816
|
+
}
|
|
817
|
+
bytes.set(comment, 46 + entry.nameBytes.length + extraBytes);
|
|
818
|
+
return bytes;
|
|
819
|
+
}
|
|
820
|
+
function encodeZipDescriptor(entry) {
|
|
821
|
+
validateHeaderEntry(entry);
|
|
822
|
+
const bytes = new Uint8Array(entry.zip64 ? 24 : 16);
|
|
823
|
+
const view = new DataView(bytes.buffer);
|
|
824
|
+
view.setUint32(0, 134695760, true);
|
|
825
|
+
view.setUint32(4, entry.crc32, true);
|
|
826
|
+
if (entry.zip64) {
|
|
827
|
+
view.setBigUint64(8, entry.compressedSize, true);
|
|
828
|
+
view.setBigUint64(16, entry.size, true);
|
|
829
|
+
} else {
|
|
830
|
+
view.setUint32(8, Number(entry.compressedSize), true);
|
|
831
|
+
view.setUint32(12, Number(entry.size), true);
|
|
832
|
+
}
|
|
833
|
+
return bytes;
|
|
834
|
+
}
|
|
835
|
+
function encodeZipEndRecords(count, directorySize, directoryOffset, zip64, comment = new Uint8Array()) {
|
|
836
|
+
for (const value of [count, directorySize, directoryOffset, directoryOffset + directorySize])
|
|
837
|
+
validateUint64(value);
|
|
838
|
+
if (comment.length > 65535)
|
|
839
|
+
throw new RangeError("ZIP archive comment exceeds 65535 bytes");
|
|
840
|
+
if (!zip64 && (count > 0xffffn || directorySize >= ZIP32_SENTINEL || directoryOffset >= ZIP32_SENTINEL))
|
|
841
|
+
throw new RangeError("ZIP32 end record capacity exceeded");
|
|
842
|
+
const bytes = new Uint8Array((zip64 ? 98 : 22) + comment.length);
|
|
843
|
+
const view = new DataView(bytes.buffer);
|
|
844
|
+
if (zip64) {
|
|
845
|
+
view.setUint32(0, 101075792, true);
|
|
846
|
+
view.setBigUint64(4, 44n, true);
|
|
847
|
+
view.setUint16(12, 45, true);
|
|
848
|
+
view.setUint16(14, 45, true);
|
|
849
|
+
view.setBigUint64(24, count, true);
|
|
850
|
+
view.setBigUint64(32, count, true);
|
|
851
|
+
view.setBigUint64(40, directorySize, true);
|
|
852
|
+
view.setBigUint64(48, directoryOffset, true);
|
|
853
|
+
view.setUint32(56, 117853008, true);
|
|
854
|
+
view.setBigUint64(64, directoryOffset + directorySize, true);
|
|
855
|
+
view.setUint32(72, 1, true);
|
|
856
|
+
}
|
|
857
|
+
const endOffset = zip64 ? 76 : 0;
|
|
858
|
+
view.setUint32(endOffset, 101010256, true);
|
|
859
|
+
view.setUint16(endOffset + 8, zip64 ? 65535 : Number(count), true);
|
|
860
|
+
view.setUint16(endOffset + 10, zip64 ? 65535 : Number(count), true);
|
|
861
|
+
view.setUint32(endOffset + 12, zip64 ? Number(ZIP32_SENTINEL) : Number(directorySize), true);
|
|
862
|
+
view.setUint32(endOffset + 16, zip64 ? Number(ZIP32_SENTINEL) : Number(directoryOffset), true);
|
|
863
|
+
view.setUint16(endOffset + 20, comment.length, true);
|
|
864
|
+
bytes.set(comment, endOffset + 22);
|
|
865
|
+
return bytes;
|
|
866
|
+
}
|
|
867
|
+
function encodeZipTimestamp(date) {
|
|
868
|
+
if (!(date instanceof Date) || !Number.isFinite(date.getTime()) || date.getUTCFullYear() < 1980 || date.getUTCFullYear() > 2107)
|
|
869
|
+
throw new RangeError("ZIP timestamp must be a valid UTC date in 1980\u20132107");
|
|
870
|
+
const time = date.getUTCHours() << 11 | date.getUTCMinutes() << 5 | Math.floor(date.getUTCSeconds() / 2);
|
|
871
|
+
const day = date.getUTCFullYear() - 1980 << 9 | date.getUTCMonth() + 1 << 5 | date.getUTCDate();
|
|
872
|
+
return (day << 16 | time) >>> 0;
|
|
873
|
+
}
|
|
874
|
+
function getZipVersion(entry) {
|
|
875
|
+
return entry.zip64 ? 45 : entry.method === 8 || entry.flags & 8 ? 20 : 10;
|
|
876
|
+
}
|
|
877
|
+
function validateHeaderEntry(entry) {
|
|
878
|
+
var _a;
|
|
879
|
+
if (!entry.nameBytes.length || entry.nameBytes.length > 65535 || (((_a = entry.commentBytes) == null ? void 0 : _a.length) ?? 0) > 65535)
|
|
880
|
+
throw new RangeError("ZIP name/comment exceeds header capacity");
|
|
881
|
+
for (const value of [entry.size, entry.compressedSize, entry.localHeaderOffset])
|
|
882
|
+
validateUint64(value);
|
|
883
|
+
if (!entry.zip64 && [entry.size, entry.compressedSize, entry.localHeaderOffset].some((value) => value >= ZIP32_SENTINEL))
|
|
884
|
+
throw new RangeError("ZIP32 entry capacity exceeded");
|
|
885
|
+
}
|
|
886
|
+
function validateUint64(value) {
|
|
887
|
+
if (typeof value !== "bigint" || value < 0n || value > 0xffffffffffffffffn)
|
|
888
|
+
throw new RangeError("ZIP64 unsigned integer capacity exceeded");
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
// dist/zip/zip-encode.js
|
|
892
|
+
var DEFAULT_OPTIONS = {
|
|
893
|
+
compression: "store",
|
|
894
|
+
zip64: "auto",
|
|
895
|
+
maxArchiveBytes: 1024n ** 4n,
|
|
896
|
+
maxEntryBytes: 1024n ** 4n,
|
|
897
|
+
maxDirectoryBytes: 32 * 1024 * 1024,
|
|
898
|
+
maxEntries: 1e5,
|
|
899
|
+
chunkBytes: 64 * 1024
|
|
900
|
+
};
|
|
901
|
+
async function encodeZip(files, options = {}) {
|
|
902
|
+
const chunks = [];
|
|
903
|
+
let size = 0;
|
|
904
|
+
for await (const chunk of encodeZipInBatches(files, options)) {
|
|
905
|
+
if (size + chunk.length > 4294967295)
|
|
906
|
+
throw new RangeError("ZIP buffer capacity exceeded; use encodeZipInBatches");
|
|
907
|
+
chunks.push(chunk);
|
|
908
|
+
size += chunk.length;
|
|
909
|
+
}
|
|
910
|
+
const output = new Uint8Array(size);
|
|
911
|
+
let offset = 0;
|
|
912
|
+
for (const chunk of chunks) {
|
|
913
|
+
output.set(chunk, offset);
|
|
914
|
+
offset += chunk.length;
|
|
915
|
+
}
|
|
916
|
+
return output.buffer;
|
|
917
|
+
}
|
|
918
|
+
async function* encodeZipInBatches(files, options = {}) {
|
|
919
|
+
const settings = {
|
|
920
|
+
compression: options.compression ?? DEFAULT_OPTIONS.compression,
|
|
921
|
+
zip64: options.zip64 ?? DEFAULT_OPTIONS.zip64,
|
|
922
|
+
maxArchiveBytes: options.maxArchiveBytes ?? DEFAULT_OPTIONS.maxArchiveBytes,
|
|
923
|
+
maxEntryBytes: options.maxEntryBytes ?? DEFAULT_OPTIONS.maxEntryBytes,
|
|
924
|
+
maxDirectoryBytes: options.maxDirectoryBytes ?? DEFAULT_OPTIONS.maxDirectoryBytes,
|
|
925
|
+
maxEntries: options.maxEntries ?? DEFAULT_OPTIONS.maxEntries,
|
|
926
|
+
chunkBytes: options.chunkBytes ?? DEFAULT_OPTIONS.chunkBytes
|
|
927
|
+
};
|
|
928
|
+
validateSettings(settings);
|
|
929
|
+
const signal = options.signal;
|
|
930
|
+
signal == null ? void 0 : signal.throwIfAborted();
|
|
931
|
+
const comment = encodeArchiveComment(options.comment ?? "");
|
|
932
|
+
const date = options.date ?? /* @__PURE__ */ new Date("1980-01-01T00:00:00Z");
|
|
933
|
+
encodeZipTimestamp(date);
|
|
934
|
+
const paths = Object.keys(files).sort();
|
|
935
|
+
if (paths.length > settings.maxEntries)
|
|
936
|
+
throw new RangeError("ZIP entry count limit exceeded");
|
|
937
|
+
if (settings.zip64 === "never" && paths.length > 65535)
|
|
938
|
+
throw new RangeError("ZIP32 entry count capacity exceeded");
|
|
939
|
+
let minimumDirectoryBytes = 0;
|
|
940
|
+
const entries = paths.map((path) => {
|
|
941
|
+
var _a;
|
|
942
|
+
validateZipPath(path);
|
|
943
|
+
const value = files[path];
|
|
944
|
+
const entry = value && typeof value === "object" && "data" in value ? value : { data: value };
|
|
945
|
+
const size = getSourceSize(entry.data);
|
|
946
|
+
const directory2 = path.endsWith("/");
|
|
947
|
+
const compression = entry.compression ?? settings.compression;
|
|
948
|
+
if (compression !== "store" && compression !== "deflate")
|
|
949
|
+
throw new TypeError("Unsupported ZIP compression");
|
|
950
|
+
if (size !== void 0 && (size > settings.maxEntryBytes || directory2 && size !== 0n))
|
|
951
|
+
throw new RangeError("ZIP entry byte limit or nonempty directory");
|
|
952
|
+
if (path.length > 65535 || (((_a = entry.comment) == null ? void 0 : _a.length) ?? 0) > 65535)
|
|
953
|
+
throw new RangeError("ZIP name/comment exceeds header capacity");
|
|
954
|
+
if (entry.comment !== void 0 && typeof entry.comment !== "string")
|
|
955
|
+
throw new TypeError("ZIP entry comment must be a string");
|
|
956
|
+
const nameBytes = encodeUtf8Text(path);
|
|
957
|
+
const commentBytes = encodeUtf8Text(entry.comment ?? "");
|
|
958
|
+
encodeZipTimestamp(entry.date ?? date);
|
|
959
|
+
const timestamp = new Date((entry.date ?? date).getTime());
|
|
960
|
+
const zip642 = settings.zip64 === "always" || settings.zip64 === "auto" && (size === void 0 || size >= 0xffffffffn || !directory2 && compression === "deflate");
|
|
961
|
+
const header = {
|
|
962
|
+
nameBytes,
|
|
963
|
+
commentBytes,
|
|
964
|
+
date: timestamp,
|
|
965
|
+
method: directory2 || compression === "store" ? 0 : 8,
|
|
966
|
+
flags: 2056,
|
|
967
|
+
crc32: 0,
|
|
968
|
+
size: size ?? 0n,
|
|
969
|
+
compressedSize: 0n,
|
|
970
|
+
localHeaderOffset: 0n,
|
|
971
|
+
zip64: zip642,
|
|
972
|
+
directory: directory2
|
|
973
|
+
};
|
|
974
|
+
encodeZipCentralHeader(header);
|
|
975
|
+
minimumDirectoryBytes += 46 + nameBytes.length + commentBytes.length + (zip642 ? 28 : 0);
|
|
976
|
+
if (minimumDirectoryBytes > settings.maxDirectoryBytes)
|
|
977
|
+
throw new RangeError("ZIP directory byte limit exceeded");
|
|
978
|
+
return { source: entry.data, size, header };
|
|
979
|
+
});
|
|
980
|
+
let outputBytes = 0n;
|
|
981
|
+
let directoryBytes = 0;
|
|
982
|
+
let usedZip64 = settings.zip64 === "always";
|
|
983
|
+
const directory = [];
|
|
984
|
+
function* emit(bytes) {
|
|
985
|
+
for (let offset = 0; offset < bytes.length; offset += settings.chunkBytes) {
|
|
986
|
+
signal == null ? void 0 : signal.throwIfAborted();
|
|
987
|
+
const chunk = bytes.slice(offset, offset + settings.chunkBytes);
|
|
988
|
+
if (outputBytes + BigInt(chunk.length) > settings.maxArchiveBytes)
|
|
989
|
+
throw new RangeError("ZIP archive output byte limit exceeded");
|
|
990
|
+
outputBytes += BigInt(chunk.length);
|
|
991
|
+
yield chunk;
|
|
992
|
+
signal == null ? void 0 : signal.throwIfAborted();
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
for (const entry of entries) {
|
|
996
|
+
signal == null ? void 0 : signal.throwIfAborted();
|
|
997
|
+
const zip642 = entry.header.zip64 || settings.zip64 === "auto" && outputBytes >= 0xffffffffn;
|
|
998
|
+
const header = { ...entry.header, localHeaderOffset: outputBytes, zip64: zip642 };
|
|
999
|
+
usedZip64 ||= zip642;
|
|
1000
|
+
yield* emit(encodeZipLocalHeader(header));
|
|
1001
|
+
let size = 0n;
|
|
1002
|
+
let compressedSize = 0n;
|
|
1003
|
+
let checksum = 0;
|
|
1004
|
+
async function* measuredInput() {
|
|
1005
|
+
for await (const block of readSource(entry.source, settings.chunkBytes, signal)) {
|
|
1006
|
+
size += BigInt(block.byteLength);
|
|
1007
|
+
if (size > settings.maxEntryBytes || header.directory && size !== 0n)
|
|
1008
|
+
throw new RangeError("ZIP entry byte limit or nonempty directory");
|
|
1009
|
+
if (!zip642 && size >= 0xffffffffn)
|
|
1010
|
+
throw new RangeError("ZIP32 entry capacity exceeded");
|
|
1011
|
+
yield block;
|
|
1012
|
+
}
|
|
1013
|
+
if (entry.size !== void 0 && size !== entry.size)
|
|
1014
|
+
throw new TypeError("ZIP source size changed during encoding");
|
|
1015
|
+
}
|
|
1016
|
+
const hash = new CRC32Hash({
|
|
1017
|
+
crypto: {
|
|
1018
|
+
/** Captures the CRC after all decoded input bytes have been consumed. */
|
|
1019
|
+
onEnd: (result) => {
|
|
1020
|
+
checksum = Number.parseInt(result.hash, 16);
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
});
|
|
1024
|
+
const input = hash.hashBatches(measuredInput(), "hex");
|
|
1025
|
+
const payload = header.method === 8 ? new DeflateCompressor({ raw: true }).compressBatches(input) : input;
|
|
1026
|
+
for await (const block of payload) {
|
|
1027
|
+
signal == null ? void 0 : signal.throwIfAborted();
|
|
1028
|
+
compressedSize += BigInt(block.byteLength);
|
|
1029
|
+
if (!zip642 && compressedSize >= 0xffffffffn)
|
|
1030
|
+
throw new RangeError("ZIP32 compressed entry capacity exceeded");
|
|
1031
|
+
yield* emit(new Uint8Array(block));
|
|
1032
|
+
}
|
|
1033
|
+
const finalHeader = { ...header, size, compressedSize, crc32: checksum };
|
|
1034
|
+
yield* emit(encodeZipDescriptor(finalHeader));
|
|
1035
|
+
const centralHeader = encodeZipCentralHeader(finalHeader);
|
|
1036
|
+
directoryBytes += centralHeader.length;
|
|
1037
|
+
if (directoryBytes > settings.maxDirectoryBytes)
|
|
1038
|
+
throw new RangeError("ZIP directory byte limit exceeded");
|
|
1039
|
+
directory.push(centralHeader);
|
|
1040
|
+
}
|
|
1041
|
+
const directoryOffset = outputBytes;
|
|
1042
|
+
const zip64 = usedZip64 || settings.zip64 === "auto" && (paths.length >= 65535 || directoryBytes >= 4294967295 || directoryOffset >= 0xffffffffn);
|
|
1043
|
+
const footer = encodeZipEndRecords(BigInt(paths.length), BigInt(directoryBytes), directoryOffset, zip64, comment);
|
|
1044
|
+
for (const header of directory)
|
|
1045
|
+
yield* emit(header);
|
|
1046
|
+
yield* emit(footer);
|
|
1047
|
+
}
|
|
1048
|
+
function validateSettings(settings) {
|
|
1049
|
+
if (settings.compression !== "store" && settings.compression !== "deflate")
|
|
1050
|
+
throw new TypeError("Unsupported ZIP compression");
|
|
1051
|
+
if (!["auto", "always", "never"].includes(settings.zip64))
|
|
1052
|
+
throw new TypeError("Invalid ZIP64 policy");
|
|
1053
|
+
for (const [name, value] of Object.entries(settings)) {
|
|
1054
|
+
if (name === "compression" || name === "zip64")
|
|
1055
|
+
continue;
|
|
1056
|
+
const bigintLimit = name === "maxArchiveBytes" || name === "maxEntryBytes";
|
|
1057
|
+
if (bigintLimit ? typeof value !== "bigint" || value < 0n : typeof value !== "number" || !Number.isSafeInteger(value) || value < 1)
|
|
1058
|
+
throw new RangeError(`Invalid ZIP ${name} limit`);
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
function getSourceSize(source) {
|
|
1062
|
+
if (source instanceof ArrayBuffer || ArrayBuffer.isView(source))
|
|
1063
|
+
return BigInt(source.byteLength);
|
|
1064
|
+
if (source instanceof Blob)
|
|
1065
|
+
return BigInt(Object.getOwnPropertyDescriptor(Blob.prototype, "size").get.call(source));
|
|
1066
|
+
if (!source || typeof source !== "object" || !(source instanceof ReadableStream) && !(Symbol.asyncIterator in source) && !(Symbol.iterator in source))
|
|
1067
|
+
throw new TypeError("ZIP source must be bytes, a Blob or a byte stream");
|
|
1068
|
+
return void 0;
|
|
1069
|
+
}
|
|
1070
|
+
async function* readSource(source, chunkBytes, signal) {
|
|
1071
|
+
if (source instanceof Blob) {
|
|
1072
|
+
const size = Number(getSourceSize(source));
|
|
1073
|
+
for (let offset = 0; offset < size; offset += chunkBytes) {
|
|
1074
|
+
signal == null ? void 0 : signal.throwIfAborted();
|
|
1075
|
+
const blob = Blob.prototype.slice.call(source, offset, Math.min(size, offset + chunkBytes));
|
|
1076
|
+
const block = await awaitWithSignal(Blob.prototype.arrayBuffer.call(blob), signal);
|
|
1077
|
+
signal == null ? void 0 : signal.throwIfAborted();
|
|
1078
|
+
if (block.byteLength !== Math.min(chunkBytes, size - offset))
|
|
1079
|
+
throw new TypeError("ZIP Blob returned a truncated block");
|
|
1080
|
+
yield block;
|
|
1081
|
+
}
|
|
1082
|
+
return;
|
|
1083
|
+
}
|
|
1084
|
+
if (source instanceof ArrayBuffer || ArrayBuffer.isView(source)) {
|
|
1085
|
+
yield* splitByteChunk(source, chunkBytes, signal);
|
|
1086
|
+
return;
|
|
1087
|
+
}
|
|
1088
|
+
const reader = source instanceof ReadableStream ? source.getReader() : void 0;
|
|
1089
|
+
const iterator = reader ? void 0 : Symbol.asyncIterator in source ? source[Symbol.asyncIterator]() : source[Symbol.iterator]();
|
|
1090
|
+
let done = false;
|
|
1091
|
+
try {
|
|
1092
|
+
while (!done) {
|
|
1093
|
+
signal == null ? void 0 : signal.throwIfAborted();
|
|
1094
|
+
const result = await awaitWithSignal(reader ? reader.read() : Promise.resolve(iterator.next()), signal);
|
|
1095
|
+
done = Boolean(result.done);
|
|
1096
|
+
if (!done)
|
|
1097
|
+
yield* splitByteChunk(result.value, chunkBytes, signal);
|
|
1098
|
+
}
|
|
1099
|
+
} finally {
|
|
1100
|
+
if (reader) {
|
|
1101
|
+
if (!done)
|
|
1102
|
+
void reader.cancel(signal == null ? void 0 : signal.reason).catch(() => {
|
|
1103
|
+
});
|
|
1104
|
+
reader.releaseLock();
|
|
1105
|
+
} else if (!done && (iterator == null ? void 0 : iterator.return)) {
|
|
1106
|
+
void Promise.resolve().then(() => iterator.return()).catch(() => {
|
|
1107
|
+
});
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
function* splitByteChunk(chunk, chunkBytes, signal) {
|
|
1112
|
+
if (!(chunk instanceof ArrayBuffer) && !ArrayBuffer.isView(chunk))
|
|
1113
|
+
throw new TypeError("ZIP stream chunks must be binary");
|
|
1114
|
+
const bytes = chunk instanceof ArrayBuffer ? new Uint8Array(chunk) : new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength);
|
|
1115
|
+
const length = bytes.length;
|
|
1116
|
+
for (let offset = 0; offset < length; offset += chunkBytes) {
|
|
1117
|
+
signal == null ? void 0 : signal.throwIfAborted();
|
|
1118
|
+
if (bytes.byteLength !== length)
|
|
1119
|
+
throw new TypeError("ZIP source size changed during encoding");
|
|
1120
|
+
yield bytes.slice(offset, offset + chunkBytes).buffer;
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
function awaitWithSignal(promise, signal) {
|
|
1124
|
+
if (!signal)
|
|
1125
|
+
return promise;
|
|
1126
|
+
return new Promise((resolve, reject) => {
|
|
1127
|
+
const finish = (settle) => {
|
|
1128
|
+
signal.removeEventListener("abort", abort);
|
|
1129
|
+
settle();
|
|
1130
|
+
};
|
|
1131
|
+
const abort = () => finish(() => reject(signal.reason));
|
|
1132
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
1133
|
+
promise.then((value) => finish(() => resolve(value)), (error) => finish(() => reject(error)));
|
|
1134
|
+
if (signal.aborted)
|
|
1135
|
+
abort();
|
|
1136
|
+
});
|
|
1137
|
+
}
|
|
1138
|
+
function encodeArchiveComment(comment) {
|
|
1139
|
+
if (typeof comment !== "string")
|
|
1140
|
+
throw new TypeError("ZIP archive comment must be a string");
|
|
1141
|
+
const codepoints = [...comment];
|
|
1142
|
+
if (codepoints.length > 65535)
|
|
1143
|
+
throw new RangeError("ZIP archive comment exceeds 65535 bytes");
|
|
1144
|
+
const alphabet = decodeZipText(Uint8Array.from({ length: 256 }, (_, index) => index), false);
|
|
1145
|
+
const bytes = new Uint8Array(codepoints.length);
|
|
1146
|
+
codepoints.forEach((character, index) => {
|
|
1147
|
+
const position = alphabet.indexOf(character);
|
|
1148
|
+
if (position < 0)
|
|
1149
|
+
throw new TypeError("ZIP archive comment is not representable in CP437");
|
|
1150
|
+
bytes[index] = position;
|
|
1151
|
+
});
|
|
1152
|
+
return bytes;
|
|
1153
|
+
}
|
|
1154
|
+
//# sourceMappingURL=zip-encode.cjs.map
|