@myrialabs/zipkit 0.0.6
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 +21 -0
- package/README.md +329 -0
- package/dist/bench/corpus.d.ts +21 -0
- package/dist/bench/corpus.d.ts.map +1 -0
- package/dist/bench/corpus.js +92 -0
- package/dist/bench/corpus.js.map +1 -0
- package/dist/checksum.d.ts +29 -0
- package/dist/checksum.d.ts.map +1 -0
- package/dist/checksum.js +35 -0
- package/dist/checksum.js.map +1 -0
- package/dist/cli.d.ts +17 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +427 -0
- package/dist/cli.js.map +1 -0
- package/dist/codecs/brotli.d.ts +6 -0
- package/dist/codecs/brotli.d.ts.map +1 -0
- package/dist/codecs/brotli.js +15 -0
- package/dist/codecs/brotli.js.map +1 -0
- package/dist/codecs/bzip2.d.ts +6 -0
- package/dist/codecs/bzip2.d.ts.map +1 -0
- package/dist/codecs/bzip2.js +15 -0
- package/dist/codecs/bzip2.js.map +1 -0
- package/dist/codecs/deflate.d.ts +6 -0
- package/dist/codecs/deflate.d.ts.map +1 -0
- package/dist/codecs/deflate.js +25 -0
- package/dist/codecs/deflate.js.map +1 -0
- package/dist/codecs/gzip.d.ts +6 -0
- package/dist/codecs/gzip.d.ts.map +1 -0
- package/dist/codecs/gzip.js +25 -0
- package/dist/codecs/gzip.js.map +1 -0
- package/dist/codecs/image.d.ts +5 -0
- package/dist/codecs/image.d.ts.map +1 -0
- package/dist/codecs/image.js +16 -0
- package/dist/codecs/image.js.map +1 -0
- package/dist/codecs/index.d.ts +18 -0
- package/dist/codecs/index.d.ts.map +1 -0
- package/dist/codecs/index.js +18 -0
- package/dist/codecs/index.js.map +1 -0
- package/dist/codecs/lz4.d.ts +6 -0
- package/dist/codecs/lz4.d.ts.map +1 -0
- package/dist/codecs/lz4.js +17 -0
- package/dist/codecs/lz4.js.map +1 -0
- package/dist/codecs/lzma.d.ts +6 -0
- package/dist/codecs/lzma.d.ts.map +1 -0
- package/dist/codecs/lzma.js +15 -0
- package/dist/codecs/lzma.js.map +1 -0
- package/dist/codecs/snappy.d.ts +6 -0
- package/dist/codecs/snappy.d.ts.map +1 -0
- package/dist/codecs/snappy.js +14 -0
- package/dist/codecs/snappy.js.map +1 -0
- package/dist/codecs/video.d.ts +13 -0
- package/dist/codecs/video.d.ts.map +1 -0
- package/dist/codecs/video.js +26 -0
- package/dist/codecs/video.js.map +1 -0
- package/dist/codecs/xz.d.ts +6 -0
- package/dist/codecs/xz.d.ts.map +1 -0
- package/dist/codecs/xz.js +30 -0
- package/dist/codecs/xz.js.map +1 -0
- package/dist/codecs/zlib.d.ts +6 -0
- package/dist/codecs/zlib.d.ts.map +1 -0
- package/dist/codecs/zlib.js +15 -0
- package/dist/codecs/zlib.js.map +1 -0
- package/dist/codecs/zstd.d.ts +6 -0
- package/dist/codecs/zstd.d.ts.map +1 -0
- package/dist/codecs/zstd.js +24 -0
- package/dist/codecs/zstd.js.map +1 -0
- package/dist/compress.d.ts +20 -0
- package/dist/compress.d.ts.map +1 -0
- package/dist/compress.js +83 -0
- package/dist/compress.js.map +1 -0
- package/dist/delta.d.ts +30 -0
- package/dist/delta.d.ts.map +1 -0
- package/dist/delta.js +44 -0
- package/dist/delta.js.map +1 -0
- package/dist/detect.d.ts +46 -0
- package/dist/detect.d.ts.map +1 -0
- package/dist/detect.js +86 -0
- package/dist/detect.js.map +1 -0
- package/dist/dictionary.d.ts +37 -0
- package/dist/dictionary.d.ts.map +1 -0
- package/dist/dictionary.js +71 -0
- package/dist/dictionary.js.map +1 -0
- package/dist/engine.d.ts +102 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +204 -0
- package/dist/engine.js.map +1 -0
- package/dist/fsa.d.ts +54 -0
- package/dist/fsa.d.ts.map +1 -0
- package/dist/fsa.js +45 -0
- package/dist/fsa.js.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +47 -0
- package/dist/index.js.map +1 -0
- package/dist/internal.d.ts +21 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +42 -0
- package/dist/internal.js.map +1 -0
- package/dist/middleware/elysia.d.ts +15 -0
- package/dist/middleware/elysia.d.ts.map +1 -0
- package/dist/middleware/elysia.js +43 -0
- package/dist/middleware/elysia.js.map +1 -0
- package/dist/middleware/express.d.ts +17 -0
- package/dist/middleware/express.d.ts.map +1 -0
- package/dist/middleware/express.js +62 -0
- package/dist/middleware/express.js.map +1 -0
- package/dist/middleware/hono.d.ts +17 -0
- package/dist/middleware/hono.d.ts.map +1 -0
- package/dist/middleware/hono.js +41 -0
- package/dist/middleware/hono.js.map +1 -0
- package/dist/middleware/index.d.ts +14 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/index.js +14 -0
- package/dist/middleware/index.js.map +1 -0
- package/dist/middleware/shared.d.ts +29 -0
- package/dist/middleware/shared.d.ts.map +1 -0
- package/dist/middleware/shared.js +47 -0
- package/dist/middleware/shared.js.map +1 -0
- package/dist/pack.d.ts +36 -0
- package/dist/pack.d.ts.map +1 -0
- package/dist/pack.js +75 -0
- package/dist/pack.js.map +1 -0
- package/dist/parallel/index.d.ts +56 -0
- package/dist/parallel/index.d.ts.map +1 -0
- package/dist/parallel/index.js +158 -0
- package/dist/parallel/index.js.map +1 -0
- package/dist/sevenzip/index.d.ts +45 -0
- package/dist/sevenzip/index.d.ts.map +1 -0
- package/dist/sevenzip/index.js +646 -0
- package/dist/sevenzip/index.js.map +1 -0
- package/dist/streams/index.d.ts +32 -0
- package/dist/streams/index.d.ts.map +1 -0
- package/dist/streams/index.js +74 -0
- package/dist/streams/index.js.map +1 -0
- package/dist/string.d.ts +38 -0
- package/dist/string.d.ts.map +1 -0
- package/dist/string.js +64 -0
- package/dist/string.js.map +1 -0
- package/dist/tar/index.d.ts +99 -0
- package/dist/tar/index.d.ts.map +1 -0
- package/dist/tar/index.js +380 -0
- package/dist/tar/index.js.map +1 -0
- package/dist/types.d.ts +59 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +22 -0
- package/dist/types.js.map +1 -0
- package/dist/workers/index.d.ts +58 -0
- package/dist/workers/index.d.ts.map +1 -0
- package/dist/workers/index.js +158 -0
- package/dist/workers/index.js.map +1 -0
- package/dist/workers/worker.d.ts +18 -0
- package/dist/workers/worker.d.ts.map +1 -0
- package/dist/workers/worker.js +45 -0
- package/dist/workers/worker.js.map +1 -0
- package/dist/zip/crypto/aes.d.ts +25 -0
- package/dist/zip/crypto/aes.d.ts.map +1 -0
- package/dist/zip/crypto/aes.js +156 -0
- package/dist/zip/crypto/aes.js.map +1 -0
- package/dist/zip/crypto/winzip.d.ts +28 -0
- package/dist/zip/crypto/winzip.d.ts.map +1 -0
- package/dist/zip/crypto/winzip.js +87 -0
- package/dist/zip/crypto/winzip.js.map +1 -0
- package/dist/zip/crypto/zipcrypto.d.ts +14 -0
- package/dist/zip/crypto/zipcrypto.d.ts.map +1 -0
- package/dist/zip/crypto/zipcrypto.js +65 -0
- package/dist/zip/crypto/zipcrypto.js.map +1 -0
- package/dist/zip/datetime.d.ts +9 -0
- package/dist/zip/datetime.d.ts.map +1 -0
- package/dist/zip/datetime.js +13 -0
- package/dist/zip/datetime.js.map +1 -0
- package/dist/zip/index.d.ts +134 -0
- package/dist/zip/index.d.ts.map +1 -0
- package/dist/zip/index.js +473 -0
- package/dist/zip/index.js.map +1 -0
- package/dist/zip/stream.d.ts +38 -0
- package/dist/zip/stream.d.ts.map +1 -0
- package/dist/zip/stream.js +240 -0
- package/dist/zip/stream.js.map +1 -0
- package/dist/zipkit.d.ts +74 -0
- package/dist/zipkit.d.ts.map +1 -0
- package/dist/zipkit.js +168 -0
- package/dist/zipkit.js.map +1 -0
- package/engine/dist/zipkit-engine.mjs +2 -0
- package/engine/dist/zipkit-engine.wasm +0 -0
- package/package.json +137 -0
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Streaming ZIP writer — build an archive incrementally without ever holding
|
|
3
|
+
* the whole thing in memory.
|
|
4
|
+
*
|
|
5
|
+
* {@link zipStream} consumes entries one at a time (from a sync or async
|
|
6
|
+
* iterable) and emits archive bytes through a web-standard
|
|
7
|
+
* `ReadableStream<Uint8Array>` you can pipe straight to a file, an HTTP
|
|
8
|
+
* response, or `FileSystemWritableFileStream`. Peak memory is bounded by the
|
|
9
|
+
* single largest entry, not the archive total — so hundreds-of-MB / multi-GB
|
|
10
|
+
* archives never OOM in Node, Bun, or the browser.
|
|
11
|
+
*
|
|
12
|
+
* Each entry is compressed as one buffer (the engine is one-shot), so its
|
|
13
|
+
* CRC-32 and sizes are known before its local header is written — the output is
|
|
14
|
+
* byte-compatible with {@link import('./index.js').zip}, ZIP64 and all, and
|
|
15
|
+
* reads back with {@link import('./index.js').unzip} or any standard tool.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { zipStream } from '@myrialabs/zipkit/zip';
|
|
20
|
+
* const stream = zipStream(async function* () {
|
|
21
|
+
* for await (const file of files) yield { name: file.name, data: await file.bytes() };
|
|
22
|
+
* }());
|
|
23
|
+
* await stream.pipeTo(destinationWritable);
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
import { getEngine } from '../engine.js';
|
|
27
|
+
import { ZipKitError } from '../types.js';
|
|
28
|
+
import { toDosDateTime } from './datetime.js';
|
|
29
|
+
const SIG_LOCAL = 0x04034b50;
|
|
30
|
+
const SIG_CENTRAL = 0x02014b50;
|
|
31
|
+
const SIG_EOCD = 0x06054b50;
|
|
32
|
+
const SIG_EOCD64 = 0x06064b50;
|
|
33
|
+
const SIG_EOCD64_LOC = 0x07064b50;
|
|
34
|
+
const U32_MAX = 0xffffffff;
|
|
35
|
+
const U16_MAX = 0xffff;
|
|
36
|
+
const METHOD_CODE = { store: 0, deflate: 8, zstd: 93 };
|
|
37
|
+
const utf8 = new TextEncoder();
|
|
38
|
+
/** A growable little-endian byte writer that yields a standalone buffer. */
|
|
39
|
+
class Chunk {
|
|
40
|
+
buf = new Uint8Array(64);
|
|
41
|
+
view = new DataView(this.buf.buffer);
|
|
42
|
+
len = 0;
|
|
43
|
+
grow(extra) {
|
|
44
|
+
if (this.len + extra <= this.buf.length)
|
|
45
|
+
return;
|
|
46
|
+
let cap = this.buf.length * 2;
|
|
47
|
+
while (cap < this.len + extra)
|
|
48
|
+
cap *= 2;
|
|
49
|
+
const next = new Uint8Array(cap);
|
|
50
|
+
next.set(this.buf.subarray(0, this.len));
|
|
51
|
+
this.buf = next;
|
|
52
|
+
this.view = new DataView(this.buf.buffer);
|
|
53
|
+
}
|
|
54
|
+
u16(v) {
|
|
55
|
+
this.grow(2);
|
|
56
|
+
this.view.setUint16(this.len, v, true);
|
|
57
|
+
this.len += 2;
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
u32(v) {
|
|
61
|
+
this.grow(4);
|
|
62
|
+
this.view.setUint32(this.len, v >>> 0, true);
|
|
63
|
+
this.len += 4;
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
u64(v) {
|
|
67
|
+
this.grow(8);
|
|
68
|
+
this.view.setBigUint64(this.len, BigInt(v), true);
|
|
69
|
+
this.len += 8;
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
bytes(b) {
|
|
73
|
+
this.grow(b.length);
|
|
74
|
+
this.buf.set(b, this.len);
|
|
75
|
+
this.len += b.length;
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
take() {
|
|
79
|
+
return this.buf.subarray(0, this.len);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
async function compressFor(data, method, level) {
|
|
83
|
+
if (method === 'store')
|
|
84
|
+
return data;
|
|
85
|
+
const e = await getEngine();
|
|
86
|
+
if (method === 'deflate')
|
|
87
|
+
return e.deflateCompress(data, level ?? 6);
|
|
88
|
+
if (method === 'zstd')
|
|
89
|
+
return e.zstdCompress(data, level ?? 19);
|
|
90
|
+
throw new ZipKitError(`Unsupported ZIP method: ${method}`);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Stream a ZIP archive built from `entries` (a sync or async iterable). Returns
|
|
94
|
+
* a `ReadableStream<Uint8Array>` of the archive bytes. Uses ZIP64 automatically
|
|
95
|
+
* for entries/offsets past 4 GB or more than 65 535 entries.
|
|
96
|
+
*/
|
|
97
|
+
export function zipStream(entries, opts = {}) {
|
|
98
|
+
const iterator = Symbol.asyncIterator in entries
|
|
99
|
+
? entries[Symbol.asyncIterator]()
|
|
100
|
+
: entries[Symbol.iterator]();
|
|
101
|
+
const central = [];
|
|
102
|
+
let offset = 0;
|
|
103
|
+
let needZip64 = false;
|
|
104
|
+
let bytesWritten = 0;
|
|
105
|
+
let finished = false;
|
|
106
|
+
return new ReadableStream({
|
|
107
|
+
async pull(controller) {
|
|
108
|
+
try {
|
|
109
|
+
const next = await iterator.next();
|
|
110
|
+
if (!next.done) {
|
|
111
|
+
const chunk = await writeEntry(next.value);
|
|
112
|
+
controller.enqueue(chunk);
|
|
113
|
+
opts.onProgress?.(central.length, bytesWritten);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (!finished) {
|
|
117
|
+
finished = true;
|
|
118
|
+
controller.enqueue(writeTrailer());
|
|
119
|
+
controller.close();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
catch (err) {
|
|
123
|
+
controller.error(err);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
async function writeEntry(entry) {
|
|
128
|
+
const e = await getEngine();
|
|
129
|
+
const method = entry.method ?? 'deflate';
|
|
130
|
+
const methodCode = METHOD_CODE[method];
|
|
131
|
+
if (methodCode === undefined)
|
|
132
|
+
throw new ZipKitError(`Unsupported ZIP method: ${method}`);
|
|
133
|
+
const nameBytes = utf8.encode(entry.name);
|
|
134
|
+
const commentBytes = entry.comment ? utf8.encode(entry.comment) : new Uint8Array(0);
|
|
135
|
+
const data = entry.data;
|
|
136
|
+
const crc = e.crc32(data);
|
|
137
|
+
const compressed = await compressFor(data, method, entry.level);
|
|
138
|
+
const size = data.length;
|
|
139
|
+
const compSize = compressed.length;
|
|
140
|
+
const mtime = entry.mtime === undefined ? new Date(0) : new Date(entry.mtime);
|
|
141
|
+
const { date: dosDate, time: dosTime } = toDosDateTime(mtime);
|
|
142
|
+
const externalAttrs = entry.unixPermissions !== undefined ? (entry.unixPermissions & 0xffff) << 16 : 0;
|
|
143
|
+
const entryZip64 = needZip64 || size > U32_MAX || compSize > U32_MAX || offset > U32_MAX;
|
|
144
|
+
if (entryZip64)
|
|
145
|
+
needZip64 = true;
|
|
146
|
+
const c = new Chunk();
|
|
147
|
+
c.u32(SIG_LOCAL)
|
|
148
|
+
.u16(entryZip64 ? 45 : 20)
|
|
149
|
+
.u16(0x0800)
|
|
150
|
+
.u16(methodCode)
|
|
151
|
+
.u16(dosTime)
|
|
152
|
+
.u16(dosDate)
|
|
153
|
+
.u32(crc)
|
|
154
|
+
.u32(entryZip64 ? U32_MAX : compSize)
|
|
155
|
+
.u32(entryZip64 ? U32_MAX : size)
|
|
156
|
+
.u16(nameBytes.length)
|
|
157
|
+
.u16(entryZip64 ? 20 : 0)
|
|
158
|
+
.bytes(nameBytes);
|
|
159
|
+
if (entryZip64)
|
|
160
|
+
c.u16(0x0001).u16(16).u64(size).u64(compSize);
|
|
161
|
+
c.bytes(compressed);
|
|
162
|
+
central.push({
|
|
163
|
+
nameBytes,
|
|
164
|
+
commentBytes,
|
|
165
|
+
method: methodCode,
|
|
166
|
+
crc,
|
|
167
|
+
compSize,
|
|
168
|
+
size,
|
|
169
|
+
dosDate,
|
|
170
|
+
dosTime,
|
|
171
|
+
offset,
|
|
172
|
+
externalAttrs,
|
|
173
|
+
zip64: entryZip64
|
|
174
|
+
});
|
|
175
|
+
offset += c.len;
|
|
176
|
+
bytesWritten += c.len;
|
|
177
|
+
// Copy out of the growable buffer so the queued chunk is independent.
|
|
178
|
+
return c.take().slice();
|
|
179
|
+
}
|
|
180
|
+
function writeTrailer() {
|
|
181
|
+
const out = new Chunk();
|
|
182
|
+
const cdStart = offset;
|
|
183
|
+
for (const c of central) {
|
|
184
|
+
out.u32(SIG_CENTRAL)
|
|
185
|
+
.u16(c.zip64 ? 45 : 20)
|
|
186
|
+
.u16(c.zip64 ? 45 : 20)
|
|
187
|
+
.u16(0x0800)
|
|
188
|
+
.u16(c.method)
|
|
189
|
+
.u16(c.dosTime)
|
|
190
|
+
.u16(c.dosDate)
|
|
191
|
+
.u32(c.crc)
|
|
192
|
+
.u32(c.zip64 ? U32_MAX : c.compSize)
|
|
193
|
+
.u32(c.zip64 ? U32_MAX : c.size)
|
|
194
|
+
.u16(c.nameBytes.length);
|
|
195
|
+
const zip64Extra = c.zip64 ? [c.size, c.compSize, c.offset] : [];
|
|
196
|
+
out.u16(c.zip64 ? 4 + zip64Extra.length * 8 : 0)
|
|
197
|
+
.u16(c.commentBytes.length)
|
|
198
|
+
.u16(0)
|
|
199
|
+
.u16(0)
|
|
200
|
+
.u32(c.externalAttrs)
|
|
201
|
+
.u32(c.zip64 ? U32_MAX : c.offset)
|
|
202
|
+
.bytes(c.nameBytes);
|
|
203
|
+
if (c.zip64) {
|
|
204
|
+
out.u16(0x0001).u16(zip64Extra.length * 8);
|
|
205
|
+
for (const v of zip64Extra)
|
|
206
|
+
out.u64(v);
|
|
207
|
+
}
|
|
208
|
+
out.bytes(c.commentBytes);
|
|
209
|
+
}
|
|
210
|
+
const cdSize = out.len;
|
|
211
|
+
const count = central.length;
|
|
212
|
+
if (needZip64 || count > U16_MAX || cdSize > U32_MAX || cdStart > U32_MAX) {
|
|
213
|
+
const eocd64Offset = cdStart + cdSize;
|
|
214
|
+
out.u32(SIG_EOCD64)
|
|
215
|
+
.u64(44)
|
|
216
|
+
.u16(45)
|
|
217
|
+
.u16(45)
|
|
218
|
+
.u32(0)
|
|
219
|
+
.u32(0)
|
|
220
|
+
.u64(count)
|
|
221
|
+
.u64(count)
|
|
222
|
+
.u64(cdSize)
|
|
223
|
+
.u64(cdStart)
|
|
224
|
+
.u32(SIG_EOCD64_LOC)
|
|
225
|
+
.u32(0)
|
|
226
|
+
.u64(eocd64Offset)
|
|
227
|
+
.u32(1);
|
|
228
|
+
}
|
|
229
|
+
out.u32(SIG_EOCD)
|
|
230
|
+
.u16(0)
|
|
231
|
+
.u16(0)
|
|
232
|
+
.u16(count > U16_MAX ? U16_MAX : count)
|
|
233
|
+
.u16(count > U16_MAX ? U16_MAX : count)
|
|
234
|
+
.u32(cdSize > U32_MAX ? U32_MAX : cdSize)
|
|
235
|
+
.u32(cdStart > U32_MAX ? U32_MAX : cdStart)
|
|
236
|
+
.u16(0);
|
|
237
|
+
return out.take().slice();
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
//# sourceMappingURL=stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/zip/stream.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAG9C,MAAM,SAAS,GAAG,UAAU,CAAC;AAC7B,MAAM,WAAW,GAAG,UAAU,CAAC;AAC/B,MAAM,QAAQ,GAAG,UAAU,CAAC;AAC5B,MAAM,UAAU,GAAG,UAAU,CAAC;AAC9B,MAAM,cAAc,GAAG,UAAU,CAAC;AAClC,MAAM,OAAO,GAAG,UAAU,CAAC;AAC3B,MAAM,OAAO,GAAG,MAAM,CAAC;AACvB,MAAM,WAAW,GAA8B,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;AAElF,MAAM,IAAI,GAAG,IAAI,WA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AAG,CAAC,YAAY,CAAC;iBACjB,GAAG,CAAC,CAAC,CAAC,CAAC;QACV,CAAC;QAED,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC;aACf,GAAG,CAAC,CAAC,CAAC;aACN,GAAG,CAAC,CAAC,CAAC;aACN,GAAG,CAAC,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC;aACtC,GAAG,CAAC,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC;aACtC,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;aACxC,GAAG,CAAC,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;aAC1C,GAAG,CAAC,CAAC,CAAC,CAAC;QACT,OAAO,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC;IAC3B,CAAC;AACF,CAAC"}
|
package/dist/zipkit.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ZipKit — the high-level, synchronous API with runtime-adaptive dispatch.
|
|
3
|
+
*
|
|
4
|
+
* Goal: keep the public API small while still taking the best path available:
|
|
5
|
+
* • gzip/deflate — balanced/speed always use native Bun zlib when available;
|
|
6
|
+
* ratio mode forces libdeflate for denser output.
|
|
7
|
+
* • zlib — uses the libdeflate engine for standard zlib streams.
|
|
8
|
+
* • zstd — where Bun ships native libzstd (the speed ceiling), dispatch to
|
|
9
|
+
* native. In the browser / Node, fall back to the ZipKit Wasm engine.
|
|
10
|
+
* • lz4/snappy/brotli/lzma/bzip2/qoi/frame-delta — no native competitor
|
|
11
|
+
* exists anywhere, so always use the ZipKit engine.
|
|
12
|
+
*
|
|
13
|
+
* Net effect: the default is practical and fast, while `mode: 'ratio'` makes
|
|
14
|
+
* density explicit without exposing a maze of options.
|
|
15
|
+
*
|
|
16
|
+
* Methods here are synchronous because the engine is already loaded — construct
|
|
17
|
+
* an instance with `await ZipKit.load()`. For the async, lazy-loading helpers,
|
|
18
|
+
* import the named codec functions from the package root instead.
|
|
19
|
+
*/
|
|
20
|
+
import { ZipKitEngine } from './engine.js';
|
|
21
|
+
import type { CompressOptions } from './types.js';
|
|
22
|
+
type SyncCompressOptions = number | CompressOptions | undefined;
|
|
23
|
+
/** The codec used to compress the frame-delta residual (see {@link ZipKit.encodeFrames}). */
|
|
24
|
+
export type FrameCodec = 'zstd' | 'lz4';
|
|
25
|
+
export declare class ZipKit {
|
|
26
|
+
/** The underlying raw Wasm engine, for codecs not surfaced as methods here. */
|
|
27
|
+
readonly engine: ZipKitEngine;
|
|
28
|
+
/**
|
|
29
|
+
* Which path zstd dispatches to: native (`'bun'`) or the Wasm engine
|
|
30
|
+
* (`'wasm'`).
|
|
31
|
+
*/
|
|
32
|
+
readonly runtime: 'bun' | 'wasm';
|
|
33
|
+
private constructor();
|
|
34
|
+
/** Instantiate the engine and return a ready-to-use, synchronous instance. */
|
|
35
|
+
static load(): Promise<ZipKit>;
|
|
36
|
+
gzip(d: Uint8Array, levelOrOpts?: SyncCompressOptions): Uint8Array;
|
|
37
|
+
gunzip(d: Uint8Array): Uint8Array;
|
|
38
|
+
deflate(d: Uint8Array, levelOrOpts?: SyncCompressOptions): Uint8Array;
|
|
39
|
+
inflate(d: Uint8Array): Uint8Array;
|
|
40
|
+
zlib(d: Uint8Array, levelOrOpts?: SyncCompressOptions): Uint8Array;
|
|
41
|
+
unzlib(d: Uint8Array): Uint8Array;
|
|
42
|
+
zstd(d: Uint8Array, levelOrOpts?: SyncCompressOptions): Uint8Array;
|
|
43
|
+
unzstd(d: Uint8Array): Uint8Array;
|
|
44
|
+
lz4(d: Uint8Array): Uint8Array;
|
|
45
|
+
unlz4(d: Uint8Array): Uint8Array;
|
|
46
|
+
snappy(d: Uint8Array): Uint8Array;
|
|
47
|
+
unsnappy(d: Uint8Array): Uint8Array;
|
|
48
|
+
brotli(d: Uint8Array, levelOrOpts?: SyncCompressOptions): Uint8Array;
|
|
49
|
+
unbrotli(d: Uint8Array): Uint8Array;
|
|
50
|
+
lzma(d: Uint8Array, levelOrOpts?: SyncCompressOptions): Uint8Array;
|
|
51
|
+
unlzma(d: Uint8Array): Uint8Array;
|
|
52
|
+
bzip2(d: Uint8Array, levelOrOpts?: SyncCompressOptions): Uint8Array;
|
|
53
|
+
unbzip2(d: Uint8Array): Uint8Array;
|
|
54
|
+
encodeImage(pixels: Uint8Array, w: number, h: number, channels: 3 | 4): Uint8Array;
|
|
55
|
+
decodeImage(d: Uint8Array): Uint8Array;
|
|
56
|
+
encodeFrames(frames: Uint8Array, frameSize: number, codec?: FrameCodec): Uint8Array;
|
|
57
|
+
decodeFrames(d: Uint8Array, frameSize: number, codec?: FrameCodec): Uint8Array;
|
|
58
|
+
/**
|
|
59
|
+
* Try the max-ratio codecs (brotli, lzma, bzip2, zstd-ultra) and return the
|
|
60
|
+
* smallest result, tagged with a one-byte codec id so {@link unpack} can
|
|
61
|
+
* reverse it. Use when output size matters more than compression time. For
|
|
62
|
+
* the async, lazy-loading form, import `pack` from the package root.
|
|
63
|
+
*/
|
|
64
|
+
pack(d: Uint8Array): Uint8Array;
|
|
65
|
+
/** Reverse {@link pack}. */
|
|
66
|
+
unpack(d: Uint8Array): Uint8Array;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Load (or reuse) a process-wide {@link ZipKit} instance. Convenient when you
|
|
70
|
+
* want the synchronous API without managing the instance yourself.
|
|
71
|
+
*/
|
|
72
|
+
export declare function init(): Promise<ZipKit>;
|
|
73
|
+
export {};
|
|
74
|
+
//# sourceMappingURL=zipkit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zipkit.d.ts","sourceRoot":"","sources":["../src/zipkit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,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E,mBAAmB,GAAG,UAAU;IAKpE,QAAQ,CAAC,CAAC,EAAE,UAAU,GAAG,UAAU;IAGnC,IAAI,CAAC,CAAC,EAAE,UAAU,EAAE,WAAW,CAAC,EAAE,mBAAmB,GAAG,UAAU;IAKlE,MAAM,CAAC,CAAC,EAAE,UAAU,GAAG,UAAU;IAGjC,KAAK,CAAC,CAAC,EAAE,UAAU,EAAE,WAAW,CAAC,EAAE,mBAAmB,GAAG,UAAU;IAKnE,OAAO,CAAC,CAAC,EAAE,UAAU,GAAG,UAAU;IAKlC,WAAW,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC,GAAG,UAAU;IAGlF,WAAW,CAAC,CAAC,EAAE,UAAU,GAAG,UAAU;IAKtC,YAAY,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,GAAE,UAAmB,GAAG,UAAU;IAI3F,YAAY,CAAC,CAAC,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,GAAE,UAAmB,GAAG,UAAU;IAMtF;;;;;OAKG;IACH,IAAI,CAAC,CAAC,EAAE,UAAU,GAAG,UAAU;IAG/B,4BAA4B;IAC5B,MAAM,CAAC,CAAC,EAAE,UAAU,GAAG,UAAU;CAGjC;AAID;;;GAGG;AACH,wBAAgB,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAEtC"}
|
package/dist/zipkit.js
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ZipKit — the high-level, synchronous API with runtime-adaptive dispatch.
|
|
3
|
+
*
|
|
4
|
+
* Goal: keep the public API small while still taking the best path available:
|
|
5
|
+
* • gzip/deflate — balanced/speed always use native Bun zlib when available;
|
|
6
|
+
* ratio mode forces libdeflate for denser output.
|
|
7
|
+
* • zlib — uses the libdeflate engine for standard zlib streams.
|
|
8
|
+
* • zstd — where Bun ships native libzstd (the speed ceiling), dispatch to
|
|
9
|
+
* native. In the browser / Node, fall back to the ZipKit Wasm engine.
|
|
10
|
+
* • lz4/snappy/brotli/lzma/bzip2/qoi/frame-delta — no native competitor
|
|
11
|
+
* exists anywhere, so always use the ZipKit engine.
|
|
12
|
+
*
|
|
13
|
+
* Net effect: the default is practical and fast, while `mode: 'ratio'` makes
|
|
14
|
+
* density explicit without exposing a maze of options.
|
|
15
|
+
*
|
|
16
|
+
* Methods here are synchronous because the engine is already loaded — construct
|
|
17
|
+
* an instance with `await ZipKit.load()`. For the async, lazy-loading helpers,
|
|
18
|
+
* import the named codec functions from the package root instead.
|
|
19
|
+
*/
|
|
20
|
+
import { ZipKitEngine } from './engine.js';
|
|
21
|
+
import { compressionMode, levelForMode } from './internal.js';
|
|
22
|
+
import { packSync, unpackSync } from './pack.js';
|
|
23
|
+
const isBun = typeof globalThis.Bun !== 'undefined';
|
|
24
|
+
const B = globalThis.Bun;
|
|
25
|
+
function optsFrom(levelOrOpts) {
|
|
26
|
+
return typeof levelOrOpts === 'number' ? { level: levelOrOpts } : levelOrOpts;
|
|
27
|
+
}
|
|
28
|
+
function useNativeDeflateFamily(opts, method) {
|
|
29
|
+
const fn = method === 'gzip' ? B?.gzipSync : B?.deflateSync;
|
|
30
|
+
return compressionMode(opts) !== 'ratio' && typeof fn === 'function';
|
|
31
|
+
}
|
|
32
|
+
export class ZipKit {
|
|
33
|
+
/** The underlying raw Wasm engine, for codecs not surfaced as methods here. */
|
|
34
|
+
engine;
|
|
35
|
+
/**
|
|
36
|
+
* Which path zstd dispatches to: native (`'bun'`) or the Wasm engine
|
|
37
|
+
* (`'wasm'`).
|
|
38
|
+
*/
|
|
39
|
+
runtime;
|
|
40
|
+
constructor(engine) {
|
|
41
|
+
this.engine = engine;
|
|
42
|
+
this.runtime = isBun ? 'bun' : 'wasm';
|
|
43
|
+
}
|
|
44
|
+
/** Instantiate the engine and return a ready-to-use, synchronous instance. */
|
|
45
|
+
static async load() {
|
|
46
|
+
return new ZipKit(await ZipKitEngine.load());
|
|
47
|
+
}
|
|
48
|
+
// ---- gzip / deflate / zlib: standard streams with adaptive policy ----
|
|
49
|
+
gzip(d, levelOrOpts) {
|
|
50
|
+
const opts = optsFrom(levelOrOpts);
|
|
51
|
+
const level = levelForMode(opts, 0, 9, { speed: 1, balanced: 6, ratio: 9 });
|
|
52
|
+
if (useNativeDeflateFamily(opts, 'gzip'))
|
|
53
|
+
return B.gzipSync(d, { level });
|
|
54
|
+
return this.engine.gzipCompress(d, level);
|
|
55
|
+
}
|
|
56
|
+
gunzip(d) {
|
|
57
|
+
if (isBun && B?.gunzipSync)
|
|
58
|
+
return B.gunzipSync(d);
|
|
59
|
+
return this.engine.gzipDecompress(d);
|
|
60
|
+
}
|
|
61
|
+
deflate(d, levelOrOpts) {
|
|
62
|
+
const opts = optsFrom(levelOrOpts);
|
|
63
|
+
const level = levelForMode(opts, 0, 9, { speed: 1, balanced: 6, ratio: 9 });
|
|
64
|
+
if (useNativeDeflateFamily(opts, 'deflate'))
|
|
65
|
+
return B.deflateSync(d, { level });
|
|
66
|
+
return this.engine.deflateCompress(d, level);
|
|
67
|
+
}
|
|
68
|
+
inflate(d) {
|
|
69
|
+
if (isBun && B?.inflateSync)
|
|
70
|
+
return B.inflateSync(d);
|
|
71
|
+
return this.engine.deflateDecompress(d);
|
|
72
|
+
}
|
|
73
|
+
zlib(d, levelOrOpts) {
|
|
74
|
+
const opts = optsFrom(levelOrOpts);
|
|
75
|
+
const level = levelForMode(opts, 0, 9, { speed: 1, balanced: 6, ratio: 9 });
|
|
76
|
+
return this.engine.zlibCompress(d, level);
|
|
77
|
+
}
|
|
78
|
+
unzlib(d) {
|
|
79
|
+
return this.engine.zlibDecompress(d);
|
|
80
|
+
}
|
|
81
|
+
// ---- zstd: native in Bun, engine elsewhere ----
|
|
82
|
+
zstd(d, levelOrOpts) {
|
|
83
|
+
const opts = optsFrom(levelOrOpts);
|
|
84
|
+
const level = levelForMode(opts, 1, 22, { speed: 1, balanced: 3, ratio: 19 });
|
|
85
|
+
if (isBun)
|
|
86
|
+
return B.zstdCompressSync(d, { level });
|
|
87
|
+
return level > 19 ? this.engine.zstdMaxCompress(d, level) : this.engine.zstdCompress(d, level);
|
|
88
|
+
}
|
|
89
|
+
unzstd(d) {
|
|
90
|
+
return isBun ? B.zstdDecompressSync(d) : this.engine.zstdDecompress(d);
|
|
91
|
+
}
|
|
92
|
+
// ---- engine-only (no native competitor anywhere) ----
|
|
93
|
+
lz4(d) {
|
|
94
|
+
return this.engine.lz4Compress(d);
|
|
95
|
+
}
|
|
96
|
+
unlz4(d) {
|
|
97
|
+
return this.engine.lz4Decompress(d);
|
|
98
|
+
}
|
|
99
|
+
snappy(d) {
|
|
100
|
+
return this.engine.snappyCompress(d);
|
|
101
|
+
}
|
|
102
|
+
unsnappy(d) {
|
|
103
|
+
return this.engine.snappyDecompress(d);
|
|
104
|
+
}
|
|
105
|
+
brotli(d, levelOrOpts) {
|
|
106
|
+
const opts = optsFrom(levelOrOpts);
|
|
107
|
+
const quality = levelForMode(opts, 0, 11, { speed: 4, balanced: 6, ratio: 11 });
|
|
108
|
+
return this.engine.brotliCompress(d, quality);
|
|
109
|
+
}
|
|
110
|
+
unbrotli(d) {
|
|
111
|
+
return this.engine.brotliDecompress(d);
|
|
112
|
+
}
|
|
113
|
+
lzma(d, levelOrOpts) {
|
|
114
|
+
const opts = optsFrom(levelOrOpts);
|
|
115
|
+
const level = levelForMode(opts, 0, 9, { speed: 3, balanced: 6, ratio: 9 });
|
|
116
|
+
return this.engine.lzmaCompress(d, level);
|
|
117
|
+
}
|
|
118
|
+
unlzma(d) {
|
|
119
|
+
return this.engine.lzmaDecompress(d);
|
|
120
|
+
}
|
|
121
|
+
bzip2(d, levelOrOpts) {
|
|
122
|
+
const opts = optsFrom(levelOrOpts);
|
|
123
|
+
const level = levelForMode(opts, 1, 9, { speed: 1, balanced: 6, ratio: 9 });
|
|
124
|
+
return this.engine.bzip2Compress(d, level);
|
|
125
|
+
}
|
|
126
|
+
unbzip2(d) {
|
|
127
|
+
return this.engine.bzip2Decompress(d);
|
|
128
|
+
}
|
|
129
|
+
// ---- image (QOI) ----
|
|
130
|
+
encodeImage(pixels, w, h, channels) {
|
|
131
|
+
return this.engine.qoiEncode(pixels, w, h, channels);
|
|
132
|
+
}
|
|
133
|
+
decodeImage(d) {
|
|
134
|
+
return this.engine.qoiDecode(d);
|
|
135
|
+
}
|
|
136
|
+
// ---- video / temporal streams: frame-delta + a fast codec ----
|
|
137
|
+
encodeFrames(frames, frameSize, codec = 'zstd') {
|
|
138
|
+
const residual = this.engine.frameDeltaEncode(frames, frameSize);
|
|
139
|
+
return codec === 'lz4' ? this.engine.lz4Compress(residual) : this.engine.zstdCompress(residual, 19);
|
|
140
|
+
}
|
|
141
|
+
decodeFrames(d, frameSize, codec = 'zstd') {
|
|
142
|
+
const residual = codec === 'lz4' ? this.engine.lz4Decompress(d) : this.engine.zstdDecompress(d);
|
|
143
|
+
return this.engine.frameDeltaDecode(residual, frameSize);
|
|
144
|
+
}
|
|
145
|
+
// ---- "smallest possible" — pick the densest codec for the data ----
|
|
146
|
+
/**
|
|
147
|
+
* Try the max-ratio codecs (brotli, lzma, bzip2, zstd-ultra) and return the
|
|
148
|
+
* smallest result, tagged with a one-byte codec id so {@link unpack} can
|
|
149
|
+
* reverse it. Use when output size matters more than compression time. For
|
|
150
|
+
* the async, lazy-loading form, import `pack` from the package root.
|
|
151
|
+
*/
|
|
152
|
+
pack(d) {
|
|
153
|
+
return packSync(this.engine, d);
|
|
154
|
+
}
|
|
155
|
+
/** Reverse {@link pack}. */
|
|
156
|
+
unpack(d) {
|
|
157
|
+
return unpackSync(this.engine, d);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
let singleton;
|
|
161
|
+
/**
|
|
162
|
+
* Load (or reuse) a process-wide {@link ZipKit} instance. Convenient when you
|
|
163
|
+
* want the synchronous API without managing the instance yourself.
|
|
164
|
+
*/
|
|
165
|
+
export function init() {
|
|
166
|
+
return (singleton ??= ZipKit.load());
|
|
167
|
+
}
|
|
168
|
+
//# sourceMappingURL=zipkit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zipkit.js","sourceRoot":"","sources":["../src/zipkit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAGjD,MAAM,KAAK,GAAG,OAAQ,UAAgC,CAAC,GAAG,KAAK,WAAW,CAAC;AAC3E,MAAM,CAAC,GAAS,UAAgC,CAAC,GAAG,CAAC;AAIrD,SAAS,QAAQ,CAAC,WAAgC;IACjD,OAAO,OAAO,WAAW,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC;AAC/E,CAAC;AAED,SAAS,sBAAsB,CAAC,IAAiC,EAAE,MAA0B;IAC5F,MAAM,EAAE,GAAG,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC;IAC5D,OAAO,eAAe,CAAC,IAAI,CAAC,KAAK,OAAO,IAAI,OAAO,EAAE,KAAK,UAAU,CAAC;AACtE,CAAC;AAKD,MAAM,OAAO,MAAM;IAClB,+EAA+E;IACtE,MAAM,CAAe;IAC9B;;;OAGG;IACM,OAAO,CAAiB;IAEjC,YAAoB,MAAoB;QACvC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC;IACvC,CAAC;IAED,8EAA8E;IAC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O,KAAK,KAAK,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IACrG,CAAC;IACD,YAAY,CAAC,CAAa,EAAE,SAAiB,EAAE,QAAoB,MAAM;QACxE,MAAM,QAAQ,GAAG,KAAK,KAAK,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;QAChG,OAAO,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IAC1D,CAAC;IAED,sEAAsE;IACtE;;;;;OAKG;IACH,IAAI,CAAC,CAAa;QACjB,OAAO,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IACjC,CAAC;IACD,4BAA4B;IAC5B,MAAM,CAAC,CAAa;QACnB,OAAO,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IACnC,CAAC;CACD;AAED,IAAI,SAAsC,CAAC;AAE3C;;;GAGG;AACH,MAAM,UAAU,IAAI;IACnB,OAAO,CAAC,SAAS,KAAK,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
async function ZipKitModule(moduleArg={}){var moduleRtn;var Module=moduleArg;var ENVIRONMENT_IS_WEB=!!globalThis.window;var ENVIRONMENT_IS_WORKER=!!globalThis.WorkerGlobalScope;var ENVIRONMENT_IS_NODE=globalThis.process?.versions?.node&&globalThis.process?.type!="renderer";if(ENVIRONMENT_IS_NODE){const{createRequire}=await import("node:module");var require=createRequire(import.meta.url)}var arguments_=[];var thisProgram="./this.program";var quit_=(status,toThrow)=>{throw toThrow};var _scriptName=import.meta.url;var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var readAsync,readBinary;if(ENVIRONMENT_IS_NODE){var fs=require("node:fs");if(_scriptName.startsWith("file:")){scriptDirectory=require("node:path").dirname(require("node:url").fileURLToPath(_scriptName))+"/"}readBinary=filename=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename);return ret};readAsync=async(filename,binary=true)=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename,binary?undefined:"utf8");return ret};if(process.argv.length>1){thisProgram=process.argv[1].replace(/\\/g,"/")}arguments_=process.argv.slice(2);quit_=(status,toThrow)=>{process.exitCode=status;throw toThrow}}else if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){try{scriptDirectory=new URL(".",_scriptName).href}catch{}{readAsync=async url=>{var response=await fetch(url,{credentials:"same-origin"});if(response.ok){return response.arrayBuffer()}throw new Error(response.status+" : "+response.url)}}}else{}var out=console.log.bind(console);var err=console.error.bind(console);var wasmBinary;var ABORT=false;var EXITSTATUS;var isFileURI=filename=>filename.startsWith("file://");class EmscriptenEH{}class EmscriptenSjLj extends EmscriptenEH{}var readyPromiseResolve,readyPromiseReject;var runtimeInitialized=false;function updateMemoryViews(){var b=wasmMemory.buffer;HEAP8=new Int8Array(b);HEAP16=new Int16Array(b);Module["HEAPU8"]=HEAPU8=new Uint8Array(b);HEAPU16=new Uint16Array(b);HEAP32=new Int32Array(b);HEAPU32=new Uint32Array(b);HEAPF32=new Float32Array(b);HEAPF64=new Float64Array(b);HEAP64=new BigInt64Array(b);HEAPU64=new BigUint64Array(b)}function preRun(){if(Module["preRun"]){if(typeof Module["preRun"]=="function")Module["preRun"]=[Module["preRun"]];while(Module["preRun"].length){addOnPreRun(Module["preRun"].shift())}}callRuntimeCallbacks(onPreRuns)}function initRuntime(){runtimeInitialized=true;wasmExports["m"]()}function postRun(){if(Module["postRun"]){if(typeof Module["postRun"]=="function")Module["postRun"]=[Module["postRun"]];while(Module["postRun"].length){addOnPostRun(Module["postRun"].shift())}}callRuntimeCallbacks(onPostRuns)}function abort(what){Module["onAbort"]?.(what);what=`Aborted(${what})`;err(what);ABORT=true;what+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(what);readyPromiseReject?.(e);throw e}var wasmBinaryFile;function findWasmBinary(){if(Module["locateFile"]){return locateFile("zipkit-engine.wasm")}return new URL("zipkit-engine.wasm",import.meta.url).href}function getBinarySync(file){if(file==wasmBinaryFile&&wasmBinary){return new Uint8Array(wasmBinary)}if(readBinary){return readBinary(file)}throw"both async and sync fetching of the wasm failed"}async function getWasmBinary(binaryFile){if(!wasmBinary){try{var response=await readAsync(binaryFile);return new Uint8Array(response)}catch{}}return getBinarySync(binaryFile)}async function instantiateArrayBuffer(binaryFile,imports){try{var binary=await getWasmBinary(binaryFile);var instance=await WebAssembly.instantiate(binary,imports);return instance}catch(reason){err(`failed to asynchronously prepare wasm: ${reason}`);abort(reason)}}async function instantiateAsync(binary,binaryFile,imports){if(!binary&&!ENVIRONMENT_IS_NODE){try{var response=fetch(binaryFile,{credentials:"same-origin"});var instantiationResult=await WebAssembly.instantiateStreaming(response,imports);return instantiationResult}catch(reason){err(`wasm streaming compile failed: ${reason}`);err("falling back to ArrayBuffer instantiation")}}return instantiateArrayBuffer(binaryFile,imports)}function getWasmImports(){var imports={a:wasmImports};return imports}async function createWasm(){function receiveInstance(instance,module){wasmExports=instance.exports;wasmExports=applySignatureConversions(wasmExports);assignWasmExports(wasmExports);updateMemoryViews();return wasmExports}function receiveInstantiationResult(result){return receiveInstance(result["instance"])}var info=getWasmImports();if(Module["instantiateWasm"]){return new Promise((resolve,reject)=>{Module["instantiateWasm"](info,(inst,mod)=>{resolve(receiveInstance(inst,mod))})})}wasmBinaryFile??=findWasmBinary();var result=await instantiateAsync(wasmBinary,wasmBinaryFile,info);var exports=receiveInstantiationResult(result);return exports}class ExitStatus{name="ExitStatus";constructor(status){this.message=`Program terminated with exit(${status})`;this.status=status}}var HEAP16;var HEAP32;var HEAP64;var HEAP8;var HEAPF32;var HEAPF64;var HEAPU16;var HEAPU32;var HEAPU64;var HEAPU8;var callRuntimeCallbacks=callbacks=>{while(callbacks.length>0){callbacks.shift()(Module)}};var onPostRuns=[];var addOnPostRun=cb=>onPostRuns.push(cb);var onPreRuns=[];var addOnPreRun=cb=>onPreRuns.push(cb);var noExitRuntime=true;var INT53_MAX=9007199254740992;var INT53_MIN=-9007199254740992;var bigintToI53Checked=num=>num<INT53_MIN||num>INT53_MAX?NaN:Number(num);var UTF8Decoder=globalThis.TextDecoder&&new TextDecoder;var findStringEnd=(heapOrArray,idx,maxBytesToRead,ignoreNul)=>{var maxIdx=idx+maxBytesToRead;if(ignoreNul)return maxIdx;while(heapOrArray[idx]&&!(idx>=maxIdx))++idx;return idx};var UTF8ArrayToString=(heapOrArray,idx=0,maxBytesToRead,ignoreNul)=>{idx>>>=0;var endPtr=findStringEnd(heapOrArray,idx,maxBytesToRead,ignoreNul);if(endPtr-idx>16&&heapOrArray.buffer&&UTF8Decoder){return UTF8Decoder.decode(heapOrArray.subarray(idx,endPtr))}var str="";while(idx<endPtr){var u0=heapOrArray[idx++];if(!(u0&128)){str+=String.fromCharCode(u0);continue}var u1=heapOrArray[idx++]&63;if((u0&224)==192){str+=String.fromCharCode((u0&31)<<6|u1);continue}var u2=heapOrArray[idx++]&63;if((u0&240)==224){u0=(u0&15)<<12|u1<<6|u2}else{u0=(u0&7)<<18|u1<<12|u2<<6|heapOrArray[idx++]&63}if(u0<65536){str+=String.fromCharCode(u0)}else{var ch=u0-65536;str+=String.fromCharCode(55296|ch>>10,56320|ch&1023)}}return str};var UTF8ToString=(ptr,maxBytesToRead,ignoreNul)=>{ptr>>>=0;return ptr?UTF8ArrayToString(HEAPU8,ptr,maxBytesToRead,ignoreNul):""};function ___assert_fail(condition,filename,line,func){condition>>>=0;filename>>>=0;func>>>=0;return abort(`Assertion failed: ${UTF8ToString(condition)}, at: `+[filename?UTF8ToString(filename):"unknown filename",line,func?UTF8ToString(func):"unknown function"])}var __abort_js=()=>abort("");var runtimeKeepaliveCounter=0;var __emscripten_runtime_keepalive_clear=()=>{noExitRuntime=false;runtimeKeepaliveCounter=0};var timers={};var handleException=e=>{if(e instanceof ExitStatus||e=="unwind"){return EXITSTATUS}quit_(1,e)};var keepRuntimeAlive=()=>noExitRuntime||runtimeKeepaliveCounter>0;var _proc_exit=code=>{EXITSTATUS=code;if(!keepRuntimeAlive()){Module["onExit"]?.(code);ABORT=true}quit_(code,new ExitStatus(code))};var exitJS=(status,implicit)=>{EXITSTATUS=status;_proc_exit(status)};var _exit=exitJS;var maybeExit=()=>{if(!keepRuntimeAlive()){try{_exit(EXITSTATUS)}catch(e){handleException(e)}}};var callUserCallback=func=>{if(ABORT){return}try{return func()}catch(e){handleException(e)}finally{maybeExit()}};var _emscripten_get_now=()=>performance.now();var __setitimer_js=(which,timeout_ms)=>{if(timers[which]){clearTimeout(timers[which].id);delete timers[which]}if(!timeout_ms)return 0;var id=setTimeout(()=>{delete timers[which];callUserCallback(()=>__emscripten_timeout(which,_emscripten_get_now()))},timeout_ms);timers[which]={id,timeout_ms};return 0};var _emscripten_date_now=()=>Date.now();var nowIsMonotonic=1;var checkWasiClock=clock_id=>clock_id>=0&&clock_id<=3;function _clock_time_get(clk_id,ignored_precision,ptime){ignored_precision=bigintToI53Checked(ignored_precision);ptime>>>=0;if(!checkWasiClock(clk_id)){return 28}var now;if(clk_id===0){now=_emscripten_date_now()}else if(nowIsMonotonic){now=_emscripten_get_now()}else{return 52}var nsec=Math.round(now*1e3*1e3);HEAP64[ptime>>>3>>>0]=BigInt(nsec);return 0}var getHeapMax=()=>4294901760;var alignMemory=(size,alignment)=>Math.ceil(size/alignment)*alignment;var growMemory=size=>{var oldHeapSize=wasmMemory.buffer.byteLength;var pages=(size-oldHeapSize+65535)/65536|0;try{wasmMemory.grow(pages);updateMemoryViews();return 1}catch(e){}};function _emscripten_resize_heap(requestedSize){requestedSize>>>=0;var oldSize=HEAPU8.length;var maxHeapSize=getHeapMax();if(requestedSize>maxHeapSize){return false}for(var cutDown=1;cutDown<=4;cutDown*=2){var overGrownHeapSize=oldSize*(1+.2/cutDown);overGrownHeapSize=Math.min(overGrownHeapSize,requestedSize+100663296);var newSize=Math.min(maxHeapSize,alignMemory(Math.max(requestedSize,overGrownHeapSize),65536));var replacement=growMemory(newSize);if(replacement){return true}}return false}var _fd_close=fd=>52;function _fd_seek(fd,offset,whence,newOffset){offset=bigintToI53Checked(offset);newOffset>>>=0;return 70}var printCharBuffers=[null,[],[]];var printChar=(stream,curr)=>{var buffer=printCharBuffers[stream];if(curr===0||curr===10){(stream===1?out:err)(UTF8ArrayToString(buffer));buffer.length=0}else{buffer.push(curr)}};function _fd_write(fd,iov,iovcnt,pnum){iov>>>=0;iovcnt>>>=0;pnum>>>=0;var num=0;for(var i=0;i<iovcnt;i++){var ptr=HEAPU32[iov>>>2>>>0];var len=HEAPU32[iov+4>>>2>>>0];iov+=8;for(var j=0;j<len;j++){printChar(fd,HEAPU8[ptr+j>>>0])}num+=len}HEAPU32[pnum>>>2>>>0]=num;return 0}{if(Module["noExitRuntime"])noExitRuntime=Module["noExitRuntime"];if(Module["print"])out=Module["print"];if(Module["printErr"])err=Module["printErr"];if(Module["wasmBinary"])wasmBinary=Module["wasmBinary"];if(Module["arguments"])arguments_=Module["arguments"];if(Module["thisProgram"])thisProgram=Module["thisProgram"];if(Module["preInit"]){if(typeof Module["preInit"]=="function")Module["preInit"]=[Module["preInit"]];while(Module["preInit"].length>0){Module["preInit"].shift()()}}}var _zk_input_ptr,_zk_result_ptr,_zk_result_len,_zk_gzip_compress,_zk_gzip_decompress,_zk_deflate_compress,_zk_deflate_decompress,_zk_zlib_compress,_zk_zlib_decompress,_zk_crc32,_zk_lz4_compress,_zk_lz4_decompress,_zk_zstd_compress,_zk_zstd_decompress,_zk_brotli_compress,_zk_brotli_decompress,_zk_snappy_compress,_zk_snappy_decompress,_zk_zstd_max_compress,_zk_set_aux,_zk_zstd_train_dict,_zk_zstd_compress_dict,_zk_zstd_decompress_dict,_zk_lzma_compress,_zk_lzma_decompress,_zk_xz_ok,_zk_xz_compress,_zk_xz_decompress,_zk_lzma2_decompress,_zk_bzip2_compress,_zk_bzip2_decompress,_zk_qoi_encode,_zk_qoi_decode,_zk_frame_delta_encode,_zk_frame_delta_decode,__emscripten_timeout,memory,__indirect_function_table,wasmMemory;function assignWasmExports(wasmExports){_zk_input_ptr=Module["_zk_input_ptr"]=wasmExports["n"];_zk_result_ptr=Module["_zk_result_ptr"]=wasmExports["o"];_zk_result_len=Module["_zk_result_len"]=wasmExports["p"];_zk_gzip_compress=Module["_zk_gzip_compress"]=wasmExports["q"];_zk_gzip_decompress=Module["_zk_gzip_decompress"]=wasmExports["r"];_zk_deflate_compress=Module["_zk_deflate_compress"]=wasmExports["s"];_zk_deflate_decompress=Module["_zk_deflate_decompress"]=wasmExports["t"];_zk_zlib_compress=Module["_zk_zlib_compress"]=wasmExports["u"];_zk_zlib_decompress=Module["_zk_zlib_decompress"]=wasmExports["v"];_zk_crc32=Module["_zk_crc32"]=wasmExports["w"];_zk_lz4_compress=Module["_zk_lz4_compress"]=wasmExports["x"];_zk_lz4_decompress=Module["_zk_lz4_decompress"]=wasmExports["y"];_zk_zstd_compress=Module["_zk_zstd_compress"]=wasmExports["z"];_zk_zstd_decompress=Module["_zk_zstd_decompress"]=wasmExports["A"];_zk_brotli_compress=Module["_zk_brotli_compress"]=wasmExports["B"];_zk_brotli_decompress=Module["_zk_brotli_decompress"]=wasmExports["C"];_zk_snappy_compress=Module["_zk_snappy_compress"]=wasmExports["D"];_zk_snappy_decompress=Module["_zk_snappy_decompress"]=wasmExports["E"];_zk_zstd_max_compress=Module["_zk_zstd_max_compress"]=wasmExports["F"];_zk_set_aux=Module["_zk_set_aux"]=wasmExports["G"];_zk_zstd_train_dict=Module["_zk_zstd_train_dict"]=wasmExports["H"];_zk_zstd_compress_dict=Module["_zk_zstd_compress_dict"]=wasmExports["I"];_zk_zstd_decompress_dict=Module["_zk_zstd_decompress_dict"]=wasmExports["J"];_zk_lzma_compress=Module["_zk_lzma_compress"]=wasmExports["K"];_zk_lzma_decompress=Module["_zk_lzma_decompress"]=wasmExports["L"];_zk_xz_ok=Module["_zk_xz_ok"]=wasmExports["M"];_zk_xz_compress=Module["_zk_xz_compress"]=wasmExports["N"];_zk_xz_decompress=Module["_zk_xz_decompress"]=wasmExports["O"];_zk_lzma2_decompress=Module["_zk_lzma2_decompress"]=wasmExports["P"];_zk_bzip2_compress=Module["_zk_bzip2_compress"]=wasmExports["Q"];_zk_bzip2_decompress=Module["_zk_bzip2_decompress"]=wasmExports["R"];_zk_qoi_encode=Module["_zk_qoi_encode"]=wasmExports["S"];_zk_qoi_decode=Module["_zk_qoi_decode"]=wasmExports["T"];_zk_frame_delta_encode=Module["_zk_frame_delta_encode"]=wasmExports["U"];_zk_frame_delta_decode=Module["_zk_frame_delta_decode"]=wasmExports["V"];__emscripten_timeout=wasmExports["W"];memory=wasmMemory=wasmExports["l"];__indirect_function_table=wasmExports["__indirect_function_table"]}var wasmImports={a:___assert_fail,f:__abort_js,e:__emscripten_runtime_keepalive_clear,k:__setitimer_js,h:_clock_time_get,c:_emscripten_resize_heap,b:_exit,j:_fd_close,g:_fd_seek,i:_fd_write,d:_proc_exit};function applySignatureConversions(wasmExports){wasmExports=Object.assign({},wasmExports);var makeWrapper_pp=f=>a0=>f(a0)>>>0;var makeWrapper_p=f=>()=>f()>>>0;wasmExports["_emscripten_stack_alloc"]=makeWrapper_pp(wasmExports["_emscripten_stack_alloc"]);wasmExports["emscripten_stack_get_current"]=makeWrapper_p(wasmExports["emscripten_stack_get_current"]);return wasmExports}function run(){preRun();function doRun(){Module["calledRun"]=true;if(ABORT)return;initRuntime();readyPromiseResolve?.(Module);Module["onRuntimeInitialized"]?.();postRun()}if(Module["setStatus"]){Module["setStatus"]("Running...");setTimeout(()=>{setTimeout(()=>Module["setStatus"](""),1);doRun()},1)}else{doRun()}}var wasmExports;wasmExports=await (createWasm());run();if(runtimeInitialized){moduleRtn=Module}else{moduleRtn=new Promise((resolve,reject)=>{readyPromiseResolve=resolve;readyPromiseReject=reject})}
|
|
2
|
+
;return moduleRtn}export default ZipKitModule;
|
|
Binary file
|