@8ms/helpers 3.2.6 → 3.2.8

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.
Files changed (106) hide show
  1. package/AGENTS.md +20 -0
  2. package/dist/aws/s3/{server → _shared}/awsS3File.cjs +1 -1
  3. package/dist/aws/s3/{server → _shared}/awsS3File.d.cts +1 -1
  4. package/dist/aws/s3/{server → _shared}/awsS3File.d.mts +1 -1
  5. package/dist/aws/s3/{server → _shared}/awsS3File.mjs +1 -1
  6. package/dist/aws/s3/_shared/index.cjs +3 -0
  7. package/dist/aws/s3/_shared/index.d.cts +3 -0
  8. package/dist/aws/s3/_shared/index.d.mts +3 -0
  9. package/dist/aws/s3/_shared/index.mjs +2 -0
  10. package/dist/aws/s3/_shared/types.cjs +0 -0
  11. package/dist/aws/s3/_shared/types.d.cts +35 -0
  12. package/dist/aws/s3/_shared/types.d.mts +35 -0
  13. package/dist/aws/s3/_shared/types.mjs +1 -0
  14. package/dist/aws/s3/server/AwsS3.cjs +83 -4
  15. package/dist/aws/s3/server/AwsS3.d.cts +19 -26
  16. package/dist/aws/s3/server/AwsS3.d.mts +19 -26
  17. package/dist/aws/s3/server/AwsS3.mjs +81 -2
  18. package/dist/aws/s3/server/index.cjs +3 -2
  19. package/dist/aws/s3/server/index.d.cts +4 -3
  20. package/dist/aws/s3/server/index.d.mts +4 -3
  21. package/dist/aws/s3/server/index.mjs +2 -1
  22. package/dist/file/_shared/dataFileType.cjs +2 -0
  23. package/dist/file/_shared/dataFileType.d.cts +2 -0
  24. package/dist/file/_shared/dataFileType.d.mts +2 -0
  25. package/dist/file/_shared/dataFileType.mjs +2 -0
  26. package/dist/file/_shared/fileMimeType.cjs +2 -0
  27. package/dist/file/_shared/fileMimeType.mjs +2 -0
  28. package/dist/file/_shared/fileType.d.cts +2 -0
  29. package/dist/file/_shared/fileType.d.mts +2 -0
  30. package/dist/googleCloud/bigquery/_shared/index.d.cts +2 -2
  31. package/dist/googleCloud/bigquery/_shared/index.d.mts +2 -2
  32. package/dist/googleCloud/bigquery/_shared/types.d.cts +54 -0
  33. package/dist/googleCloud/bigquery/_shared/types.d.mts +54 -0
  34. package/dist/googleCloud/bigquery/client/index.d.cts +2 -2
  35. package/dist/googleCloud/bigquery/client/index.d.mts +2 -2
  36. package/dist/googleCloud/bigquery/server/GoogleCloudBigquery.cjs +158 -7
  37. package/dist/googleCloud/bigquery/server/GoogleCloudBigquery.d.cts +47 -31
  38. package/dist/googleCloud/bigquery/server/GoogleCloudBigquery.d.mts +47 -31
  39. package/dist/googleCloud/bigquery/server/GoogleCloudBigquery.mjs +158 -7
  40. package/dist/googleCloud/bigquery/server/index.d.cts +3 -3
  41. package/dist/googleCloud/bigquery/server/index.d.mts +3 -3
  42. package/dist/googleCloud/drive/server/GoogleCloudDrive.cjs +85 -0
  43. package/dist/googleCloud/drive/server/GoogleCloudDrive.d.cts +34 -0
  44. package/dist/googleCloud/drive/server/GoogleCloudDrive.d.mts +34 -0
  45. package/dist/googleCloud/drive/server/GoogleCloudDrive.mjs +85 -0
  46. package/dist/stream/server/index.cjs +11 -0
  47. package/dist/stream/server/index.d.cts +4 -1
  48. package/dist/stream/server/index.d.mts +4 -1
  49. package/dist/stream/server/index.mjs +4 -1
  50. package/dist/stream/server/json/logic.cjs +18 -0
  51. package/dist/stream/server/json/logic.d.cts +27 -0
  52. package/dist/stream/server/json/logic.d.mts +27 -0
  53. package/dist/stream/server/json/logic.mjs +16 -0
  54. package/dist/stream/server/json/read.cjs +46 -0
  55. package/dist/stream/server/json/read.d.cts +7 -0
  56. package/dist/stream/server/json/read.d.mts +7 -0
  57. package/dist/stream/server/json/read.mjs +42 -0
  58. package/dist/stream/server/json/write.cjs +69 -0
  59. package/dist/stream/server/json/write.d.cts +14 -0
  60. package/dist/stream/server/json/write.d.mts +14 -0
  61. package/dist/stream/server/json/write.mjs +63 -0
  62. package/dist/stream/server/sort.cjs +12 -23
  63. package/dist/stream/server/sort.d.cts +10 -6
  64. package/dist/stream/server/sort.d.mts +10 -6
  65. package/dist/stream/server/sort.mjs +12 -23
  66. package/dist/xlsx/_shared/createXlsx.cjs +12 -22
  67. package/dist/xlsx/_shared/createXlsx.mjs +12 -22
  68. package/dist/xlsx/_shared/modifyXlsx.cjs +32 -44
  69. package/dist/xlsx/_shared/modifyXlsx.mjs +32 -44
  70. package/dist/xlsx/client/index.cjs +0 -1
  71. package/dist/xlsx/client/index.mjs +0 -1
  72. package/dist/xlsx/server/index.cjs +0 -1
  73. package/dist/xlsx/server/index.mjs +0 -1
  74. package/dist/zip/_shared/ZipArchive.cjs +49 -0
  75. package/dist/zip/_shared/ZipArchive.d.cts +24 -0
  76. package/dist/zip/_shared/ZipArchive.d.mts +24 -0
  77. package/dist/zip/_shared/ZipArchive.mjs +48 -0
  78. package/dist/zip/_shared/crc32.cjs +24 -0
  79. package/dist/zip/_shared/crc32.d.cts +4 -0
  80. package/dist/zip/_shared/crc32.d.mts +4 -0
  81. package/dist/zip/_shared/crc32.mjs +23 -0
  82. package/dist/zip/_shared/deflate.cjs +21 -0
  83. package/dist/zip/_shared/deflate.d.cts +10 -0
  84. package/dist/zip/_shared/deflate.d.mts +10 -0
  85. package/dist/zip/_shared/deflate.mjs +19 -0
  86. package/dist/zip/_shared/index.cjs +12 -0
  87. package/dist/zip/_shared/index.d.cts +6 -0
  88. package/dist/zip/_shared/index.d.mts +6 -0
  89. package/dist/zip/_shared/index.mjs +6 -0
  90. package/dist/zip/_shared/readZip.cjs +63 -0
  91. package/dist/zip/_shared/readZip.d.cts +9 -0
  92. package/dist/zip/_shared/readZip.d.mts +9 -0
  93. package/dist/zip/_shared/readZip.mjs +62 -0
  94. package/dist/zip/_shared/writeZip.cjs +105 -0
  95. package/dist/zip/_shared/writeZip.d.cts +7 -0
  96. package/dist/zip/_shared/writeZip.d.mts +7 -0
  97. package/dist/zip/_shared/writeZip.mjs +104 -0
  98. package/dist/zip/client/index.cjs +12 -0
  99. package/dist/zip/client/index.d.cts +6 -0
  100. package/dist/zip/client/index.d.mts +6 -0
  101. package/dist/zip/client/index.mjs +6 -0
  102. package/dist/zip/server/index.cjs +12 -0
  103. package/dist/zip/server/index.d.cts +6 -0
  104. package/dist/zip/server/index.d.mts +6 -0
  105. package/dist/zip/server/index.mjs +6 -0
  106. package/package.json +65 -10
