@stll/docx-core 0.39.2 → 0.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/archive-yBR7X-Qc.js +456 -0
- package/dist/errors-Dm3jsb5q.d.ts +57 -0
- package/dist/format-DXPXB02u.js +378 -0
- package/dist/index.d.ts +0 -7
- package/dist/index.js +106 -193
- package/dist/zip/archive.d.ts +114 -0
- package/dist/zip/archive.js +3 -0
- package/dist/zip/stream.d.ts +30 -0
- package/dist/zip/stream.js +117 -0
- package/package.json +10 -6
- package/dist/zip/writeZipPart.d.ts +0 -10
- package/dist/zip/writeZipPart.js +0 -16
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
import { Result, TaggedError } from "better-result";
|
|
2
|
+
import { encodeUtf8 } from "@stll/utf8-boundaries";
|
|
3
|
+
// src/zip/codec.ts
|
|
4
|
+
/**
|
|
5
|
+
* The platform's DEFLATE and CRC-32.
|
|
6
|
+
*
|
|
7
|
+
* Bun and Node.js expose native zlib through `process.getBuiltinModule`, which
|
|
8
|
+
* needs no import a browser bundler would have to resolve. Everywhere else
|
|
9
|
+
* (browsers, web workers, and runtimes too old for `getBuiltinModule`) uses
|
|
10
|
+
* `CompressionStream` / `DecompressionStream` and a table CRC-32. Runtimes
|
|
11
|
+
* whose streams lack `"deflate-raw"` get the same raw DEFLATE data framed as
|
|
12
|
+
* gzip: a fixed ten-byte header before it and the entry's CRC-32 and size,
|
|
13
|
+
* known from the central directory, after it.
|
|
14
|
+
*/
|
|
15
|
+
const isNativeZlib = (value) => typeof value === "object" && value !== null && "inflateRawSync" in value && typeof value.inflateRawSync === "function" && "deflateRawSync" in value && typeof value.deflateRawSync === "function";
|
|
16
|
+
const nativeZlibCrc32 = (zlib) => {
|
|
17
|
+
if (!("crc32" in zlib) || typeof zlib.crc32 !== "function") return null;
|
|
18
|
+
const { crc32 } = zlib;
|
|
19
|
+
return (data, previous) => crc32(data, previous);
|
|
20
|
+
};
|
|
21
|
+
const loadNativeZlib = () => {
|
|
22
|
+
const runtimeProcess = Reflect.get(globalThis, "process");
|
|
23
|
+
if (typeof runtimeProcess !== "object" || runtimeProcess === null || !("getBuiltinModule" in runtimeProcess) || typeof runtimeProcess.getBuiltinModule !== "function") return null;
|
|
24
|
+
const zlib = runtimeProcess.getBuiltinModule("node:zlib");
|
|
25
|
+
return isNativeZlib(zlib) ? zlib : null;
|
|
26
|
+
};
|
|
27
|
+
const loadBunCrc32 = () => {
|
|
28
|
+
const bun = Reflect.get(globalThis, "Bun");
|
|
29
|
+
if (typeof bun !== "object" || bun === null || !("hash" in bun)) return null;
|
|
30
|
+
const { hash } = bun;
|
|
31
|
+
if (typeof hash !== "function" || !("crc32" in hash) || typeof hash.crc32 !== "function") return null;
|
|
32
|
+
const { crc32 } = hash;
|
|
33
|
+
return (data, previous) => crc32(data, previous);
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* A copy of `bytes` in a new `ArrayBuffer` of exactly its length. Node.js
|
|
37
|
+
* `Buffer#slice` returns a view into a shared pool, so copies never go
|
|
38
|
+
* through `slice`.
|
|
39
|
+
*/
|
|
40
|
+
const copyBytes = (bytes) => new Uint8Array(bytes);
|
|
41
|
+
/** `bytes` backed by an `ArrayBuffer` of exactly its length. */
|
|
42
|
+
const exactBytes = (bytes) => {
|
|
43
|
+
const { buffer } = bytes;
|
|
44
|
+
return buffer instanceof ArrayBuffer && bytes.byteOffset === 0 && bytes.byteLength === buffer.byteLength ? new Uint8Array(buffer) : copyBytes(bytes);
|
|
45
|
+
};
|
|
46
|
+
let crcTable = null;
|
|
47
|
+
const tableCrc32 = (data, previous = 0) => {
|
|
48
|
+
if (crcTable === null) {
|
|
49
|
+
crcTable = /* @__PURE__ */ new Uint32Array(256);
|
|
50
|
+
for (let index = 0; index < 256; index++) {
|
|
51
|
+
let value = index;
|
|
52
|
+
for (let bit = 0; bit < 8; bit++) value = value & 1 ? 3988292384 ^ value >>> 1 : value >>> 1;
|
|
53
|
+
crcTable[index] = value >>> 0;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const table = crcTable;
|
|
57
|
+
let crc = ~previous >>> 0;
|
|
58
|
+
for (const byte of data) crc = table[(crc ^ byte) & 255] ^ crc >>> 8;
|
|
59
|
+
return ~crc >>> 0;
|
|
60
|
+
};
|
|
61
|
+
const BUFFER_TOO_LARGE = "ERR_BUFFER_TOO_LARGE";
|
|
62
|
+
const isBufferTooLarge = (error) => typeof error === "object" && error !== null && "code" in error && error.code === BUFFER_TOO_LARGE;
|
|
63
|
+
const shortOf = (size) => ({
|
|
64
|
+
type: "corrupt",
|
|
65
|
+
cause: /* @__PURE__ */ new RangeError(`Entry inflates short of its declared ${size} bytes`)
|
|
66
|
+
});
|
|
67
|
+
const nativeCodec = (zlib) => ({
|
|
68
|
+
inflate: (data, { size }) => {
|
|
69
|
+
const inflated = Result.try(() => zlib.inflateRawSync(data, { maxOutputLength: Math.max(1, size) }));
|
|
70
|
+
if (Result.isError(inflated)) {
|
|
71
|
+
const cause = inflated.error.cause;
|
|
72
|
+
return Promise.resolve(isBufferTooLarge(cause) ? { type: "overflow" } : {
|
|
73
|
+
type: "corrupt",
|
|
74
|
+
cause
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
const bytes = inflated.value;
|
|
78
|
+
if (bytes.byteLength > size) return Promise.resolve({ type: "overflow" });
|
|
79
|
+
if (bytes.byteLength < size) return Promise.resolve(shortOf(size));
|
|
80
|
+
return Promise.resolve({
|
|
81
|
+
type: "ok",
|
|
82
|
+
bytes: exactBytes(bytes)
|
|
83
|
+
});
|
|
84
|
+
},
|
|
85
|
+
deflate: (data, level) => Promise.resolve(exactBytes(zlib.deflateRawSync(data, { level }))),
|
|
86
|
+
crc32: loadBunCrc32() ?? nativeZlibCrc32(zlib) ?? tableCrc32
|
|
87
|
+
});
|
|
88
|
+
const concatChunks = (chunks, length) => {
|
|
89
|
+
const merged = new Uint8Array(length);
|
|
90
|
+
let offset = 0;
|
|
91
|
+
for (const chunk of chunks) {
|
|
92
|
+
merged.set(chunk, offset);
|
|
93
|
+
offset += chunk.byteLength;
|
|
94
|
+
}
|
|
95
|
+
return merged;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Feed `data` through a transform without awaiting the write, so the reader
|
|
99
|
+
* drains the output while the input is still being written. The write
|
|
100
|
+
* settles with the readable side; its rejection carries the same failure the
|
|
101
|
+
* read loop reports, so it is observed here rather than left unhandled.
|
|
102
|
+
*/
|
|
103
|
+
const pipeBytes = (transform, chunks) => {
|
|
104
|
+
const writer = transform.writable.getWriter();
|
|
105
|
+
const write = async () => {
|
|
106
|
+
for (const chunk of chunks) await writer.write(exactBytes(chunk));
|
|
107
|
+
await writer.close();
|
|
108
|
+
};
|
|
109
|
+
write().catch(() => {});
|
|
110
|
+
return transform.readable.getReader();
|
|
111
|
+
};
|
|
112
|
+
/** Whether this runtime's streams accept `"deflate-raw"`. */
|
|
113
|
+
const detectFraming = () => Result.isOk(Result.try(() => new DecompressionStream("deflate-raw"))) ? "deflate-raw" : "gzip";
|
|
114
|
+
const GZIP_HEADER = Uint8Array.of(31, 139, 8, 0, 0, 0, 0, 0, 0, 255);
|
|
115
|
+
const GZIP_HEADER_SIZE = GZIP_HEADER.byteLength;
|
|
116
|
+
const GZIP_TRAILER_SIZE = 8;
|
|
117
|
+
const gzipTrailer = ({ size, crc32 }) => {
|
|
118
|
+
const trailer = new Uint8Array(GZIP_TRAILER_SIZE);
|
|
119
|
+
const view = new DataView(trailer.buffer);
|
|
120
|
+
view.setUint32(0, crc32, true);
|
|
121
|
+
view.setUint32(4, size % 4294967296, true);
|
|
122
|
+
return trailer;
|
|
123
|
+
};
|
|
124
|
+
const streamInflate = async (framing, data, expected) => {
|
|
125
|
+
const { size } = expected;
|
|
126
|
+
const reader = pipeBytes(new DecompressionStream(framing), framing === "gzip" ? [
|
|
127
|
+
GZIP_HEADER,
|
|
128
|
+
data,
|
|
129
|
+
gzipTrailer(expected)
|
|
130
|
+
] : [data]);
|
|
131
|
+
const bytes = new Uint8Array(size);
|
|
132
|
+
let offset = 0;
|
|
133
|
+
const read = await Result.tryPromise(async () => {
|
|
134
|
+
for (;;) {
|
|
135
|
+
const { done, value } = await reader.read();
|
|
136
|
+
if (done) return "ended";
|
|
137
|
+
if (offset + value.byteLength > size) {
|
|
138
|
+
await reader.cancel();
|
|
139
|
+
return "overflow";
|
|
140
|
+
}
|
|
141
|
+
bytes.set(value, offset);
|
|
142
|
+
offset += value.byteLength;
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
if (Result.isError(read)) return {
|
|
146
|
+
type: "corrupt",
|
|
147
|
+
cause: read.error.cause
|
|
148
|
+
};
|
|
149
|
+
if (read.value === "overflow") return { type: "overflow" };
|
|
150
|
+
if (offset < size) return shortOf(size);
|
|
151
|
+
return {
|
|
152
|
+
type: "ok",
|
|
153
|
+
bytes
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
const streamDeflate = async (framing, data) => {
|
|
157
|
+
const reader = pipeBytes(new CompressionStream(framing), [data]);
|
|
158
|
+
const chunks = [];
|
|
159
|
+
let length = 0;
|
|
160
|
+
for (;;) {
|
|
161
|
+
const { done, value } = await reader.read();
|
|
162
|
+
if (done) break;
|
|
163
|
+
chunks.push(value);
|
|
164
|
+
length += value.byteLength;
|
|
165
|
+
}
|
|
166
|
+
const output = concatChunks(chunks, length);
|
|
167
|
+
return framing === "gzip" ? output.slice(GZIP_HEADER_SIZE, output.byteLength - GZIP_TRAILER_SIZE) : output;
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* A codec over the web compression streams with the given framing.
|
|
171
|
+
* `CompressionStream` has no level parameter; it writes the platform's
|
|
172
|
+
* default level.
|
|
173
|
+
*/
|
|
174
|
+
const streamZipCodec = (framing) => ({
|
|
175
|
+
inflate: async (data, expected) => await streamInflate(framing, data, expected),
|
|
176
|
+
deflate: async (data) => await streamDeflate(framing, data),
|
|
177
|
+
crc32: tableCrc32
|
|
178
|
+
});
|
|
179
|
+
let webCodec = null;
|
|
180
|
+
/** The web compression streams, in the framing this runtime supports. */
|
|
181
|
+
const webZipCodec = () => {
|
|
182
|
+
webCodec ??= streamZipCodec(detectFraming());
|
|
183
|
+
return webCodec;
|
|
184
|
+
};
|
|
185
|
+
let platformCodec = null;
|
|
186
|
+
/** Native zlib where the runtime has it, the web streams otherwise. */
|
|
187
|
+
const platformZipCodec = () => {
|
|
188
|
+
if (platformCodec === null) {
|
|
189
|
+
const zlib = loadNativeZlib();
|
|
190
|
+
platformCodec = zlib === null ? webZipCodec() : nativeCodec(zlib);
|
|
191
|
+
}
|
|
192
|
+
return platformCodec;
|
|
193
|
+
};
|
|
194
|
+
// src/zip/errors.ts
|
|
195
|
+
const ZipErrorBase = TaggedError("ZipError");
|
|
196
|
+
/** A ZIP archive or entry the module refuses to read or write. */
|
|
197
|
+
var ZipError = class extends ZipErrorBase {};
|
|
198
|
+
// src/zip/format.ts
|
|
199
|
+
/** ZIP record layouts (APPNOTE 6.3.10) shared by the readers and writers. */
|
|
200
|
+
const LOCAL_FILE_HEADER_SIGNATURE = 67324752;
|
|
201
|
+
const CENTRAL_DIRECTORY_SIGNATURE = 33639248;
|
|
202
|
+
const END_OF_CENTRAL_DIRECTORY_SIGNATURE = 101010256;
|
|
203
|
+
const ZIP64_END_OF_CENTRAL_DIRECTORY_SIGNATURE = 101075792;
|
|
204
|
+
const ZIP64_END_LOCATOR_SIGNATURE = 117853008;
|
|
205
|
+
const DATA_DESCRIPTOR_SIGNATURE = 134695760;
|
|
206
|
+
const FLAG_UTF8_NAME = 2048;
|
|
207
|
+
/** A 32-bit field at this value defers to the Zip64 extra field. */
|
|
208
|
+
const UINT32_SENTINEL = 4294967295;
|
|
209
|
+
/** A 16-bit count at this value defers to the Zip64 end record. */
|
|
210
|
+
const UINT16_SENTINEL = 65535;
|
|
211
|
+
const VERSION_DEFAULT = 20;
|
|
212
|
+
const VERSION_ZIP64 = 45;
|
|
213
|
+
const DOS_DIRECTORY_ATTRIBUTE = 16;
|
|
214
|
+
const DOS_EPOCH_YEAR = 1980;
|
|
215
|
+
const DOS_LAST_YEAR = 2107;
|
|
216
|
+
/** `date` as DOS fields in UTC, clamped to the range DOS dates can hold. */
|
|
217
|
+
const toDosDateTime = (date) => {
|
|
218
|
+
const year = date.getUTCFullYear();
|
|
219
|
+
if (Number.isNaN(year) || year < DOS_EPOCH_YEAR) return {
|
|
220
|
+
date: 33,
|
|
221
|
+
time: 0
|
|
222
|
+
};
|
|
223
|
+
if (year > DOS_LAST_YEAR) return {
|
|
224
|
+
date: 65439,
|
|
225
|
+
time: 49021
|
|
226
|
+
};
|
|
227
|
+
return {
|
|
228
|
+
date: year - DOS_EPOCH_YEAR << 9 | date.getUTCMonth() + 1 << 5 | date.getUTCDate(),
|
|
229
|
+
time: date.getUTCHours() << 11 | date.getUTCMinutes() << 5 | date.getUTCSeconds() >> 1
|
|
230
|
+
};
|
|
231
|
+
};
|
|
232
|
+
/** DOS fields as a UTC `Date`; out-of-range fields roll over like `Date.UTC`. */
|
|
233
|
+
const fromDosDateTime = ({ date, time }) => new Date(Date.UTC(DOS_EPOCH_YEAR + (date >> 9), (date >> 5 & 15) - 1, date & 31, time >> 11, time >> 5 & 63, (time & 31) * 2));
|
|
234
|
+
/** The reproducible timestamp written for new entries: 2000-01-01T00:00Z. */
|
|
235
|
+
const FIXED_DOS_DATE_TIME = toDosDateTime(new Date(Date.UTC(2e3, 0, 1)));
|
|
236
|
+
/** Entry name bytes and the general-purpose flag they need. */
|
|
237
|
+
const encodeEntryName = (path) => {
|
|
238
|
+
const bytes = encodeUtf8(path);
|
|
239
|
+
return {
|
|
240
|
+
bytes,
|
|
241
|
+
flags: bytes.every((byte) => byte < 128) ? 0 : FLAG_UTF8_NAME
|
|
242
|
+
};
|
|
243
|
+
};
|
|
244
|
+
/** Whether `path` is a relative, forward-slash name with no `..` segment. */
|
|
245
|
+
const isSafeZipPath = (path) => {
|
|
246
|
+
if (path.length === 0 || path.startsWith("/")) return false;
|
|
247
|
+
if (path.includes("\\") || path.includes("\0")) return false;
|
|
248
|
+
if (/^[A-Za-z]:/u.test(path)) return false;
|
|
249
|
+
return !path.split("/").some((segment) => segment === "..");
|
|
250
|
+
};
|
|
251
|
+
const writeCommonFields = (view, offset, record) => {
|
|
252
|
+
view.setUint16(offset, record.flags, true);
|
|
253
|
+
view.setUint16(offset + 2, record.method, true);
|
|
254
|
+
view.setUint16(offset + 4, record.dateTime.time, true);
|
|
255
|
+
view.setUint16(offset + 6, record.dateTime.date, true);
|
|
256
|
+
view.setUint32(offset + 8, record.crc32, true);
|
|
257
|
+
};
|
|
258
|
+
const needsZip64 = (value) => value >= UINT32_SENTINEL;
|
|
259
|
+
/**
|
|
260
|
+
* A local file header. Sizes go in the header unless the entry streams them
|
|
261
|
+
* in a data descriptor; a header that carries sizes of 4 GiB or more puts
|
|
262
|
+
* both in a Zip64 extra field, as APPNOTE 4.5.3 requires.
|
|
263
|
+
*/
|
|
264
|
+
const encodeLocalHeader = (record) => {
|
|
265
|
+
const streamed = (record.flags & 8) !== 0;
|
|
266
|
+
const zip64 = !streamed && (needsZip64(record.compressedSize) || needsZip64(record.uncompressedSize));
|
|
267
|
+
const extraLength = zip64 ? 20 : 0;
|
|
268
|
+
const bytes = new Uint8Array(30 + record.name.byteLength + extraLength);
|
|
269
|
+
const view = new DataView(bytes.buffer);
|
|
270
|
+
view.setUint32(0, LOCAL_FILE_HEADER_SIGNATURE, true);
|
|
271
|
+
view.setUint16(4, zip64 ? VERSION_ZIP64 : VERSION_DEFAULT, true);
|
|
272
|
+
writeCommonFields(view, 6, record);
|
|
273
|
+
if (streamed) view.setUint32(14, 0, true);
|
|
274
|
+
else {
|
|
275
|
+
view.setUint32(18, zip64 ? UINT32_SENTINEL : record.compressedSize, true);
|
|
276
|
+
view.setUint32(22, zip64 ? UINT32_SENTINEL : record.uncompressedSize, true);
|
|
277
|
+
}
|
|
278
|
+
view.setUint16(26, record.name.byteLength, true);
|
|
279
|
+
view.setUint16(28, extraLength, true);
|
|
280
|
+
bytes.set(record.name, 30);
|
|
281
|
+
if (zip64) {
|
|
282
|
+
const extra = 30 + record.name.byteLength;
|
|
283
|
+
view.setUint16(extra, 1, true);
|
|
284
|
+
view.setUint16(extra + 2, 16, true);
|
|
285
|
+
view.setBigUint64(extra + 4, BigInt(record.uncompressedSize), true);
|
|
286
|
+
view.setBigUint64(extra + 12, BigInt(record.compressedSize), true);
|
|
287
|
+
}
|
|
288
|
+
return bytes;
|
|
289
|
+
};
|
|
290
|
+
/**
|
|
291
|
+
* The data descriptor that follows a streamed entry. Sizes of 4 GiB or more
|
|
292
|
+
* are written as 8-byte fields.
|
|
293
|
+
*/
|
|
294
|
+
const encodeDataDescriptor = (record) => {
|
|
295
|
+
const zip64 = needsZip64(record.compressedSize) || needsZip64(record.uncompressedSize);
|
|
296
|
+
const bytes = new Uint8Array(zip64 ? 24 : 16);
|
|
297
|
+
const view = new DataView(bytes.buffer);
|
|
298
|
+
view.setUint32(0, DATA_DESCRIPTOR_SIGNATURE, true);
|
|
299
|
+
view.setUint32(4, record.crc32, true);
|
|
300
|
+
if (zip64) {
|
|
301
|
+
view.setBigUint64(8, BigInt(record.compressedSize), true);
|
|
302
|
+
view.setBigUint64(16, BigInt(record.uncompressedSize), true);
|
|
303
|
+
} else {
|
|
304
|
+
view.setUint32(8, record.compressedSize, true);
|
|
305
|
+
view.setUint32(12, record.uncompressedSize, true);
|
|
306
|
+
}
|
|
307
|
+
return bytes;
|
|
308
|
+
};
|
|
309
|
+
/**
|
|
310
|
+
* A central directory header. Each field of 4 GiB or more is written as the
|
|
311
|
+
* sentinel and carried, in APPNOTE order, by a Zip64 extra field.
|
|
312
|
+
*/
|
|
313
|
+
const encodeCentralHeader = (record, localOffset) => {
|
|
314
|
+
const overflow = [
|
|
315
|
+
record.uncompressedSize,
|
|
316
|
+
record.compressedSize,
|
|
317
|
+
localOffset
|
|
318
|
+
].filter((value) => needsZip64(value));
|
|
319
|
+
const extraLength = overflow.length === 0 ? 0 : 4 + overflow.length * 8;
|
|
320
|
+
const bytes = new Uint8Array(46 + record.name.byteLength + extraLength);
|
|
321
|
+
const view = new DataView(bytes.buffer);
|
|
322
|
+
const version = extraLength === 0 ? VERSION_DEFAULT : VERSION_ZIP64;
|
|
323
|
+
view.setUint32(0, CENTRAL_DIRECTORY_SIGNATURE, true);
|
|
324
|
+
view.setUint16(4, version, true);
|
|
325
|
+
view.setUint16(6, version, true);
|
|
326
|
+
writeCommonFields(view, 8, record);
|
|
327
|
+
view.setUint32(20, needsZip64(record.compressedSize) ? UINT32_SENTINEL : record.compressedSize, true);
|
|
328
|
+
view.setUint32(24, needsZip64(record.uncompressedSize) ? UINT32_SENTINEL : record.uncompressedSize, true);
|
|
329
|
+
view.setUint16(28, record.name.byteLength, true);
|
|
330
|
+
view.setUint16(30, extraLength, true);
|
|
331
|
+
view.setUint32(38, record.directory ? DOS_DIRECTORY_ATTRIBUTE : 0, true);
|
|
332
|
+
view.setUint32(42, needsZip64(localOffset) ? UINT32_SENTINEL : localOffset, true);
|
|
333
|
+
bytes.set(record.name, 46);
|
|
334
|
+
if (extraLength !== 0) {
|
|
335
|
+
let field = 46 + record.name.byteLength;
|
|
336
|
+
view.setUint16(field, 1, true);
|
|
337
|
+
view.setUint16(field + 2, overflow.length * 8, true);
|
|
338
|
+
field += 4;
|
|
339
|
+
for (const value of overflow) {
|
|
340
|
+
view.setBigUint64(field, BigInt(value), true);
|
|
341
|
+
field += 8;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
return bytes;
|
|
345
|
+
};
|
|
346
|
+
/**
|
|
347
|
+
* The end-of-central-directory record, preceded by the Zip64 end record and
|
|
348
|
+
* its locator when a count, size or offset does not fit the classic fields.
|
|
349
|
+
*/
|
|
350
|
+
const encodeEndOfCentralDirectory = ({ entryCount, offset, size }) => {
|
|
351
|
+
const zip64 = entryCount >= 65535 || needsZip64(offset) || needsZip64(size);
|
|
352
|
+
const zip64Length = zip64 ? 76 : 0;
|
|
353
|
+
const bytes = new Uint8Array(zip64Length + 22);
|
|
354
|
+
const view = new DataView(bytes.buffer);
|
|
355
|
+
if (zip64) {
|
|
356
|
+
const recordOffset = offset + size;
|
|
357
|
+
view.setUint32(0, ZIP64_END_OF_CENTRAL_DIRECTORY_SIGNATURE, true);
|
|
358
|
+
view.setBigUint64(4, BigInt(44), true);
|
|
359
|
+
view.setUint16(12, VERSION_ZIP64, true);
|
|
360
|
+
view.setUint16(14, VERSION_ZIP64, true);
|
|
361
|
+
view.setBigUint64(24, BigInt(entryCount), true);
|
|
362
|
+
view.setBigUint64(32, BigInt(entryCount), true);
|
|
363
|
+
view.setBigUint64(40, BigInt(size), true);
|
|
364
|
+
view.setBigUint64(48, BigInt(offset), true);
|
|
365
|
+
view.setUint32(56, ZIP64_END_LOCATOR_SIGNATURE, true);
|
|
366
|
+
view.setBigUint64(64, BigInt(recordOffset), true);
|
|
367
|
+
view.setUint32(72, 1, true);
|
|
368
|
+
}
|
|
369
|
+
const end = zip64Length;
|
|
370
|
+
view.setUint32(end, END_OF_CENTRAL_DIRECTORY_SIGNATURE, true);
|
|
371
|
+
const count = Math.min(entryCount, UINT16_SENTINEL);
|
|
372
|
+
view.setUint16(end + 8, count, true);
|
|
373
|
+
view.setUint16(end + 10, count, true);
|
|
374
|
+
view.setUint32(end + 12, needsZip64(size) ? UINT32_SENTINEL : size, true);
|
|
375
|
+
view.setUint32(end + 16, needsZip64(offset) ? UINT32_SENTINEL : offset, true);
|
|
376
|
+
return bytes;
|
|
377
|
+
};
|
|
378
|
+
export { ZipError as _, UINT16_SENTINEL as a, ZIP64_END_OF_CENTRAL_DIRECTORY_SIGNATURE as c, encodeEndOfCentralDirectory as d, encodeEntryName as f, toDosDateTime as g, isSafeZipPath as h, LOCAL_FILE_HEADER_SIGNATURE as i, encodeCentralHeader as l, fromDosDateTime as m, END_OF_CENTRAL_DIRECTORY_SIGNATURE as n, UINT32_SENTINEL as o, encodeLocalHeader as p, FIXED_DOS_DATE_TIME as r, ZIP64_END_LOCATOR_SIGNATURE as s, CENTRAL_DIRECTORY_SIGNATURE as t, encodeDataDescriptor as u, copyBytes as v, platformZipCodec as y };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { B as finalizeParagraphFormatting, Dn as Run, E as Style, H as setDocumentBodyComments, K as BlockContent, On as RunContent, Pn as SectionProperties, Q as BreakContent, V as isCanonicallyEmptyParagraphFormatting, Vr as NumberingDefinitions, Xn as TableCell, Yn as Table, _n as PositionalTab, cr as TextContent, ct as DocumentBackground, dn as Paragraph, fn as ParagraphContent, i as Document, ir as TableRow, lt as DocumentBackgroundDrawing, o as DocxConformanceClass, r as DOCX_CONFORMANCE_CLASSES, s as DocxPackage, ut as DocumentBody } from "./document-BWDHON3T.js";
|
|
2
2
|
import { TaggedErrorClass } from "better-result";
|
|
3
|
-
import JSZip from "jszip";
|
|
4
3
|
import { Buffer } from "node:buffer";
|
|
5
4
|
type LegalDocumentKind = "agreement" | "letter" | "memo" | "checklist" | "pleading" | "other";
|
|
6
5
|
type LegalNumberingProfile = "legal" | "none" | "checklist";
|
|
@@ -272,12 +271,6 @@ export declare const sanitizeXmlCharacters: (value: string) => string;
|
|
|
272
271
|
* runs merged, because ProseMirror has nowhere to carry it.
|
|
273
272
|
*/
|
|
274
273
|
export declare const requiresXmlSpacePreserve: (text: string) => boolean;
|
|
275
|
-
declare module "jszip" {
|
|
276
|
-
interface JSZipObject {
|
|
277
|
-
/** Chunked read of the entry content, missing from the published typings. */
|
|
278
|
-
internalStream(type: "uint8array"): JSZip.JSZipStreamHelper<Uint8Array>;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
274
|
export declare const DOCX_PACKAGE_ISSUE_CODES: {
|
|
282
275
|
readonly ArchiveBoundsExceeded: "archive_bounds_exceeded";
|
|
283
276
|
readonly InvalidArchive: "invalid_archive";
|