@bitbybit-dev/base 1.6.0-rc.0 → 1.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
1
  export class GlobalCDNProvider {
2
2
  }
3
- GlobalCDNProvider.BITBYBIT_CDN_URL = "https://git-cdn.bitbybit.dev/v1.6.0-rc.0";
3
+ GlobalCDNProvider.BITBYBIT_CDN_URL = "https://git-cdn.bitbybit.dev/v1.6.1";
@@ -319,7 +319,9 @@ export declare namespace Base {
319
319
  */
320
320
  of: number;
321
321
  /**
322
- * The indices of what is cut away, all at once.
322
+ * The indices of what is cut away, all at once. A solid tool that ends within the recipe's
323
+ * `tolerance` of a side of the solid's bounding box, as the half-spaces before it leave the
324
+ * solid, passes through that side.
323
325
  */
324
326
  tools: number[];
325
327
  }
@@ -345,6 +347,8 @@ export declare namespace Base {
345
347
  /**
346
348
  * A host solid with openings cut through it, such as a wall with its doors' and windows' holes.
347
349
  * The same as a difference, kept apart so an executor can cut openings through flat hosts in 2D.
350
+ * An opening that ends within the recipe's `tolerance` of a side of the host's bounding box passes
351
+ * through that side, so an opening as deep as its wall cuts through it however its placement rounds.
348
352
  * @beta
349
353
  */
350
354
  interface RecipeVoidsNode {
@@ -970,7 +974,10 @@ export declare namespace Base {
970
974
  millimetresPerUnit: number;
971
975
  /**
972
976
  * The distance below which two positions count as the same, in the recipe's units, as the
973
- * recipe's source measured it. An executor may use it where it compares positions, or not.
977
+ * recipe's source measured it. Every executor applies it to cuts: an opening of a `voids` step,
978
+ * or a solid tool of a `difference`, that ends within it of a side of the bounding box of what it
979
+ * cuts passes through that side. Elsewhere an executor may use it where it compares positions,
980
+ * or not.
974
981
  */
975
982
  tolerance: number;
976
983
  /**
@@ -1,2 +1,2 @@
1
1
  export declare function isGzip(bytes: Uint8Array): boolean;
2
- export declare function gunzipped(bytes: Uint8Array): Uint8Array;
2
+ export declare function gunzipped(bytes: Uint8Array, limit?: number): Uint8Array;
@@ -1,5 +1,6 @@
1
1
  import { crc32 } from "./crc32";
2
2
  import { inflateRaw } from "./inflate";
3
+ import { MOST_INFLATED_BYTES } from "./inflate.constants";
3
4
  import { BYTE_BITS, UINT16_BYTES, UINT32_BYTES } from "./zip.constants";
4
5
  import { GZIP_COMMENT_FLAG, GZIP_DEFLATE_METHOD, GZIP_EXTRA_FLAG, GZIP_FLAGS_AT, GZIP_HEADER_CRC_FLAG, GZIP_HEADER_SIZE, GZIP_MAGIC_FIRST, GZIP_MAGIC_SECOND, GZIP_METHOD_AT, GZIP_NAME_FLAG, GZIP_TRAILER_SIZE, } from "./gzip.constants";
5
6
  function uint32(bytes, at) {
@@ -15,7 +16,7 @@ function afterText(bytes, from) {
15
16
  export function isGzip(bytes) {
16
17
  return bytes.length >= 2 && bytes[0] === GZIP_MAGIC_FIRST && bytes[1] === GZIP_MAGIC_SECOND;
17
18
  }
18
- export function gunzipped(bytes) {
19
+ export function gunzipped(bytes, limit = MOST_INFLATED_BYTES) {
19
20
  if (!isGzip(bytes) || bytes.length < GZIP_HEADER_SIZE + GZIP_TRAILER_SIZE) {
20
21
  throw new Error("The data is not gzip: it does not start with the gzip signature or is too short to hold its header");
21
22
  }
@@ -41,10 +42,7 @@ export function gunzipped(bytes) {
41
42
  throw new Error("The gzip header runs past the end of the data");
42
43
  }
43
44
  const size = uint32(bytes, end + UINT32_BYTES);
44
- const data = inflateRaw(bytes.subarray(start, end), size);
45
- if (data.length !== size) {
46
- throw new Error(`The gzip data holds ${data.length} bytes, not the ${size} its trailer records`);
47
- }
45
+ const data = inflateRaw(bytes.subarray(start, end), size, limit);
48
46
  if (crc32(data) !== uint32(bytes, end)) {
49
47
  throw new Error("The gzip data fails its CRC-32 check");
50
48
  }
@@ -34,6 +34,7 @@ export declare const REPEAT_ZERO_LONG_BITS = 7;
34
34
  export declare const REPEAT_ZERO_LONG_BASE = 11;
35
35
  export declare const INITIAL_OUTPUT: number;
36
36
  export declare const MOST_DEFLATE_RATIO = 1032;
37
+ export declare const MOST_INFLATED_BYTES = 1073741824;
37
38
  export declare const CODE_LENGTH_ORDER: Uint8Array<ArrayBuffer>;
38
39
  export declare const LENGTH_BASE: Uint16Array<ArrayBuffer>;
39
40
  export declare const LENGTH_EXTRA: Uint8Array<ArrayBuffer>;
@@ -34,6 +34,7 @@ export const REPEAT_ZERO_LONG_BITS = 7;
34
34
  export const REPEAT_ZERO_LONG_BASE = 11;
35
35
  export const INITIAL_OUTPUT = 1 << 16;
36
36
  export const MOST_DEFLATE_RATIO = 1032;
37
+ export const MOST_INFLATED_BYTES = 0x40000000;
37
38
  export const CODE_LENGTH_ORDER = Uint8Array.of(16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15);
38
39
  export const LENGTH_BASE = Uint16Array.of(3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258);
39
40
  export const LENGTH_EXTRA = Uint8Array.of(0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0);
@@ -1,3 +1,3 @@
1
1
  import type { HuffmanTable } from "../helper-types";
2
2
  export declare function huffmanTable(lengths: ArrayLike<number>): HuffmanTable;
3
- export declare function inflateRaw(data: Uint8Array, expectedSize?: number): Uint8Array;
3
+ export declare function inflateRaw(data: Uint8Array, expectedSize?: number, limit?: number): Uint8Array;
@@ -1,4 +1,4 @@
1
- import { BLOCK_TYPE_BITS, BYTE_BITS, CODE_LENGTH_BITS, CODE_LENGTH_ORDER, CODE_LENGTH_SYMBOLS, DISTANCE_BASE, DISTANCE_EXTRA, DISTANCE_SYMBOLS, DYNAMIC_BLOCK, END_OF_BLOCK, FIRST_LENGTH_SYMBOL, FIXED_BLOCK, FIXED_DISTANCE_BITS, FIXED_LITERAL_BITS, FIXED_LITERAL_ENDS, HCLEN_BASE, HCLEN_BITS, HDIST_BASE, HDIST_BITS, HLIT_BASE, HLIT_BITS, INITIAL_OUTPUT, MOST_DEFLATE_RATIO, LENGTH_BASE, LENGTH_EXTRA, LENGTH_MASK, LITERAL_LENGTH_SYMBOLS, MAX_CODE_BITS, REFILL_BELOW, REPEAT_PREVIOUS, REPEAT_PREVIOUS_BASE, REPEAT_PREVIOUS_BITS, REPEAT_ZERO_LONG_BASE, REPEAT_ZERO_LONG_BITS, REPEAT_ZERO_SHORT, REPEAT_ZERO_SHORT_BASE, REPEAT_ZERO_SHORT_BITS, STORED_BLOCK, STORED_HEADER_BYTES, STORED_LENGTH_BYTES, SYMBOL_SHIFT, UINT16_MASK, } from "./inflate.constants";
1
+ import { BLOCK_TYPE_BITS, BYTE_BITS, CODE_LENGTH_BITS, CODE_LENGTH_ORDER, CODE_LENGTH_SYMBOLS, DISTANCE_BASE, DISTANCE_EXTRA, DISTANCE_SYMBOLS, DYNAMIC_BLOCK, END_OF_BLOCK, FIRST_LENGTH_SYMBOL, FIXED_BLOCK, FIXED_DISTANCE_BITS, FIXED_LITERAL_BITS, FIXED_LITERAL_ENDS, HCLEN_BASE, HCLEN_BITS, HDIST_BASE, HDIST_BITS, HLIT_BASE, HLIT_BITS, INITIAL_OUTPUT, MOST_DEFLATE_RATIO, MOST_INFLATED_BYTES, LENGTH_BASE, LENGTH_EXTRA, LENGTH_MASK, LITERAL_LENGTH_SYMBOLS, MAX_CODE_BITS, REFILL_BELOW, REPEAT_PREVIOUS, REPEAT_PREVIOUS_BASE, REPEAT_PREVIOUS_BITS, REPEAT_ZERO_LONG_BASE, REPEAT_ZERO_LONG_BITS, REPEAT_ZERO_SHORT, REPEAT_ZERO_SHORT_BASE, REPEAT_ZERO_SHORT_BITS, STORED_BLOCK, STORED_HEADER_BYTES, STORED_LENGTH_BYTES, SYMBOL_SHIFT, UINT16_MASK, } from "./inflate.constants";
2
2
  function reversed(code, bits) {
3
3
  let result = 0;
4
4
  for (let bit = 0; bit < bits; bit++) {
@@ -50,14 +50,18 @@ function fixed() {
50
50
  return fixedTables;
51
51
  }
52
52
  class Inflater {
53
- constructor(data, expected) {
53
+ constructor(data, expected, limit) {
54
54
  this.data = data;
55
55
  this.expected = expected;
56
+ this.limit = limit;
56
57
  this.at = 0;
57
58
  this.bitBuffer = 0;
58
59
  this.bitCount = 0;
59
60
  this.size = 0;
60
- this.output = new Uint8Array(Math.min(expected !== null && expected !== void 0 ? expected : Math.max(INITIAL_OUTPUT, data.length * 2), data.length * MOST_DEFLATE_RATIO + INITIAL_OUTPUT));
61
+ if (expected !== undefined && expected > limit) {
62
+ throw new Error(`The deflate stream is said to hold ${expected} bytes, more than the ${limit} this reader inflates`);
63
+ }
64
+ this.output = new Uint8Array(Math.min(expected !== null && expected !== void 0 ? expected : Math.max(INITIAL_OUTPUT, data.length * 2), data.length * MOST_DEFLATE_RATIO + INITIAL_OUTPUT, limit));
61
65
  }
62
66
  run() {
63
67
  let last = 0;
@@ -118,14 +122,18 @@ class Inflater {
118
122
  return entry >> SYMBOL_SHIFT;
119
123
  }
120
124
  room(count) {
125
+ var _a;
121
126
  if (this.size + count <= this.output.length) {
122
127
  return;
123
128
  }
124
129
  if (this.expected !== undefined && this.size + count > this.expected) {
125
130
  throw new Error(`The deflate stream holds more than the ${this.expected} bytes expected`);
126
131
  }
132
+ if (this.size + count > this.limit) {
133
+ throw new Error(`The deflate stream inflates past the ${this.limit} bytes this reader inflates`);
134
+ }
127
135
  const wanted = Math.max(this.output.length * 2, this.size + count);
128
- const grown = new Uint8Array(this.expected === undefined ? wanted : Math.min(wanted, this.expected));
136
+ const grown = new Uint8Array(Math.min(wanted, (_a = this.expected) !== null && _a !== void 0 ? _a : this.limit));
129
137
  grown.set(this.output.subarray(0, this.size));
130
138
  this.output = grown;
131
139
  }
@@ -224,6 +232,6 @@ class Inflater {
224
232
  }
225
233
  }
226
234
  }
227
- export function inflateRaw(data, expectedSize) {
228
- return new Inflater(data, expectedSize).run();
235
+ export function inflateRaw(data, expectedSize, limit = MOST_INFLATED_BYTES) {
236
+ return new Inflater(data, expectedSize, limit).run();
229
237
  }
@@ -32,3 +32,11 @@ export declare const STORED_METHOD = 0;
32
32
  export declare const DEFLATED_METHOD = 8;
33
33
  export declare const UINT16_BYTES = 2;
34
34
  export declare const UINT32_BYTES = 4;
35
+ export declare const ZIP_VERSION = 20;
36
+ export declare const DOS_EPOCH_YEAR = 1980;
37
+ export declare const DOS_YEAR_SHIFT = 9;
38
+ export declare const DOS_MONTH_SHIFT = 5;
39
+ export declare const DOS_HOUR_SHIFT = 11;
40
+ export declare const DOS_MINUTE_SHIFT = 5;
41
+ export declare const DOS_SECONDS_PER_UNIT = 2;
42
+ export declare const ZIP_MIME_TYPE = "application/zip";
@@ -32,3 +32,11 @@ export const STORED_METHOD = 0;
32
32
  export const DEFLATED_METHOD = 8;
33
33
  export const UINT16_BYTES = 2;
34
34
  export const UINT32_BYTES = 4;
35
+ export const ZIP_VERSION = 20;
36
+ export const DOS_EPOCH_YEAR = 1980;
37
+ export const DOS_YEAR_SHIFT = 9;
38
+ export const DOS_MONTH_SHIFT = 5;
39
+ export const DOS_HOUR_SHIFT = 11;
40
+ export const DOS_MINUTE_SHIFT = 5;
41
+ export const DOS_SECONDS_PER_UNIT = 2;
42
+ export const ZIP_MIME_TYPE = "application/zip";
@@ -1,4 +1,8 @@
1
- import type { ZipEntry } from "../helper-types";
1
+ import type { DosDateTime, ZipEntry, ZipFile, ZipStoredRecord } from "../helper-types";
2
2
  export declare function isZip(bytes: Uint8Array): boolean;
3
3
  export declare function zipEntries(bytes: Uint8Array): ZipEntry[];
4
- export declare function zipEntryData(bytes: Uint8Array, entry: ZipEntry): Uint8Array;
4
+ export declare function zipEntryData(bytes: Uint8Array, entry: ZipEntry, limit?: number): Uint8Array;
5
+ export declare function dosDateTime(moment: Date): DosDateTime;
6
+ export declare function zipStoredParts<T>(records: readonly ZipStoredRecord<T>[], modified?: Date): (Uint8Array<ArrayBuffer> | T)[];
7
+ export declare function zipStored(files: readonly ZipFile[], modified?: Date): Uint8Array<ArrayBuffer>;
8
+ export declare function zipStoredBlob(files: readonly ZipFile[], modified?: Date): Blob;
@@ -1,6 +1,7 @@
1
1
  import { crc32 } from "./crc32";
2
2
  import { inflateRaw } from "./inflate";
3
- import { BYTE_BITS, CENTRAL_COMMENT_LENGTH, CENTRAL_COMPRESSED_SIZE, CENTRAL_CRC32, CENTRAL_EXTRA_LENGTH, CENTRAL_FLAGS, CENTRAL_HEADER_SIGNATURE, CENTRAL_HEADER_SIZE, CENTRAL_LOCAL_OFFSET, CENTRAL_METHOD, CENTRAL_NAME_LENGTH, CENTRAL_SIZE, DEFLATED_METHOD, ENCRYPTED_FLAG, END_DIRECTORY_OFFSET, END_DIRECTORY_SIZE, END_ENTRY_COUNT, END_OF_CENTRAL_SIGNATURE, END_OF_CENTRAL_SIZE, LOCAL_EXTRA_LENGTH, LOCAL_HEADER_SIGNATURE, LOCAL_HEADER_SIZE, LOCAL_NAME_LENGTH, LONGEST_ARCHIVE_COMMENT, STORED_METHOD, UINT16_BYTES, UINT32_BYTES, UTF8_NAME_FLAG, ZIP64_COUNT, ZIP64_SIZE, } from "./zip.constants";
3
+ import { MOST_INFLATED_BYTES } from "./inflate.constants";
4
+ import { BYTE_BITS, CENTRAL_COMMENT_LENGTH, CENTRAL_COMPRESSED_SIZE, CENTRAL_CRC32, CENTRAL_EXTRA_LENGTH, CENTRAL_FLAGS, CENTRAL_HEADER_SIGNATURE, CENTRAL_HEADER_SIZE, CENTRAL_LOCAL_OFFSET, CENTRAL_METHOD, CENTRAL_NAME_LENGTH, CENTRAL_SIZE, DEFLATED_METHOD, DOS_EPOCH_YEAR, DOS_HOUR_SHIFT, DOS_MINUTE_SHIFT, DOS_MONTH_SHIFT, DOS_SECONDS_PER_UNIT, DOS_YEAR_SHIFT, ENCRYPTED_FLAG, END_DIRECTORY_OFFSET, END_DIRECTORY_SIZE, END_ENTRY_COUNT, END_OF_CENTRAL_SIGNATURE, END_OF_CENTRAL_SIZE, LOCAL_EXTRA_LENGTH, LOCAL_HEADER_SIGNATURE, LOCAL_HEADER_SIZE, LOCAL_NAME_LENGTH, LONGEST_ARCHIVE_COMMENT, STORED_METHOD, UINT16_BYTES, UINT32_BYTES, UTF8_NAME_FLAG, ZIP64_COUNT, ZIP64_SIZE, ZIP_MIME_TYPE, ZIP_VERSION, } from "./zip.constants";
4
5
  const utf8 = new TextDecoder("utf-8");
5
6
  const windows1252 = new TextDecoder("windows-1252");
6
7
  function uint16(bytes, at) {
@@ -55,9 +56,24 @@ export function zipEntries(bytes) {
55
56
  });
56
57
  at += CENTRAL_HEADER_SIZE + nameLength + uint16(bytes, at + CENTRAL_EXTRA_LENGTH) + uint16(bytes, at + CENTRAL_COMMENT_LENGTH);
57
58
  }
59
+ refuseOverlappingEntries(entries, directory);
58
60
  return entries;
59
61
  }
60
- export function zipEntryData(bytes, entry) {
62
+ function refuseOverlappingEntries(entries, directory) {
63
+ const byOffset = [...entries].sort((first, second) => first.localOffset - second.localOffset);
64
+ for (let index = 0; index < byOffset.length; index++) {
65
+ const entry = byOffset[index];
66
+ const end = entry.localOffset + LOCAL_HEADER_SIZE + entry.compressedSize;
67
+ const next = byOffset[index + 1];
68
+ if (next !== undefined && end > next.localOffset) {
69
+ throw new Error(`The zip archive's entries ${entry.name} and ${next.name} share their data, which a zip bomb does and an archive never needs`);
70
+ }
71
+ if (end > directory) {
72
+ throw new Error(`${entry.name} runs into the zip archive's central directory`);
73
+ }
74
+ }
75
+ }
76
+ export function zipEntryData(bytes, entry, limit = MOST_INFLATED_BYTES) {
61
77
  if (entry.encrypted) {
62
78
  throw new Error(`${entry.name} in the zip archive is encrypted`);
63
79
  }
@@ -74,7 +90,7 @@ export function zipEntryData(bytes, entry) {
74
90
  data = stored;
75
91
  }
76
92
  else if (entry.method === DEFLATED_METHOD) {
77
- data = inflateRaw(stored, entry.size);
93
+ data = inflateRaw(stored, entry.size, limit);
78
94
  }
79
95
  else {
80
96
  throw new Error(`${entry.name} is compressed with zip method ${entry.method}; only stored and deflated entries are read`);
@@ -87,3 +103,124 @@ export function zipEntryData(bytes, entry) {
87
103
  }
88
104
  return data;
89
105
  }
106
+ export function dosDateTime(moment) {
107
+ const year = Math.max(DOS_EPOCH_YEAR, moment.getFullYear());
108
+ return {
109
+ time: (moment.getHours() << DOS_HOUR_SHIFT) | (moment.getMinutes() << DOS_MINUTE_SHIFT) | Math.floor(moment.getSeconds() / DOS_SECONDS_PER_UNIT),
110
+ date: ((year - DOS_EPOCH_YEAR) << DOS_YEAR_SHIFT) | ((moment.getMonth() + 1) << DOS_MONTH_SHIFT) | moment.getDate(),
111
+ };
112
+ }
113
+ function headerWriter(size) {
114
+ const bytes = new Uint8Array(size);
115
+ const view = new DataView(bytes.buffer);
116
+ let at = 0;
117
+ return {
118
+ bytes,
119
+ u16: (value) => {
120
+ view.setUint16(at, value, true);
121
+ at += UINT16_BYTES;
122
+ },
123
+ u32: (value) => {
124
+ view.setUint32(at, value, true);
125
+ at += UINT32_BYTES;
126
+ },
127
+ raw: (value) => {
128
+ bytes.set(value, at);
129
+ at += value.length;
130
+ },
131
+ };
132
+ }
133
+ function sharedFields(writer, name, record, stamp) {
134
+ writer.u16(UTF8_NAME_FLAG);
135
+ writer.u16(STORED_METHOD);
136
+ writer.u16(stamp.time);
137
+ writer.u16(stamp.date);
138
+ writer.u32(record.crc32);
139
+ writer.u32(record.size);
140
+ writer.u32(record.size);
141
+ writer.u16(name.length);
142
+ writer.u16(0);
143
+ }
144
+ function checkedEntryName(name) {
145
+ const segments = name.split("/");
146
+ if (name === "" || name.startsWith("/") || name.includes("\\") || /^[A-Za-z]:/.test(name) || segments.includes("..") || /\p{Cc}/u.test(name)) {
147
+ throw new Error(`"${name}" cannot be a zip entry name: it must be a relative path without "..", backslashes or control characters`);
148
+ }
149
+ return name;
150
+ }
151
+ export function zipStoredParts(records, modified = new Date()) {
152
+ if (records.length >= ZIP64_COUNT) {
153
+ throw new Error(`A zip archive written here holds at most ${ZIP64_COUNT - 1} entries, not ${records.length}`);
154
+ }
155
+ const stamp = dosDateTime(modified);
156
+ const encoder = new TextEncoder();
157
+ const names = records.map((record) => encoder.encode(checkedEntryName(record.name)));
158
+ names.forEach((name, index) => {
159
+ if (name.length > LONGEST_ARCHIVE_COMMENT) {
160
+ throw new Error(`Zip entry ${index} has a name longer than ${LONGEST_ARCHIVE_COMMENT} bytes`);
161
+ }
162
+ });
163
+ let total = 0;
164
+ for (const record of records) {
165
+ total += record.size;
166
+ if (record.size >= ZIP64_SIZE || total >= ZIP64_SIZE) {
167
+ throw new Error("A zip archive written here holds less than 4 GB in all, because it does not write ZIP64");
168
+ }
169
+ }
170
+ const parts = [];
171
+ const offsets = [];
172
+ let at = 0;
173
+ records.forEach((record, index) => {
174
+ const name = names[index];
175
+ const local = headerWriter(LOCAL_HEADER_SIZE + name.length);
176
+ local.u32(LOCAL_HEADER_SIGNATURE);
177
+ local.u16(ZIP_VERSION);
178
+ sharedFields(local, name, record, stamp);
179
+ local.raw(name);
180
+ offsets.push(at);
181
+ parts.push(local.bytes, record.data);
182
+ at += local.bytes.length + record.size;
183
+ });
184
+ const directory = at;
185
+ records.forEach((record, index) => {
186
+ const name = names[index];
187
+ const central = headerWriter(CENTRAL_HEADER_SIZE + name.length);
188
+ central.u32(CENTRAL_HEADER_SIGNATURE);
189
+ central.u16(ZIP_VERSION);
190
+ central.u16(ZIP_VERSION);
191
+ sharedFields(central, name, record, stamp);
192
+ central.u16(0);
193
+ central.u16(0);
194
+ central.u16(0);
195
+ central.u32(0);
196
+ central.u32(offsets[index]);
197
+ central.raw(name);
198
+ parts.push(central.bytes);
199
+ at += central.bytes.length;
200
+ });
201
+ const end = headerWriter(END_OF_CENTRAL_SIZE);
202
+ end.u32(END_OF_CENTRAL_SIGNATURE);
203
+ end.u16(0);
204
+ end.u16(0);
205
+ end.u16(records.length);
206
+ end.u16(records.length);
207
+ end.u32(at - directory);
208
+ end.u32(directory);
209
+ end.u16(0);
210
+ parts.push(end.bytes);
211
+ return parts;
212
+ }
213
+ export function zipStored(files, modified = new Date()) {
214
+ const parts = zipStoredParts(files.map((file) => ({ name: file.name, size: file.data.length, crc32: crc32(file.data), data: file.data })), modified);
215
+ const archive = new Uint8Array(parts.reduce((sum, part) => sum + part.length, 0));
216
+ let at = 0;
217
+ for (const part of parts) {
218
+ archive.set(part, at);
219
+ at += part.length;
220
+ }
221
+ return archive;
222
+ }
223
+ export function zipStoredBlob(files, modified = new Date()) {
224
+ const records = files.map((file) => ({ name: file.name, size: file.data.length, crc32: crc32(file.data), data: file.data }));
225
+ return new Blob(zipStoredParts(records, modified), { type: ZIP_MIME_TYPE });
226
+ }
@@ -19,6 +19,26 @@ export interface HuffmanTable {
19
19
  readonly entries: Int32Array;
20
20
  readonly bits: number;
21
21
  }
22
+ export interface ZipFile {
23
+ readonly name: string;
24
+ readonly data: Uint8Array;
25
+ }
26
+ export interface ZipStoredRecord<T> {
27
+ readonly name: string;
28
+ readonly size: number;
29
+ readonly crc32: number;
30
+ readonly data: T;
31
+ }
32
+ export interface ZipHeaderWriter {
33
+ readonly bytes: Uint8Array<ArrayBuffer>;
34
+ readonly u16: (value: number) => void;
35
+ readonly u32: (value: number) => void;
36
+ readonly raw: (value: Uint8Array) => void;
37
+ }
38
+ export interface DosDateTime {
39
+ readonly time: number;
40
+ readonly date: number;
41
+ }
22
42
  export interface ZipEntry {
23
43
  readonly name: string;
24
44
  readonly method: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bitbybit-dev/base",
3
- "version": "1.6.0-rc.0",
3
+ "version": "1.6.1",
4
4
  "description": "Bit By Bit Developers Base CAD Library to Program Geometry",
5
5
  "homepage": "https://docs.bitbybit.dev/modules/Bit",
6
6
  "main": "index.js",