@@ -0,0 +1,63 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_zip__shared_crc32 = require("./crc32.cjs");
3
+ const require_zip__shared_deflate = require("./deflate.cjs");
4
+ //#region src/zip/_shared/readZip.ts
5
+ const EOCD_SIGNATURE = 101010256;
6
+ const CENTRAL_HEADER_SIGNATURE = 33639248;
7
+ const LOCAL_HEADER_SIGNATURE = 67324752;
8
+ const EOCD_SIZE = 22;
9
+ const CENTRAL_HEADER_SIZE = 46;
10
+ const LOCAL_HEADER_SIZE = 30;
11
+ /** A ZIP comment is a 16-bit length, so the EOCD starts at most this far from the end. */
12
+ const MAX_EOCD_SEARCH = 65557;
13
+ const METHOD_STORED = 0;
14
+ const METHOD_DEFLATE = 8;
15
+ const getEocdOffset = (view) => {
16
+ const earliest = Math.max(0, view.byteLength - MAX_EOCD_SEARCH);
17
+ for (let offset = view.byteLength - EOCD_SIZE; offset >= earliest; offset--) if (EOCD_SIGNATURE === view.getUint32(offset, true)) return offset;
18
+ return -1;
19
+ };
20
+ /**
21
+ * Read every file entry out of a ZIP archive.
22
+ *
23
+ * Entries are keyed by their full path and returned decompressed, in central
24
+ * directory order. Directory entries are skipped.
25
+ */
26
+ const getZipEntries = async (bytes) => {
27
+ if (bytes.byteLength < EOCD_SIZE) throw new Error("Not a ZIP archive: too short to contain an end of central directory record.");
28
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
29
+ const eocdOffset = getEocdOffset(view);
30
+ if (0 > eocdOffset) throw new Error("Not a ZIP archive: no end of central directory record found.");
31
+ const entryCount = view.getUint16(eocdOffset + 10, true);
32
+ const centralOffset = view.getUint32(eocdOffset + 16, true);
33
+ if (65535 === entryCount || 4294967295 === centralOffset) throw new Error("ZIP64 archives are not supported.");
34
+ const entries = /* @__PURE__ */ new Map();
35
+ const decoder = new TextDecoder();
36
+ let cursor = centralOffset;
37
+ for (let index = 0; index < entryCount; index++) {
38
+ if (CENTRAL_HEADER_SIGNATURE !== view.getUint32(cursor, true)) throw new Error(`Corrupt ZIP archive: bad central directory header at offset ${cursor}.`);
39
+ const method = view.getUint16(cursor + 10, true);
40
+ const expectedCrc = view.getUint32(cursor + 16, true);
41
+ const compressedSize = view.getUint32(cursor + 20, true);
42
+ const nameLength = view.getUint16(cursor + 28, true);
43
+ const extraLength = view.getUint16(cursor + 30, true);
44
+ const commentLength = view.getUint16(cursor + 32, true);
45
+ const localOffset = view.getUint32(cursor + 42, true);
46
+ const name = decoder.decode(bytes.subarray(cursor + CENTRAL_HEADER_SIZE, cursor + CENTRAL_HEADER_SIZE + nameLength));
47
+ cursor += CENTRAL_HEADER_SIZE + nameLength + extraLength + commentLength;
48
+ if (name.endsWith("/")) continue;
49
+ if (LOCAL_HEADER_SIGNATURE !== view.getUint32(localOffset, true)) throw new Error(`Corrupt ZIP archive: bad local header for "${name}".`);
50
+ const localNameLength = view.getUint16(localOffset + 26, true);
51
+ const localExtraLength = view.getUint16(localOffset + 28, true);
52
+ const dataOffset = localOffset + LOCAL_HEADER_SIZE + localNameLength + localExtraLength;
53
+ if (dataOffset + compressedSize > bytes.byteLength) throw new Error(`Corrupt ZIP archive: "${name}" extends past the end of the buffer.`);
54
+ const stored = bytes.subarray(dataOffset, dataOffset + compressedSize);
55
+ if (METHOD_STORED !== method && METHOD_DEFLATE !== method) throw new Error(`Unsupported compression method ${method} for "${name}".`);
56
+ const content = METHOD_DEFLATE === method ? await require_zip__shared_deflate.getInflatedRaw(stored) : stored.slice();
57
+ if (expectedCrc !== require_zip__shared_crc32.getCrc32(content)) throw new Error(`Corrupt ZIP archive: CRC mismatch for "${name}".`);
58
+ entries.set(name, content);
59
+ }
60
+ return entries;
61
+ };
62
+ //#endregion
63
+ exports.getZipEntries = getZipEntries;
@@ -0,0 +1,9 @@
1
+ //#region src/zip/_shared/readZip.d.ts
2
+ /**
3
+ * Read every file entry out of a ZIP archive.
4
+ *
5
+ * Entries are keyed by their full path and returned decompressed, in central
6
+ * directory order. Directory entries are skipped.
7
+ */
8
+ export declare const getZipEntries: (bytes: Uint8Array) => Promise<Map<string, Uint8Array>>;
9
+ //#endregion
@@ -0,0 +1,9 @@
1
+ //#region src/zip/_shared/readZip.d.ts
2
+ /**
3
+ * Read every file entry out of a ZIP archive.
4
+ *
5
+ * Entries are keyed by their full path and returned decompressed, in central
6
+ * directory order. Directory entries are skipped.
7
+ */
8
+ export declare const getZipEntries: (bytes: Uint8Array) => Promise<Map<string, Uint8Array>>;
9
+ //#endregion
@@ -0,0 +1,62 @@
1
+ import { getCrc32 } from "./crc32.mjs";
2
+ import { getInflatedRaw } from "./deflate.mjs";
3
+ //#region src/zip/_shared/readZip.ts
4
+ const EOCD_SIGNATURE = 101010256;
5
+ const CENTRAL_HEADER_SIGNATURE = 33639248;
6
+ const LOCAL_HEADER_SIGNATURE = 67324752;
7
+ const EOCD_SIZE = 22;
8
+ const CENTRAL_HEADER_SIZE = 46;
9
+ const LOCAL_HEADER_SIZE = 30;
10
+ /** A ZIP comment is a 16-bit length, so the EOCD starts at most this far from the end. */
11
+ const MAX_EOCD_SEARCH = 65557;
12
+ const METHOD_STORED = 0;
13
+ const METHOD_DEFLATE = 8;
14
+ const getEocdOffset = (view) => {
15
+ const earliest = Math.max(0, view.byteLength - MAX_EOCD_SEARCH);
16
+ for (let offset = view.byteLength - EOCD_SIZE; offset >= earliest; offset--) if (EOCD_SIGNATURE === view.getUint32(offset, true)) return offset;
17
+ return -1;
18
+ };
19
+ /**
20
+ * Read every file entry out of a ZIP archive.
21
+ *
22
+ * Entries are keyed by their full path and returned decompressed, in central
23
+ * directory order. Directory entries are skipped.
24
+ */
25
+ const getZipEntries = async (bytes) => {
26
+ if (bytes.byteLength < EOCD_SIZE) throw new Error("Not a ZIP archive: too short to contain an end of central directory record.");
27
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
28
+ const eocdOffset = getEocdOffset(view);
29
+ if (0 > eocdOffset) throw new Error("Not a ZIP archive: no end of central directory record found.");
30
+ const entryCount = view.getUint16(eocdOffset + 10, true);
31
+ const centralOffset = view.getUint32(eocdOffset + 16, true);
32
+ if (65535 === entryCount || 4294967295 === centralOffset) throw new Error("ZIP64 archives are not supported.");
33
+ const entries = /* @__PURE__ */ new Map();
34
+ const decoder = new TextDecoder();
35
+ let cursor = centralOffset;
36
+ for (let index = 0; index < entryCount; index++) {
37
+ if (CENTRAL_HEADER_SIGNATURE !== view.getUint32(cursor, true)) throw new Error(`Corrupt ZIP archive: bad central directory header at offset ${cursor}.`);
38
+ const method = view.getUint16(cursor + 10, true);
39
+ const expectedCrc = view.getUint32(cursor + 16, true);
40
+ const compressedSize = view.getUint32(cursor + 20, true);
41
+ const nameLength = view.getUint16(cursor + 28, true);
42
+ const extraLength = view.getUint16(cursor + 30, true);
43
+ const commentLength = view.getUint16(cursor + 32, true);
44
+ const localOffset = view.getUint32(cursor + 42, true);
45
+ const name = decoder.decode(bytes.subarray(cursor + CENTRAL_HEADER_SIZE, cursor + CENTRAL_HEADER_SIZE + nameLength));
46
+ cursor += CENTRAL_HEADER_SIZE + nameLength + extraLength + commentLength;
47
+ if (name.endsWith("/")) continue;
48
+ if (LOCAL_HEADER_SIGNATURE !== view.getUint32(localOffset, true)) throw new Error(`Corrupt ZIP archive: bad local header for "${name}".`);
49
+ const localNameLength = view.getUint16(localOffset + 26, true);
50
+ const localExtraLength = view.getUint16(localOffset + 28, true);
51
+ const dataOffset = localOffset + LOCAL_HEADER_SIZE + localNameLength + localExtraLength;
52
+ if (dataOffset + compressedSize > bytes.byteLength) throw new Error(`Corrupt ZIP archive: "${name}" extends past the end of the buffer.`);
53
+ const stored = bytes.subarray(dataOffset, dataOffset + compressedSize);
54
+ if (METHOD_STORED !== method && METHOD_DEFLATE !== method) throw new Error(`Unsupported compression method ${method} for "${name}".`);
55
+ const content = METHOD_DEFLATE === method ? await getInflatedRaw(stored) : stored.slice();
56
+ if (expectedCrc !== getCrc32(content)) throw new Error(`Corrupt ZIP archive: CRC mismatch for "${name}".`);
57
+ entries.set(name, content);
58
+ }
59
+ return entries;
60
+ };
61
+ //#endregion
62
+ export { getZipEntries };
@@ -0,0 +1,105 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_zip__shared_crc32 = require("./crc32.cjs");
3
+ const require_zip__shared_deflate = require("./deflate.cjs");
4
+ //#region src/zip/_shared/writeZip.ts
5
+ const LOCAL_HEADER_SIGNATURE = 67324752;
6
+ const CENTRAL_HEADER_SIGNATURE = 33639248;
7
+ const EOCD_SIGNATURE = 101010256;
8
+ const LOCAL_HEADER_SIZE = 30;
9
+ const CENTRAL_HEADER_SIZE = 46;
10
+ const EOCD_SIZE = 22;
11
+ const METHOD_STORED = 0;
12
+ const METHOD_DEFLATE = 8;
13
+ const VERSION = 20;
14
+ /** Bit 11 of the general purpose flags marks the filename as UTF-8. */
15
+ const UTF8_FLAG = 2048;
16
+ /**
17
+ * Fixed at the ZIP epoch (1980-01-01 00:00) so the same input always produces the
18
+ * same bytes. No consumer of this library reads entry timestamps.
19
+ */
20
+ const DOS_TIME = 0;
21
+ const DOS_DATE = 33;
22
+ const getPrepared = async (name, content) => {
23
+ const encodedName = new TextEncoder().encode(name);
24
+ const deflated = 0 === content.length ? content : await require_zip__shared_deflate.getDeflatedRaw(content);
25
+ const useDeflate = deflated.length < content.length;
26
+ return {
27
+ name: encodedName,
28
+ flags: encodedName.length === name.length ? 0 : UTF8_FLAG,
29
+ method: useDeflate ? METHOD_DEFLATE : METHOD_STORED,
30
+ crc: require_zip__shared_crc32.getCrc32(content),
31
+ compressedSize: useDeflate ? deflated.length : content.length,
32
+ size: content.length,
33
+ data: useDeflate ? deflated : content
34
+ };
35
+ };
36
+ /**
37
+ * Build a ZIP archive from a map of path to file contents, preserving insertion
38
+ * order. Entries are deflated unless that would make them larger.
39
+ */
40
+ const getZipBytes = async (entries) => {
41
+ if (entries.size > 65535) throw new Error("ZIP archives with more than 65535 entries require ZIP64, which is not supported.");
42
+ const prepared = [];
43
+ let offset = 0;
44
+ for (const [name, content] of entries) {
45
+ const entry = await getPrepared(name, content);
46
+ prepared.push({
47
+ ...entry,
48
+ localOffset: offset
49
+ });
50
+ offset += LOCAL_HEADER_SIZE + entry.name.length + entry.compressedSize;
51
+ }
52
+ const centralOffset = offset;
53
+ const centralSize = prepared.reduce((total, entry) => total + CENTRAL_HEADER_SIZE + entry.name.length, 0);
54
+ const output = new Uint8Array(centralOffset + centralSize + EOCD_SIZE);
55
+ const view = new DataView(output.buffer);
56
+ for (const entry of prepared) {
57
+ const start = entry.localOffset;
58
+ view.setUint32(start, LOCAL_HEADER_SIGNATURE, true);
59
+ view.setUint16(start + 4, VERSION, true);
60
+ view.setUint16(start + 6, entry.flags, true);
61
+ view.setUint16(start + 8, entry.method, true);
62
+ view.setUint16(start + 10, DOS_TIME, true);
63
+ view.setUint16(start + 12, DOS_DATE, true);
64
+ view.setUint32(start + 14, entry.crc, true);
65
+ view.setUint32(start + 18, entry.compressedSize, true);
66
+ view.setUint32(start + 22, entry.size, true);
67
+ view.setUint16(start + 26, entry.name.length, true);
68
+ view.setUint16(start + 28, 0, true);
69
+ output.set(entry.name, start + LOCAL_HEADER_SIZE);
70
+ output.set(entry.data, start + LOCAL_HEADER_SIZE + entry.name.length);
71
+ }
72
+ let cursor = centralOffset;
73
+ for (const entry of prepared) {
74
+ view.setUint32(cursor, CENTRAL_HEADER_SIGNATURE, true);
75
+ view.setUint16(cursor + 4, VERSION, true);
76
+ view.setUint16(cursor + 6, VERSION, true);
77
+ view.setUint16(cursor + 8, entry.flags, true);
78
+ view.setUint16(cursor + 10, entry.method, true);
79
+ view.setUint16(cursor + 12, DOS_TIME, true);
80
+ view.setUint16(cursor + 14, DOS_DATE, true);
81
+ view.setUint32(cursor + 16, entry.crc, true);
82
+ view.setUint32(cursor + 20, entry.compressedSize, true);
83
+ view.setUint32(cursor + 24, entry.size, true);
84
+ view.setUint16(cursor + 28, entry.name.length, true);
85
+ view.setUint16(cursor + 30, 0, true);
86
+ view.setUint16(cursor + 32, 0, true);
87
+ view.setUint16(cursor + 34, 0, true);
88
+ view.setUint16(cursor + 36, 0, true);
89
+ view.setUint32(cursor + 38, 0, true);
90
+ view.setUint32(cursor + 42, entry.localOffset, true);
91
+ output.set(entry.name, cursor + CENTRAL_HEADER_SIZE);
92
+ cursor += CENTRAL_HEADER_SIZE + entry.name.length;
93
+ }
94
+ view.setUint32(cursor, EOCD_SIGNATURE, true);
95
+ view.setUint16(cursor + 4, 0, true);
96
+ view.setUint16(cursor + 6, 0, true);
97
+ view.setUint16(cursor + 8, prepared.length, true);
98
+ view.setUint16(cursor + 10, prepared.length, true);
99
+ view.setUint32(cursor + 12, centralSize, true);
100
+ view.setUint32(cursor + 16, centralOffset, true);
101
+ view.setUint16(cursor + 20, 0, true);
102
+ return output;
103
+ };
104
+ //#endregion
105
+ exports.getZipBytes = getZipBytes;
@@ -0,0 +1,7 @@
1
+ //#region src/zip/_shared/writeZip.d.ts
2
+ /**
3
+ * Build a ZIP archive from a map of path to file contents, preserving insertion
4
+ * order. Entries are deflated unless that would make them larger.
5
+ */
6
+ export declare const getZipBytes: (entries: Map<string, Uint8Array>) => Promise<Uint8Array>;
7
+ //#endregion
@@ -0,0 +1,7 @@
1
+ //#region src/zip/_shared/writeZip.d.ts
2
+ /**
3
+ * Build a ZIP archive from a map of path to file contents, preserving insertion
4
+ * order. Entries are deflated unless that would make them larger.
5
+ */
6
+ export declare const getZipBytes: (entries: Map<string, Uint8Array>) => Promise<Uint8Array>;
7
+ //#endregion
@@ -0,0 +1,104 @@
1
+ import { getCrc32 } from "./crc32.mjs";
2
+ import { getDeflatedRaw } from "./deflate.mjs";
3
+ //#region src/zip/_shared/writeZip.ts
4
+ const LOCAL_HEADER_SIGNATURE = 67324752;
5
+ const CENTRAL_HEADER_SIGNATURE = 33639248;
6
+ const EOCD_SIGNATURE = 101010256;
7
+ const LOCAL_HEADER_SIZE = 30;
8
+ const CENTRAL_HEADER_SIZE = 46;
9
+ const EOCD_SIZE = 22;
10
+ const METHOD_STORED = 0;
11
+ const METHOD_DEFLATE = 8;
12
+ const VERSION = 20;
13
+ /** Bit 11 of the general purpose flags marks the filename as UTF-8. */
14
+ const UTF8_FLAG = 2048;
15
+ /**
16
+ * Fixed at the ZIP epoch (1980-01-01 00:00) so the same input always produces the
17
+ * same bytes. No consumer of this library reads entry timestamps.
18
+ */
19
+ const DOS_TIME = 0;
20
+ const DOS_DATE = 33;
21
+ const getPrepared = async (name, content) => {
22
+ const encodedName = new TextEncoder().encode(name);
23
+ const deflated = 0 === content.length ? content : await getDeflatedRaw(content);
24
+ const useDeflate = deflated.length < content.length;
25
+ return {
26
+ name: encodedName,
27
+ flags: encodedName.length === name.length ? 0 : UTF8_FLAG,
28
+ method: useDeflate ? METHOD_DEFLATE : METHOD_STORED,
29
+ crc: getCrc32(content),
30
+ compressedSize: useDeflate ? deflated.length : content.length,
31
+ size: content.length,
32
+ data: useDeflate ? deflated : content
33
+ };
34
+ };
35
+ /**
36
+ * Build a ZIP archive from a map of path to file contents, preserving insertion
37
+ * order. Entries are deflated unless that would make them larger.
38
+ */
39
+ const getZipBytes = async (entries) => {
40
+ if (entries.size > 65535) throw new Error("ZIP archives with more than 65535 entries require ZIP64, which is not supported.");
41
+ const prepared = [];
42
+ let offset = 0;
43
+ for (const [name, content] of entries) {
44
+ const entry = await getPrepared(name, content);
45
+ prepared.push({
46
+ ...entry,
47
+ localOffset: offset
48
+ });
49
+ offset += LOCAL_HEADER_SIZE + entry.name.length + entry.compressedSize;
50
+ }
51
+ const centralOffset = offset;
52
+ const centralSize = prepared.reduce((total, entry) => total + CENTRAL_HEADER_SIZE + entry.name.length, 0);
53
+ const output = new Uint8Array(centralOffset + centralSize + EOCD_SIZE);
54
+ const view = new DataView(output.buffer);
55
+ for (const entry of prepared) {
56
+ const start = entry.localOffset;
57
+ view.setUint32(start, LOCAL_HEADER_SIGNATURE, true);
58
+ view.setUint16(start + 4, VERSION, true);
59
+ view.setUint16(start + 6, entry.flags, true);
60
+ view.setUint16(start + 8, entry.method, true);
61
+ view.setUint16(start + 10, DOS_TIME, true);
62
+ view.setUint16(start + 12, DOS_DATE, true);
63
+ view.setUint32(start + 14, entry.crc, true);
64
+ view.setUint32(start + 18, entry.compressedSize, true);
65
+ view.setUint32(start + 22, entry.size, true);
66
+ view.setUint16(start + 26, entry.name.length, true);
67
+ view.setUint16(start + 28, 0, true);
68
+ output.set(entry.name, start + LOCAL_HEADER_SIZE);
69
+ output.set(entry.data, start + LOCAL_HEADER_SIZE + entry.name.length);
70
+ }
71
+ let cursor = centralOffset;
72
+ for (const entry of prepared) {
73
+ view.setUint32(cursor, CENTRAL_HEADER_SIGNATURE, true);
74
+ view.setUint16(cursor + 4, VERSION, true);
75
+ view.setUint16(cursor + 6, VERSION, true);
76
+ view.setUint16(cursor + 8, entry.flags, true);
77
+ view.setUint16(cursor + 10, entry.method, true);
78
+ view.setUint16(cursor + 12, DOS_TIME, true);
79
+ view.setUint16(cursor + 14, DOS_DATE, true);
80
+ view.setUint32(cursor + 16, entry.crc, true);
81
+ view.setUint32(cursor + 20, entry.compressedSize, true);
82
+ view.setUint32(cursor + 24, entry.size, true);
83
+ view.setUint16(cursor + 28, entry.name.length, true);
84
+ view.setUint16(cursor + 30, 0, true);
85
+ view.setUint16(cursor + 32, 0, true);
86
+ view.setUint16(cursor + 34, 0, true);
87
+ view.setUint16(cursor + 36, 0, true);
88
+ view.setUint32(cursor + 38, 0, true);
89
+ view.setUint32(cursor + 42, entry.localOffset, true);
90
+ output.set(entry.name, cursor + CENTRAL_HEADER_SIZE);
91
+ cursor += CENTRAL_HEADER_SIZE + entry.name.length;
92
+ }
93
+ view.setUint32(cursor, EOCD_SIGNATURE, true);
94
+ view.setUint16(cursor + 4, 0, true);
95
+ view.setUint16(cursor + 6, 0, true);
96
+ view.setUint16(cursor + 8, prepared.length, true);
97
+ view.setUint16(cursor + 10, prepared.length, true);
98
+ view.setUint32(cursor + 12, centralSize, true);
99
+ view.setUint32(cursor + 16, centralOffset, true);
100
+ view.setUint16(cursor + 20, 0, true);
101
+ return output;
102
+ };
103
+ //#endregion
104
+ export { getZipBytes };
@@ -0,0 +1,12 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_zip__shared_crc32 = require("../_shared/crc32.cjs");
3
+ const require_zip__shared_deflate = require("../_shared/deflate.cjs");
4
+ const require_zip__shared_readZip = require("../_shared/readZip.cjs");
5
+ const require_zip__shared_writeZip = require("../_shared/writeZip.cjs");
6
+ const require_zip__shared_ZipArchive = require("../_shared/ZipArchive.cjs");
7
+ exports.ZipArchive = require_zip__shared_ZipArchive.ZipArchive;
8
+ exports.getCrc32 = require_zip__shared_crc32.getCrc32;
9
+ exports.getDeflatedRaw = require_zip__shared_deflate.getDeflatedRaw;
10
+ exports.getInflatedRaw = require_zip__shared_deflate.getInflatedRaw;
11
+ exports.getZipBytes = require_zip__shared_writeZip.getZipBytes;
12
+ exports.getZipEntries = require_zip__shared_readZip.getZipEntries;
@@ -0,0 +1,6 @@
1
+ import { ZipArchive } from "../_shared/ZipArchive.cjs";
2
+ import { getCrc32 } from "../_shared/crc32.cjs";
3
+ import { getDeflatedRaw, getInflatedRaw } from "../_shared/deflate.cjs";
4
+ import { getZipEntries } from "../_shared/readZip.cjs";
5
+ import { getZipBytes } from "../_shared/writeZip.cjs";
6
+ export { ZipArchive, getCrc32, getDeflatedRaw, getInflatedRaw, getZipBytes, getZipEntries };
@@ -0,0 +1,6 @@
1
+ import { ZipArchive } from "../_shared/ZipArchive.mjs";
2
+ import { getCrc32 } from "../_shared/crc32.mjs";
3
+ import { getDeflatedRaw, getInflatedRaw } from "../_shared/deflate.mjs";
4
+ import { getZipEntries } from "../_shared/readZip.mjs";
5
+ import { getZipBytes } from "../_shared/writeZip.mjs";
6
+ export { ZipArchive, getCrc32, getDeflatedRaw, getInflatedRaw, getZipBytes, getZipEntries };
@@ -0,0 +1,6 @@
1
+ import { getCrc32 } from "../_shared/crc32.mjs";
2
+ import { getDeflatedRaw, getInflatedRaw } from "../_shared/deflate.mjs";
3
+ import { getZipEntries } from "../_shared/readZip.mjs";
4
+ import { getZipBytes } from "../_shared/writeZip.mjs";
5
+ import { ZipArchive } from "../_shared/ZipArchive.mjs";
6
+ export { ZipArchive, getCrc32, getDeflatedRaw, getInflatedRaw, getZipBytes, getZipEntries };
@@ -0,0 +1,12 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_zip__shared_crc32 = require("../_shared/crc32.cjs");
3
+ const require_zip__shared_deflate = require("../_shared/deflate.cjs");
4
+ const require_zip__shared_readZip = require("../_shared/readZip.cjs");
5
+ const require_zip__shared_writeZip = require("../_shared/writeZip.cjs");
6
+ const require_zip__shared_ZipArchive = require("../_shared/ZipArchive.cjs");
7
+ exports.ZipArchive = require_zip__shared_ZipArchive.ZipArchive;
8
+ exports.getCrc32 = require_zip__shared_crc32.getCrc32;
9
+ exports.getDeflatedRaw = require_zip__shared_deflate.getDeflatedRaw;
10
+ exports.getInflatedRaw = require_zip__shared_deflate.getInflatedRaw;
11
+ exports.getZipBytes = require_zip__shared_writeZip.getZipBytes;
12
+ exports.getZipEntries = require_zip__shared_readZip.getZipEntries;
@@ -0,0 +1,6 @@
1
+ import { ZipArchive } from "../_shared/ZipArchive.cjs";
2
+ import { getCrc32 } from "../_shared/crc32.cjs";
3
+ import { getDeflatedRaw, getInflatedRaw } from "../_shared/deflate.cjs";
4
+ import { getZipEntries } from "../_shared/readZip.cjs";
5
+ import { getZipBytes } from "../_shared/writeZip.cjs";
6
+ export { ZipArchive, getCrc32, getDeflatedRaw, getInflatedRaw, getZipBytes, getZipEntries };
@@ -0,0 +1,6 @@
1
+ import { ZipArchive } from "../_shared/ZipArchive.mjs";
2
+ import { getCrc32 } from "../_shared/crc32.mjs";
3
+ import { getDeflatedRaw, getInflatedRaw } from "../_shared/deflate.mjs";
4
+ import { getZipEntries } from "../_shared/readZip.mjs";
5
+ import { getZipBytes } from "../_shared/writeZip.mjs";
6
+ export { ZipArchive, getCrc32, getDeflatedRaw, getInflatedRaw, getZipBytes, getZipEntries };
@@ -0,0 +1,6 @@
1
+ import { getCrc32 } from "../_shared/crc32.mjs";
2
+ import { getDeflatedRaw, getInflatedRaw } from "../_shared/deflate.mjs";
3
+ import { getZipEntries } from "../_shared/readZip.mjs";
4
+ import { getZipBytes } from "../_shared/writeZip.mjs";
5
+ import { ZipArchive } from "../_shared/ZipArchive.mjs";
6
+ export { ZipArchive, getCrc32, getDeflatedRaw, getInflatedRaw, getZipBytes, getZipEntries };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
3
  "license": "UNLICENSED",
