@konstit/csv 0.6.0 → 0.7.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/README.md +113 -101
- package/THIRD_PARTY_NOTICES.md +27 -0
- package/dist/api.d.ts +84 -57
- package/dist/api.js +211 -40
- package/dist/batch-pipeline.d.ts +10 -0
- package/dist/batch-pipeline.js +83 -0
- package/dist/batches.d.ts +36 -1
- package/dist/batches.js +241 -5
- package/dist/cli-command.d.ts +7 -7
- package/dist/cli-command.js +325 -164
- package/dist/cli-schema.d.ts +51 -21
- package/dist/cli-schema.js +126 -65
- package/dist/cli.js +1 -1
- package/dist/file-stream.d.ts +66 -18
- package/dist/file-stream.js +534 -199
- package/dist/files.d.ts +17 -37
- package/dist/files.js +50 -21
- package/dist/gzip-reader.d.ts +2 -0
- package/dist/gzip-reader.js +37 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/inspect-file.d.ts +26 -3
- package/dist/inspect-file.js +169 -74
- package/dist/inspect-zip.d.ts +26 -0
- package/dist/inspect-zip.js +59 -0
- package/dist/latin1-rows.d.ts +11 -3
- package/dist/latin1-rows.js +276 -75
- package/dist/materialize-field.d.ts +6 -0
- package/dist/materialize-field.js +9 -0
- package/dist/native.d.ts +118 -20
- package/dist/native.js +53 -23
- package/dist/normalize.d.ts +7 -1
- package/dist/normalize.js +49 -9
- package/dist/options.d.ts +27 -12
- package/dist/parser.d.ts +34 -14
- package/dist/parser.js +296 -102
- package/dist/strict-schema.d.ts +7 -8
- package/dist/strict-schema.js +45 -83
- package/dist/transforms.d.ts +1 -3
- package/dist/transforms.js +17 -16
- package/dist/types.d.ts +192 -75
- package/dist/zip-entry.d.ts +14 -0
- package/dist/zip-entry.js +155 -0
- package/dist/zip-reader.d.ts +14 -3
- package/dist/zip-reader.js +65 -23
- package/package.json +34 -23
- package/prebuilds/darwin-arm64/libcsv_native.dylib +0 -0
- package/prebuilds/darwin-x64/libcsv_native.dylib +0 -0
- package/prebuilds/linux-x64/libcsv_native.so +0 -0
- package/prebuilds/manifest.json +18 -8
- package/prebuilds/provenance/darwin-arm64.json +1 -1
- package/prebuilds/provenance/darwin-x64.json +1 -1
- package/prebuilds/provenance/linux-x64.json +1 -1
package/dist/inspect-file.js
CHANGED
|
@@ -1,54 +1,89 @@
|
|
|
1
1
|
import { stat } from "node:fs/promises";
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
DELIMITER_CANDIDATES,
|
|
3
|
+
COMPRESSION_PROBE_SIZE,
|
|
4
|
+
delimiterAmbiguityError,
|
|
6
5
|
FILE_PROBE_SIZE,
|
|
7
|
-
|
|
6
|
+
isDelimiterCandidate,
|
|
7
|
+
probeCompression,
|
|
8
8
|
readCsvFileChunks,
|
|
9
9
|
scanCsvFileFormat,
|
|
10
|
-
|
|
10
|
+
scanDelimiterScores,
|
|
11
11
|
selectDelimiter
|
|
12
12
|
} from "./file-stream.js";
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
13
|
+
import { formatBytes } from "./format-bytes.js";
|
|
14
|
+
import {
|
|
15
|
+
inspectZipArchive
|
|
16
|
+
} from "./inspect-zip.js";
|
|
17
|
+
import {
|
|
18
|
+
delimiterByte,
|
|
19
|
+
hasUtf8Bom,
|
|
20
|
+
resolveInputEncoding,
|
|
21
|
+
UTF8_BOM
|
|
22
|
+
} from "./normalize.js";
|
|
23
|
+
export const MAX_INSPECTION_SAMPLE_SIZE = 1048576;
|
|
24
|
+
|
|
25
|
+
export class ZipProbeError extends Error {
|
|
26
|
+
fileSizeBytes;
|
|
27
|
+
archive;
|
|
28
|
+
constructor(cause, fileSizeBytes, archive) {
|
|
29
|
+
super(cause.message, { cause });
|
|
30
|
+
this.fileSizeBytes = fileSizeBytes;
|
|
31
|
+
this.archive = archive;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
15
34
|
export async function inspectCsvFile(path, options = {}) {
|
|
35
|
+
const sampleSize = options.sampleSize ?? FILE_PROBE_SIZE;
|
|
36
|
+
if (!Number.isSafeInteger(sampleSize) || sampleSize < 1 || sampleSize > MAX_INSPECTION_SAMPLE_SIZE)
|
|
37
|
+
throw RangeError("sample size must be between 1 byte and 1 MiB");
|
|
16
38
|
const info = await stat(path);
|
|
17
39
|
if (!info.isFile())
|
|
18
40
|
throw Error("probe requires a regular file");
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
|
|
41
|
+
const configuredCompression = options.compression ?? "auto";
|
|
42
|
+
const compressionSource = configuredCompression === "auto" ? "inferred" : "explicit";
|
|
43
|
+
const readSize = sampleSize + 1;
|
|
44
|
+
const chunkSize = Math.max(COMPRESSION_PROBE_SIZE, Math.min(readSize, FILE_PROBE_SIZE + 1));
|
|
45
|
+
const raw = configuredCompression === "auto" || configuredCompression === "none" ? await Bun.file(path).slice(0, configuredCompression === "auto" ? Math.max(COMPRESSION_PROBE_SIZE, readSize) : readSize).bytes() : new Uint8Array(0);
|
|
46
|
+
const compression = configuredCompression === "auto" ? probeCompression(raw, !0, { kind: "inspection", path }) : configuredCompression;
|
|
47
|
+
if (options.zipEntry !== void 0 && compression !== "zip")
|
|
22
48
|
throw Error("--zip-entry requires a ZIP archive");
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (
|
|
35
|
-
throw error;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
const zipInspection = compression === "zip" ? await inspectZipArchive(path, {
|
|
50
|
+
entry: options.zipEntry,
|
|
51
|
+
chunkSize,
|
|
52
|
+
readSample: (chunks) => readCompressedSample(chunks, readSize)
|
|
53
|
+
}) : void 0;
|
|
54
|
+
const archive = zipInspection?.archive;
|
|
55
|
+
try {
|
|
56
|
+
let zipEntry = null;
|
|
57
|
+
let sample = raw.subarray(0, readSize);
|
|
58
|
+
if (zipInspection !== void 0) {
|
|
59
|
+
const selection = zipInspection.selection;
|
|
60
|
+
if ("error" in selection)
|
|
61
|
+
throw selection.error;
|
|
62
|
+
zipEntry = selection.zipEntry;
|
|
63
|
+
sample = selection.sample;
|
|
64
|
+
} else if (compression !== "none" && compression !== "zip")
|
|
65
|
+
sample = await readCompressedSample(readCsvFileChunks(path, { compression, chunkSize }), readSize);
|
|
66
|
+
const eof = sample.length <= sampleSize;
|
|
67
|
+
const prefix = sample.subarray(0, sampleSize);
|
|
68
|
+
const format = inspectFormat(zipEntry ?? path, prefix, eof, options);
|
|
69
|
+
return {
|
|
70
|
+
fileSizeBytes: info.size,
|
|
71
|
+
sampleBytes: prefix.byteLength,
|
|
72
|
+
sampleReachedEof: eof,
|
|
73
|
+
compression,
|
|
74
|
+
compressionSource,
|
|
75
|
+
zipEntry,
|
|
76
|
+
...archive !== void 0 && (archive.zipArchives !== void 0 || archive.zipEntries.length > 1 || archive.zipEntries.some((entry) => entry.includes("/"))) ? archive : {},
|
|
77
|
+
...format
|
|
78
|
+
};
|
|
79
|
+
} catch (error) {
|
|
80
|
+
if (archive !== void 0 && archive.zipEntries.length > 0 && error instanceof Error)
|
|
81
|
+
throw new ZipProbeError(error, info.size, archive);
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
49
84
|
}
|
|
50
|
-
async function readCompressedSample(chunks) {
|
|
51
|
-
const sample = new Uint8Array(
|
|
85
|
+
async function readCompressedSample(chunks, readSize) {
|
|
86
|
+
const sample = new Uint8Array(readSize);
|
|
52
87
|
let length = 0;
|
|
53
88
|
for await (const chunk of chunks) {
|
|
54
89
|
const take = Math.min(chunk.length, sample.length - length);
|
|
@@ -59,80 +94,140 @@ async function readCompressedSample(chunks) {
|
|
|
59
94
|
}
|
|
60
95
|
return sample.subarray(0, length);
|
|
61
96
|
}
|
|
62
|
-
function inspectFormat(path, prefix, eof,
|
|
97
|
+
function inspectFormat(path, prefix, eof, options) {
|
|
63
98
|
let bytes = prefix;
|
|
64
|
-
let
|
|
99
|
+
let scores;
|
|
100
|
+
let hasBom = !1;
|
|
101
|
+
let encoding = options.encoding ?? "auto";
|
|
102
|
+
const delimiter = options.delimiter ?? "auto";
|
|
65
103
|
const encodingSource = encoding === "auto" ? "inferred" : "explicit";
|
|
66
104
|
if (encoding === "auto") {
|
|
67
105
|
const sample = scanCsvFileFormat(prefix, eof, !0);
|
|
68
106
|
bytes = sample.bytes;
|
|
69
|
-
|
|
107
|
+
scores = sample.scores;
|
|
70
108
|
encoding = sample.encoding;
|
|
109
|
+
hasBom = sample.hasBom;
|
|
71
110
|
} else {
|
|
72
111
|
const decoder = resolveInputEncoding(encoding, delimiter);
|
|
73
|
-
if (typeof decoder === "string")
|
|
112
|
+
if (typeof decoder === "string") {
|
|
74
113
|
encoding = decoder;
|
|
75
|
-
|
|
114
|
+
if (encoding === "utf8" && hasUtf8Bom(bytes))
|
|
115
|
+
bytes = bytes.subarray(UTF8_BOM.length);
|
|
116
|
+
} else {
|
|
76
117
|
bytes = new TextEncoder().encode(decoder.decode(prefix, { stream: !eof }));
|
|
77
118
|
encoding = decoder.encoding;
|
|
78
119
|
}
|
|
79
120
|
}
|
|
80
|
-
|
|
81
|
-
|
|
121
|
+
if (delimiter !== "auto")
|
|
122
|
+
delimiterByte(delimiter, encoding === "latin1" ? "latin1" : "utf8");
|
|
123
|
+
const choice = delimiter === "auto" ? inspectDelimiter(path, scores ?? scanDelimiterScores(bytes, eof), eof, prefix.length, options.explain) : { delimiter, delimiterSource: "explicit", delimiterReason: null, detail: "Set by --delimiter" };
|
|
124
|
+
const { detail, ...delimiterReport } = choice;
|
|
125
|
+
const explanation = options.explain ? { encoding: explainEncoding(prefix, encoding, encodingSource, hasBom), delimiter: detail } : void 0;
|
|
126
|
+
return {
|
|
127
|
+
encoding,
|
|
128
|
+
encodingSource,
|
|
129
|
+
...delimiterReport,
|
|
130
|
+
...inspectRecords(bytes, eof, choice.delimiter),
|
|
131
|
+
...explanation === void 0 ? {} : { explanation }
|
|
132
|
+
};
|
|
82
133
|
}
|
|
83
|
-
function
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if (
|
|
87
|
-
return
|
|
134
|
+
function explainEncoding(prefix, encoding, source, hasBom) {
|
|
135
|
+
if (source === "explicit")
|
|
136
|
+
return "Set by --encoding";
|
|
137
|
+
if (hasBom)
|
|
138
|
+
return "Identified by a byte-order mark (BOM)";
|
|
139
|
+
if (prefix.length === 0)
|
|
140
|
+
return "Using UTF-8 for an empty sample";
|
|
141
|
+
if (encoding === "utf8")
|
|
142
|
+
return prefix.every((byte) => byte < 128) ? "ASCII-only sample fits UTF-8, Latin-1, and Windows-1252. Using UTF-8." : "Sample bytes are consistent with UTF-8";
|
|
143
|
+
return encoding === "windows-1252" ? "Sample is invalid UTF-8 and contains bytes in the range 0x80\u20130x9F" : "Sample is invalid UTF-8 and contains no bytes in the range 0x80\u20130x9F";
|
|
144
|
+
}
|
|
145
|
+
function inspectDelimiter(path, scores, eof, sampleBytes, explain) {
|
|
146
|
+
const choice = selectDelimiter(path, scores);
|
|
147
|
+
if ("delimiter" in choice) {
|
|
148
|
+
let detail = "Separator count is consistent across the records used for detection";
|
|
149
|
+
if (explain && choice.extensionHint !== void 0)
|
|
150
|
+
detail = choice.extensionBrokeTie ? `The ${choice.extensionHint} filename hint resolved a tie in quoting evidence` : `Stable separator counts and quoting evidence support the ${choice.extensionHint} filename hint`;
|
|
151
|
+
return { delimiter: choice.delimiter, delimiterSource: "inferred", delimiterReason: null, detail };
|
|
152
|
+
}
|
|
88
153
|
let reason;
|
|
89
154
|
switch (choice.reason) {
|
|
90
155
|
case "no-records":
|
|
91
|
-
reason = sampleBytes === 0 ? "Empty payload" : eof ? "No complete non-empty record in the payload" :
|
|
156
|
+
reason = sampleBytes === 0 ? "Empty payload" : eof ? "No complete non-empty record in the payload" : `No complete non-empty record in the ${formatBytes(sampleBytes)} sample`;
|
|
92
157
|
break;
|
|
93
158
|
case "no-stable-separator": {
|
|
94
|
-
|
|
95
|
-
reason = perRecord.some((row) => row.some((count) => count > 0)) ? "Separator counts vary across sampled records" : "No supported separator found in sampled records";
|
|
159
|
+
reason = scores.hasSeparator ? "Separator counts vary across sampled records" : "No supported separator found in sampled records";
|
|
96
160
|
break;
|
|
97
161
|
}
|
|
98
162
|
case "ambiguous":
|
|
163
|
+
if (choice.conflictingHint)
|
|
164
|
+
throw delimiterAmbiguityError(choice.candidates);
|
|
99
165
|
reason = `Ambiguous between ${choice.candidates.map((c) => JSON.stringify(c)).join(" and ")}`;
|
|
100
166
|
break;
|
|
167
|
+
case "weak-separator":
|
|
168
|
+
reason = `Could not confirm ${JSON.stringify(choice.candidate)} from one separator per record without stronger quoting evidence`;
|
|
169
|
+
break;
|
|
101
170
|
}
|
|
102
|
-
return { delimiter: null, delimiterSource: null, delimiterReason: reason };
|
|
171
|
+
return { delimiter: null, delimiterSource: null, delimiterReason: reason, detail: reason };
|
|
103
172
|
}
|
|
104
173
|
function inspectRecords(bytes, eof, delimiter) {
|
|
105
174
|
const separator = delimiter?.charCodeAt(0);
|
|
106
175
|
const endings = new Set;
|
|
107
176
|
let quoted = !1;
|
|
108
|
-
let
|
|
177
|
+
let atFieldStart = !0;
|
|
178
|
+
let recordStart = 0;
|
|
109
179
|
let columns = 1;
|
|
180
|
+
let count = 0;
|
|
181
|
+
let firstRecordColumns = bytes.length === 0 ? 0 : null;
|
|
182
|
+
let minColumns = 1 / 0;
|
|
183
|
+
let maxColumns = 0;
|
|
110
184
|
let unknownWidth = !1;
|
|
185
|
+
function finishRecord() {
|
|
186
|
+
if (count === 0 && !unknownWidth)
|
|
187
|
+
firstRecordColumns = columns;
|
|
188
|
+
++count;
|
|
189
|
+
minColumns = Math.min(minColumns, columns);
|
|
190
|
+
maxColumns = Math.max(maxColumns, columns);
|
|
191
|
+
columns = 1;
|
|
192
|
+
}
|
|
111
193
|
for (let i = 0;i < bytes.length; ++i) {
|
|
112
194
|
const byte = bytes[i];
|
|
113
|
-
if (
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
if (byte === 13 || byte === 10) {
|
|
117
|
-
firstRecord = !1;
|
|
118
|
-
if (byte === 13 && bytes[i + 1] === 10) {
|
|
119
|
-
endings.add("CRLF");
|
|
195
|
+
if (quoted) {
|
|
196
|
+
if (byte === 34)
|
|
197
|
+
if (bytes[i + 1] === 34)
|
|
120
198
|
++i;
|
|
121
|
-
} else if (byte === 13 && i + 1 === bytes.length && !eof)
|
|
122
|
-
break;
|
|
123
199
|
else
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
200
|
+
quoted = !1;
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
if (byte === 13 || byte === 10) {
|
|
204
|
+
finishRecord();
|
|
205
|
+
atFieldStart = !0;
|
|
206
|
+
if (byte === 13 && bytes[i + 1] === 10) {
|
|
207
|
+
endings.add("CRLF");
|
|
208
|
+
++i;
|
|
209
|
+
} else if (byte === 13 && i + 1 === bytes.length && !eof)
|
|
210
|
+
break;
|
|
211
|
+
else
|
|
212
|
+
endings.add(byte === 10 ? "LF" : "CR");
|
|
213
|
+
recordStart = i + 1;
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
if (byte === 34 && atFieldStart)
|
|
217
|
+
quoted = !0;
|
|
218
|
+
atFieldStart = separator === void 0 ? isDelimiterCandidate(byte) : byte === separator;
|
|
219
|
+
if (atFieldStart) {
|
|
220
|
+
++columns;
|
|
221
|
+
unknownWidth ||= separator === void 0;
|
|
131
222
|
}
|
|
132
223
|
}
|
|
133
|
-
|
|
224
|
+
if (eof && !quoted && recordStart < bytes.length)
|
|
225
|
+
finishRecord();
|
|
134
226
|
return {
|
|
135
|
-
firstRecordColumns
|
|
136
|
-
lineEnding: endings.size > 1 ? "mixed" : endings.values().next().value ?? (eof ? "none" : "unknown")
|
|
227
|
+
firstRecordColumns,
|
|
228
|
+
lineEnding: endings.size > 1 ? "mixed" : endings.values().next().value ?? (eof ? "none" : "unknown"),
|
|
229
|
+
sampledRecords: unknownWidth ? null : count,
|
|
230
|
+
minRecordColumns: unknownWidth || count === 0 ? null : minColumns,
|
|
231
|
+
maxRecordColumns: unknownWidth || count === 0 ? null : maxColumns
|
|
137
232
|
};
|
|
138
233
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface ZipTree {
|
|
2
|
+
readonly zipEntries: readonly string[];
|
|
3
|
+
readonly zipArchives?: readonly NestedZipArchive[];
|
|
4
|
+
}
|
|
5
|
+
export type NestedZipArchive = {
|
|
6
|
+
readonly path: string;
|
|
7
|
+
} & (ZipTree | {
|
|
8
|
+
readonly error: string;
|
|
9
|
+
});
|
|
10
|
+
interface ZipEntrySample {
|
|
11
|
+
readonly zipEntry: string;
|
|
12
|
+
readonly sample: Uint8Array<ArrayBuffer>;
|
|
13
|
+
}
|
|
14
|
+
interface ZipEntryRequest {
|
|
15
|
+
readonly entry?: string;
|
|
16
|
+
readonly chunkSize: number;
|
|
17
|
+
readonly readSample: (chunks: Iterable<Uint8Array>) => Promise<Uint8Array<ArrayBuffer>>;
|
|
18
|
+
}
|
|
19
|
+
interface ZipInspection {
|
|
20
|
+
readonly archive?: ZipTree;
|
|
21
|
+
readonly selection: ZipEntrySample | {
|
|
22
|
+
readonly error: unknown;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export declare function inspectZipArchive(path: string, request: ZipEntryRequest): Promise<ZipInspection>;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { isZipSignature } from "./file-stream.js";
|
|
2
|
+
import {
|
|
3
|
+
AmbiguousZipGlobError,
|
|
4
|
+
isZipMember,
|
|
5
|
+
MAX_NESTED_ZIP_DEPTH,
|
|
6
|
+
openNestedZip,
|
|
7
|
+
withZipEntry
|
|
8
|
+
} from "./zip-entry.js";
|
|
9
|
+
import {
|
|
10
|
+
readZipDirectory
|
|
11
|
+
} from "./zip-reader.js";
|
|
12
|
+
export async function inspectZipArchive(path, request) {
|
|
13
|
+
const archive = request.entry === void 0 ? await inspectZipTree(path) : void 0;
|
|
14
|
+
try {
|
|
15
|
+
await using resources = new AsyncDisposableStack;
|
|
16
|
+
const selection = await withZipEntry(path, { format: "zip", entry: request.entry ?? "*" }, resources, async (reader, prefix) => {
|
|
17
|
+
const entry = reader.entryName;
|
|
18
|
+
if (archive?.zipArchives?.some((nested) => nested.path === entry && ("zipEntries" in nested)))
|
|
19
|
+
throw Error("Selected entry is a nested ZIP archive");
|
|
20
|
+
const sample = await request.readSample(reader.chunks(request.chunkSize));
|
|
21
|
+
if (isZipMember(entry) && isZipSignature(sample))
|
|
22
|
+
throw Error("Selected entry is a nested ZIP archive");
|
|
23
|
+
return { zipEntry: prefix + entry, sample };
|
|
24
|
+
});
|
|
25
|
+
return { archive, selection };
|
|
26
|
+
} catch (error) {
|
|
27
|
+
if (archive !== void 0)
|
|
28
|
+
return { archive, selection: { error } };
|
|
29
|
+
if (error instanceof AmbiguousZipGlobError)
|
|
30
|
+
return { selection: { error } };
|
|
31
|
+
try {
|
|
32
|
+
return { archive: await inspectZipTree(path), selection: { error } };
|
|
33
|
+
} catch {
|
|
34
|
+
return { selection: { error } };
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async function inspectZipTree(source, depth = 0) {
|
|
39
|
+
const zipEntries = readZipDirectory(source);
|
|
40
|
+
const zipArchives = [];
|
|
41
|
+
for (const entry of new Set(zipEntries.filter(isZipMember))) {
|
|
42
|
+
if (depth >= MAX_NESTED_ZIP_DEPTH) {
|
|
43
|
+
zipArchives.push({ path: entry, error: `ZIP nesting exceeds ${MAX_NESTED_ZIP_DEPTH} levels` });
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
await using resources = new AsyncDisposableStack;
|
|
48
|
+
const innerSource = await openNestedZip(source, { format: "zip", entry }, resources);
|
|
49
|
+
const tree = await inspectZipTree(innerSource, depth + 1);
|
|
50
|
+
zipArchives.push({ path: entry, ...tree });
|
|
51
|
+
} catch (error) {
|
|
52
|
+
zipArchives.push({ path: entry, error: nestedArchiveError(error) });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return { zipEntries, ...zipArchives.length === 0 ? {} : { zipArchives } };
|
|
56
|
+
}
|
|
57
|
+
function nestedArchiveError(error) {
|
|
58
|
+
return error instanceof Error && error.message.startsWith("native ZIP reader failed: ") ? error.message : "Failed to read nested ZIP archive";
|
|
59
|
+
}
|
package/dist/latin1-rows.d.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
+
import { type MappedRowLayout } from './batches.js';
|
|
2
|
+
import type { CsvFileInput } from './file-stream.js';
|
|
1
3
|
import { type NativePointer } from './native.js';
|
|
2
|
-
import type { CsvColumns, CsvDelimiter, CsvNativeFilterProgramEntry, CsvParserOptions, CsvRow, CsvTransform, CsvTransformOptions } from './types.js';
|
|
4
|
+
import type { CsvColumns, CsvDelimiter, CsvMappedRow, CsvNativeFilterProgramEntry, CsvParserOptions, CsvRow, CsvTransform, CsvTransformOptions } from './types.js';
|
|
5
|
+
type Latin1RowsOptions = Pick<CsvParserOptions, 'limit' | 'skipRows' | 'skipEmptyLines' | 'strict' | 'maxRecordBytes' | 'expectedHeaders' | 'requireHeader' | 'minDataRows'> & CsvTransformOptions & {
|
|
6
|
+
readonly maxBatchRows?: number;
|
|
7
|
+
};
|
|
8
|
+
type Latin1RowsInput = CsvFileInput | AsyncIterable<Uint8Array> | Iterable<Uint8Array>;
|
|
3
9
|
export declare function canUseFilteredLatin1Cleanup(columns: CsvColumns | undefined, filters: readonly CsvNativeFilterProgramEntry[] | undefined, transforms: readonly CsvTransform[]): boolean;
|
|
4
|
-
export declare function latin1Rows(
|
|
5
|
-
export declare function
|
|
10
|
+
export declare function latin1Rows(input: Latin1RowsInput, delimiter: CsvDelimiter, columns: CsvColumns | undefined, filters: readonly CsvNativeFilterProgramEntry[] | undefined, createParser: (delimiter: number) => NativePointer | null, layout: MappedRowLayout, options?: Latin1RowsOptions): AsyncGenerator<CsvMappedRow[], void>;
|
|
11
|
+
export declare function latin1Rows(input: Latin1RowsInput, delimiter: CsvDelimiter, columns: CsvColumns | undefined, filters: readonly CsvNativeFilterProgramEntry[] | undefined, createParser: (delimiter: number) => NativePointer | null, reusableRows?: CsvRow[], options?: Latin1RowsOptions): AsyncGenerator<CsvRow[], void>;
|
|
12
|
+
export declare function checkedOffset(words: Uint32Array, index: number, upperBound: number, wordsPerOffset?: 1 | 2): number;
|
|
13
|
+
export {};
|