4
- "version": "3.2.6",
4
+ "version": "3.2.8",
5
5
  "packageManager": "yarn@4.18.0",
6
6
  "repository": {
7
7
  "type": "git",
@@ -72,12 +72,12 @@
72
72
  "gaxios": "^8.0.0",
73
73
  "google-auth-library": "^11.0.0",
74
74
  "googleapis-common": "^9.0.0",
75
- "jszip": "^3.10.1",
76
75
  "mysql2": "^3.0.0",
77
76
  "next": "^16.0.0",
78
77
  "pg": "^8.0.0",
79
78
  "react": "^19.0.0",
80
79
  "react-intersection-observer": "^11.0.0",
80
+ "stream-json": "^3.7.0",
81
81
  "swr": "^2.0.0",
82
82
  "tailwind-merge": "^3.0.0"
83
83
  },
@@ -172,9 +172,6 @@
172
172
  "googleapis-common": {
173
173
  "optional": true
174
174
  },
175
- "jszip": {
176
- "optional": true
177
- },
178
175
  "mysql2": {
179
176
  "optional": true
180
177
  },
@@ -187,6 +184,9 @@
187
184
  "react": {
188
185
  "optional": true
189
186
  },
187
+ "stream-json": {
188
+ "optional": true
189
+ },
190
190
  "swr": {
191
191
  "optional": true
192
192
  },
@@ -237,12 +237,12 @@
237
237
  "google-auth-library": "^11.1.0",
238
238
  "googleapis-common": "^9.1.0",
239
239
  "jest": "^30.5.2",
240
- "jszip": "^3.10.2",
241
240
  "mysql2": "^3.24.4",
242
241
  "next": "^16.3.6",
243
242
  "pg": "^8.23.0",
244
243
  "react": "^19.3.0",
245
244
  "react-intersection-observer": "^11.0.1",
245
+ "stream-json": "^3.7.0",
246
246
  "swr": "^2.5.1",
247
247
  "tailwind-merge": "^3.7.0",
248
248
  "ts-node": "^10.9.2",
@@ -435,6 +435,18 @@
435
435
  "import": "./dist/aws/lambda/server/getHandlerPath.mjs",
436
436
  "require": "./dist/aws/lambda/server/getHandlerPath.cjs"
437
437
  },
438
+ "./aws/s3/_shared": {
439
+ "import": "./dist/aws/s3/_shared/index.mjs",
440
+ "require": "./dist/aws/s3/_shared/index.cjs"
441
+ },
442
+ "./aws/s3/_shared/awsS3File": {
443
+ "import": "./dist/aws/s3/_shared/awsS3File.mjs",
444
+ "require": "./dist/aws/s3/_shared/awsS3File.cjs"
445
+ },
446
+ "./aws/s3/_shared/types": {
447
+ "import": "./dist/aws/s3/_shared/types.mjs",
448
+ "require": "./dist/aws/s3/_shared/types.cjs"
449
+ },
438
450
  "./aws/s3/server": {
439
451
  "import": "./dist/aws/s3/server/index.mjs",
440
452
  "require": "./dist/aws/s3/server/index.cjs"
@@ -443,10 +455,6 @@
443
455
  "import": "./dist/aws/s3/server/AwsS3.mjs",
444
456
  "require": "./dist/aws/s3/server/AwsS3.cjs"
445
457
  },
446
- "./aws/s3/server/awsS3File": {
447
- "import": "./dist/aws/s3/server/awsS3File.mjs",
448
- "require": "./dist/aws/s3/server/awsS3File.cjs"
449
- },
450
458
  "./aws/s3/server/payload": {
451
459
  "import": "./dist/aws/s3/server/payload.mjs",
452
460
  "require": "./dist/aws/s3/server/payload.cjs"
@@ -1547,6 +1555,18 @@
1547
1555
  "import": "./dist/stream/server/index.mjs",
1548
1556
  "require": "./dist/stream/server/index.cjs"
1549
1557
  },
1558
+ "./stream/server/json/logic": {
1559
+ "import": "./dist/stream/server/json/logic.mjs",
1560
+ "require": "./dist/stream/server/json/logic.cjs"
1561
+ },
1562
+ "./stream/server/json/read": {
1563
+ "import": "./dist/stream/server/json/read.mjs",
1564
+ "require": "./dist/stream/server/json/read.cjs"
1565
+ },
1566
+ "./stream/server/json/write": {
1567
+ "import": "./dist/stream/server/json/write.mjs",
1568
+ "require": "./dist/stream/server/json/write.cjs"
1569
+ },
1550
1570
  "./stream/server/sort": {
1551
1571
  "import": "./dist/stream/server/sort.mjs",
1552
1572
  "require": "./dist/stream/server/sort.cjs"
@@ -1819,6 +1839,41 @@
1819
1839
  "import": "./dist/xml/server/getXml.mjs",
1820
1840
  "require": "./dist/xml/server/getXml.cjs"
1821
1841
  },
1842
+ "./zip/_shared": {
1843
+ "import": "./dist/zip/_shared/index.mjs",
1844
+ "require": "./dist/zip/_shared/index.cjs"
1845
+ },
1846
+ "./zip/_shared/crc32": {
1847
+ "import": "./dist/zip/_shared/crc32.mjs",
1848
+ "require": "./dist/zip/_shared/crc32.cjs"
1849
+ },
1850
+ "./zip/_shared/deflate": {
1851
+ "import": "./dist/zip/_shared/deflate.mjs",
1852
+ "require": "./dist/zip/_shared/deflate.cjs"
1853
+ },
1854
+ "./zip/_shared/readZip": {
1855
+ "import": "./dist/zip/_shared/readZip.mjs",
1856
+ "require": "./dist/zip/_shared/readZip.cjs"
1857
+ },
1858
+ "./zip/_shared/writeZip": {
1859
+ "import": "./dist/zip/_shared/writeZip.mjs",
1860
+ "require": "./dist/zip/_shared/writeZip.cjs"
1861
+ },
1862
+ "./zip/_shared/ZipArchive": {
1863
+ "import": "./dist/zip/_shared/ZipArchive.mjs",
1864
+ "require": "./dist/zip/_shared/ZipArchive.cjs"
1865
+ },
1866
+ "./zip/client": {
1867
+ "import": "./dist/zip/client/index.mjs",
1868
+ "require": "./dist/zip/client/index.cjs"
1869
+ },
1870
+ "./zip/server": {
1871
+ "import": "./dist/zip/server/index.mjs",
1872
+ "require": "./dist/zip/server/index.cjs"
1873
+ },
1822
1874
  "./package.json": "./package.json"
1875
+ },
1876
+ "inlinedDependencies": {
1877
+ "@google-cloud/paginator": "7.1.0"
1823
1878
  }
1824
1879
  }