@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/files.d.ts
CHANGED
|
@@ -8,8 +8,7 @@ import type { CsvEncoding, CsvFileOptions, CsvNativeProjectionOptions, CsvParser
|
|
|
8
8
|
* options are captured when the function is called; changing an options array
|
|
9
9
|
* while parsing cannot change the operation.
|
|
10
10
|
*
|
|
11
|
-
*
|
|
12
|
-
* Use an explicit one-character delimiter for in-memory input.
|
|
11
|
+
* The delimiter is detected by default. Supply uncompressed bytes with a known encoding.
|
|
13
12
|
*
|
|
14
13
|
* @param buffer Complete CSV bytes to parse.
|
|
15
14
|
* @param suppliedOptions Parser, projection, and strict-schema options.
|
|
@@ -25,37 +24,22 @@ import type { CsvEncoding, CsvFileOptions, CsvNativeProjectionOptions, CsvParser
|
|
|
25
24
|
* ```
|
|
26
25
|
*/
|
|
27
26
|
export declare function parseCsvBuffer(buffer: NodeJS.TypedArray | DataView, suppliedOptions?: CsvParserOptions<CsvEncoding>): CsvRow[];
|
|
28
|
-
/**
|
|
29
|
-
* Count rows in bytes known to contain one record per physical line.
|
|
30
|
-
*
|
|
31
|
-
* This is a structural newline counter rather than a CSV parser: newlines in
|
|
32
|
-
* quoted fields are counted as row boundaries. The native counter counts each
|
|
33
|
-
* LF byte; a final byte other than LF or CR adds one unterminated row. Thus a
|
|
34
|
-
* CRLF ending counts once through its LF, while a standalone CR is not a row
|
|
35
|
-
* separator. Use it only for trusted newline-delimited data.
|
|
36
|
-
*
|
|
37
|
-
* @param buffer Newline-delimited bytes. Typed-array views are counted from their visible byte range.
|
|
38
|
-
* @returns The number of physical lines, represented as a safe JavaScript number.
|
|
39
|
-
* @throws If the count cannot be represented safely as a JavaScript number.
|
|
40
|
-
*/
|
|
41
|
-
export declare function countTrustedNewlineRows(buffer: NodeJS.TypedArray | DataView): number;
|
|
42
27
|
/**
|
|
43
28
|
* Find byte offsets at which a CSV file can be split without breaking a record.
|
|
44
29
|
*
|
|
45
30
|
* Returned offsets include `0` and the file byte length. Intermediate offsets
|
|
46
31
|
* are chosen at record boundaries, including records containing quoted
|
|
47
|
-
* newlines, and approximate the requested number of shards. The
|
|
48
|
-
*
|
|
49
|
-
* one-character delimiter.
|
|
32
|
+
* newlines, and approximate the requested number of shards. The delimiter
|
|
33
|
+
* is detected from a prefix of the raw file bytes by default.
|
|
50
34
|
*
|
|
51
35
|
* @param path Path to the uncompressed CSV file.
|
|
52
|
-
* @param shardCount Desired number of shards. It must be a positive integer.
|
|
53
|
-
* @param delimiter One-byte CSV delimiter
|
|
36
|
+
* @param shardCount Desired number of shards. It must be a positive safe integer.
|
|
37
|
+
* @param delimiter One-byte CSV delimiter or `'auto'` (the default).
|
|
54
38
|
* @returns Nondecreasing byte offsets suitable as half-open shard starts and ends.
|
|
55
|
-
* @throws {RangeError} If `shardCount` is not a positive integer.
|
|
56
|
-
* @throws If
|
|
39
|
+
* @throws {RangeError} If `shardCount` is not a positive safe integer.
|
|
40
|
+
* @throws If the delimiter cannot be resolved or the native scan fails.
|
|
57
41
|
*/
|
|
58
|
-
export declare function findCsvSafeSplitOffsets(path: string, shardCount: number, delimiter?: string): number[];
|
|
42
|
+
export declare function findCsvSafeSplitOffsets(path: string, shardCount: number, delimiter?: string, encoding?: 'utf8' | 'latin1'): number[];
|
|
59
43
|
/**
|
|
60
44
|
* Return inclusive byte ranges that can each be read as complete CSV records.
|
|
61
45
|
*
|
|
@@ -65,13 +49,13 @@ export declare function findCsvSafeSplitOffsets(path: string, shardCount: number
|
|
|
65
49
|
* are inclusive.
|
|
66
50
|
*
|
|
67
51
|
* @param path Path to the uncompressed CSV file.
|
|
68
|
-
* @param shardCount Desired number of shards. It must be a positive integer.
|
|
69
|
-
* @param delimiter One-byte CSV delimiter
|
|
52
|
+
* @param shardCount Desired number of shards. It must be a positive safe integer.
|
|
53
|
+
* @param delimiter One-byte CSV delimiter or `'auto'` (the default).
|
|
70
54
|
* @returns Non-empty, record-safe ranges in file order.
|
|
71
|
-
* @throws {RangeError} If `shardCount` is not a positive integer.
|
|
72
|
-
* @throws If
|
|
55
|
+
* @throws {RangeError} If `shardCount` is not a positive safe integer.
|
|
56
|
+
* @throws If the delimiter cannot be resolved or the native scan fails.
|
|
73
57
|
*/
|
|
74
|
-
export declare function findCsvSafeShards(path: string, shardCount: number, delimiter?: string): CsvShard[];
|
|
58
|
+
export declare function findCsvSafeShards(path: string, shardCount: number, delimiter?: string, encoding?: 'utf8' | 'latin1'): CsvShard[];
|
|
75
59
|
/**
|
|
76
60
|
* Stream materialized row arrays from a CSV file.
|
|
77
61
|
*
|
|
@@ -108,14 +92,12 @@ export declare function parseCsvFile(path: string, options?: CsvFileOptions): As
|
|
|
108
92
|
* physical columns before materialization. Options are snapshotted at call
|
|
109
93
|
* time, including nested filter values.
|
|
110
94
|
*
|
|
111
|
-
* Strict
|
|
112
|
-
* quote parsing and strict schema metadata. Use `parseCsvFile` when strict
|
|
113
|
-
* validation is required.
|
|
95
|
+
* Strict validation uses the physical fields before projection or filtering.
|
|
114
96
|
*
|
|
115
97
|
* @param path Path to the CSV file (or compressed/ZIP input selected by `options.compression`).
|
|
116
98
|
* @param options Native projection/filter and file parser options.
|
|
117
99
|
* @returns An async generator of non-empty projected row batches.
|
|
118
|
-
* @throws When
|
|
100
|
+
* @throws When I/O, decompression, validation, or parsing fails during iteration.
|
|
119
101
|
*
|
|
120
102
|
* @example
|
|
121
103
|
* ```ts
|
|
@@ -135,14 +117,12 @@ export declare function parseCsvFileProjected(path: string, options?: CsvFileOpt
|
|
|
135
117
|
*
|
|
136
118
|
* The parser honors quoted newlines and supports the same compression and
|
|
137
119
|
* delimiter options as file parsing. With `strict: true`, quote syntax
|
|
138
|
-
*
|
|
139
|
-
* supported by this counting path; use row parsing when headers or minimum
|
|
140
|
-
* data-row constraints must be checked.
|
|
120
|
+
* and physical widths are validated while counting. Schema options apply to the consumed records.
|
|
141
121
|
*
|
|
142
122
|
* @param path Path to the CSV file (or compressed/ZIP input selected by `suppliedOptions.compression`).
|
|
143
123
|
* @param suppliedOptions File and parser options.
|
|
144
124
|
* @returns A promise for the logical CSV record count.
|
|
145
|
-
* @throws When
|
|
125
|
+
* @throws When reading, decompression, parsing, or validation fails, or the count exceeds the safe integer range.
|
|
146
126
|
*
|
|
147
127
|
* @example
|
|
148
128
|
* ```ts
|
package/dist/files.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
closeSync,
|
|
3
|
+
constants,
|
|
4
|
+
fstatSync,
|
|
5
|
+
openSync,
|
|
6
|
+
readSync
|
|
7
|
+
} from "node:fs";
|
|
8
|
+
import {
|
|
9
|
+
detectBufferDelimiter,
|
|
10
|
+
FILE_PROBE_SIZE,
|
|
11
|
+
prepareCsvFileInput
|
|
12
|
+
} from "./file-stream.js";
|
|
2
13
|
import {
|
|
3
14
|
native,
|
|
4
15
|
u64ToSafeNumber
|
|
@@ -8,7 +19,7 @@ import {
|
|
|
8
19
|
toArrayBuffer
|
|
9
20
|
} from "./native.js";
|
|
10
21
|
import {
|
|
11
|
-
|
|
22
|
+
delimiterByte,
|
|
12
23
|
prepareCsvBufferInput,
|
|
13
24
|
rejectSelectedColumns
|
|
14
25
|
} from "./normalize.js";
|
|
@@ -19,11 +30,11 @@ import {
|
|
|
19
30
|
NativeCsvParser,
|
|
20
31
|
parseFileChunks
|
|
21
32
|
} from "./parser.js";
|
|
22
|
-
import { rejectStrictSchemaUnsupported } from "./strict-schema.js";
|
|
23
33
|
export function parseCsvBuffer(buffer, suppliedOptions = {}) {
|
|
24
34
|
const options = snapshotCsvOptions(suppliedOptions);
|
|
25
35
|
const input = prepareCsvBufferInput(buffer, options.encoding, options.delimiter);
|
|
26
|
-
|
|
36
|
+
const delimiter = options.delimiter === void 0 || options.delimiter === "auto" ? detectBufferDelimiter(input.bytes, "", !0, options) : options.delimiter;
|
|
37
|
+
using parser = createPreparedParser({ ...options, encoding: input.parserEncoding, delimiter });
|
|
27
38
|
const batch = parser.writeBatch(input.bytes, !0);
|
|
28
39
|
try {
|
|
29
40
|
return batch.rowsInto([], options.columns);
|
|
@@ -31,18 +42,13 @@ export function parseCsvBuffer(buffer, suppliedOptions = {}) {
|
|
|
31
42
|
batch.close();
|
|
32
43
|
}
|
|
33
44
|
}
|
|
34
|
-
export function
|
|
35
|
-
if (
|
|
36
|
-
return 0;
|
|
37
|
-
const input = normalizeChunk(buffer);
|
|
38
|
-
return u64ToSafeNumber(native.symbols.csv_parser_count_trusted_newlines(input, input), "CSV newline row count");
|
|
39
|
-
}
|
|
40
|
-
export function findCsvSafeSplitOffsets(path, shardCount, delimiter = ",") {
|
|
41
|
-
if (!Number.isInteger(shardCount) || shardCount <= 0)
|
|
45
|
+
export function findCsvSafeSplitOffsets(path, shardCount, delimiter = "auto", encoding = "utf8") {
|
|
46
|
+
if (!Number.isSafeInteger(shardCount) || shardCount <= 0)
|
|
42
47
|
throw RangeError(`invalid shard count: ${shardCount}`);
|
|
43
|
-
if (
|
|
44
|
-
throw
|
|
45
|
-
const
|
|
48
|
+
if (path.includes("\x00"))
|
|
49
|
+
throw TypeError("CSV path must not contain a null byte");
|
|
50
|
+
const resolved = delimiter === "auto" ? detectBufferDelimiter(readShardingPrefix(path), path, !0, void 0, encoding === "utf8") : delimiter;
|
|
51
|
+
const batch = native.symbols.csv_parser_find_split_offsets_v2(Buffer.from(`${path}\x00`), BigInt(shardCount), delimiterByte(resolved, encoding), encoding === "utf8");
|
|
46
52
|
if (batch === null)
|
|
47
53
|
throw Error(`native CSV split offset scan failed: ${path}`);
|
|
48
54
|
try {
|
|
@@ -54,8 +60,31 @@ export function findCsvSafeSplitOffsets(path, shardCount, delimiter = ",") {
|
|
|
54
60
|
native.symbols.csv_split_offsets_batch_destroy(batch);
|
|
55
61
|
}
|
|
56
62
|
}
|
|
57
|
-
|
|
58
|
-
|
|
63
|
+
function readShardingPrefix(path) {
|
|
64
|
+
try {
|
|
65
|
+
const file = openSync(path, constants.O_RDONLY | constants.O_NONBLOCK);
|
|
66
|
+
try {
|
|
67
|
+
const stats = fstatSync(file);
|
|
68
|
+
if (!stats.isFile())
|
|
69
|
+
throw Error("CSV shard input must be a regular file");
|
|
70
|
+
const prefix = Buffer.allocUnsafe(FILE_PROBE_SIZE + 1);
|
|
71
|
+
let length = 0;
|
|
72
|
+
while (length < prefix.length) {
|
|
73
|
+
const bytesRead = readSync(file, prefix, length, prefix.length - length, length);
|
|
74
|
+
if (bytesRead === 0)
|
|
75
|
+
break;
|
|
76
|
+
length += bytesRead;
|
|
77
|
+
}
|
|
78
|
+
return prefix.subarray(0, length);
|
|
79
|
+
} finally {
|
|
80
|
+
closeSync(file);
|
|
81
|
+
}
|
|
82
|
+
} catch (error) {
|
|
83
|
+
throw Error(`native CSV split offset scan failed: ${path}`, { cause: error });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
export function findCsvSafeShards(path, shardCount, delimiter = "auto", encoding = "utf8") {
|
|
87
|
+
const offsets = findCsvSafeSplitOffsets(path, shardCount, delimiter, encoding);
|
|
59
88
|
const shards = [];
|
|
60
89
|
for (let index = 0;index < offsets.length - 1; ++index) {
|
|
61
90
|
const start = offsets[index] ?? 0;
|
|
@@ -83,13 +112,17 @@ export function parseCsvFileProjected(path, options = {}) {
|
|
|
83
112
|
return iterateCsvFileProjected(path, snapshotCsvOptions({
|
|
84
113
|
encoding: options.encoding,
|
|
85
114
|
delimiter: options.delimiter,
|
|
115
|
+
quote: options.quote,
|
|
116
|
+
recordDelimiter: options.recordDelimiter,
|
|
86
117
|
compression: options.compression,
|
|
87
118
|
chunkSize: options.chunkSize,
|
|
88
119
|
columns: options.columns,
|
|
89
120
|
equalsFilter: options.equalsFilter,
|
|
90
121
|
filters: options.filters,
|
|
91
122
|
fixedColumns: options.fixedColumns,
|
|
123
|
+
maxRecordBytes: options.maxRecordBytes,
|
|
92
124
|
skipRows: options.skipRows,
|
|
125
|
+
skipEmptyLines: options.skipEmptyLines,
|
|
93
126
|
limit: options.limit,
|
|
94
127
|
strict: options.strict,
|
|
95
128
|
expectedHeaders: options.expectedHeaders,
|
|
@@ -98,17 +131,13 @@ export function parseCsvFileProjected(path, options = {}) {
|
|
|
98
131
|
}));
|
|
99
132
|
}
|
|
100
133
|
async function* iterateCsvFileProjected(path, options) {
|
|
101
|
-
rejectStrictSchemaUnsupported(options, "projected file parsing");
|
|
102
134
|
await using input = await prepareCsvFileInput(path, options);
|
|
103
|
-
if (options.strict === !0)
|
|
104
|
-
throw Error("strict CSV validation is not supported for projected batches");
|
|
105
135
|
using parser = new NativeCsvParser({ ...options, encoding: input.parserEncoding, delimiter: input.delimiter });
|
|
106
136
|
for await (using batch of parseFileChunks(input, parser, options.limit))
|
|
107
137
|
yield batch.rows();
|
|
108
138
|
}
|
|
109
139
|
export async function countCsvFile(path, suppliedOptions = {}) {
|
|
110
140
|
const options = snapshotCsvOptions(suppliedOptions);
|
|
111
|
-
rejectStrictSchemaUnsupported(options, "count");
|
|
112
141
|
await using input = await prepareCsvFileInput(path, options, "count");
|
|
113
142
|
return await countFileChunks(input, { ...options, encoding: input.parserEncoding, delimiter: input.delimiter });
|
|
114
143
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {
|
|
2
|
+
native
|
|
3
|
+
} from "./native.js";
|
|
4
|
+
import { validateChunkSize } from "./normalize.js";
|
|
5
|
+
const gzipReaderFinalizer = new FinalizationRegistry(native.symbols.csv_gzip_reader_destroy);
|
|
6
|
+
export function* readGzipFileChunks(fd, chunkSize, reuseBuffer, readAhead = !0) {
|
|
7
|
+
validateChunkSize(chunkSize);
|
|
8
|
+
const handle = native.symbols.csv_gzip_reader_create(fd);
|
|
9
|
+
if (handle === null)
|
|
10
|
+
throw Error("failed to create native gzip reader");
|
|
11
|
+
const lifetime = {};
|
|
12
|
+
gzipReaderFinalizer.register(lifetime, handle, lifetime);
|
|
13
|
+
try {
|
|
14
|
+
const reusableBuffer = reuseBuffer ? new Uint8Array(chunkSize) : void 0;
|
|
15
|
+
let startProducer = readAhead;
|
|
16
|
+
while (!0) {
|
|
17
|
+
const buffer = reusableBuffer ?? new Uint8Array(chunkSize);
|
|
18
|
+
const size = Number(native.symbols.csv_gzip_reader_read(handle, buffer, buffer));
|
|
19
|
+
if (size < 0) {
|
|
20
|
+
const message = native.symbols.csv_gzip_reader_last_error(handle)?.toString() ?? "gzip read failed";
|
|
21
|
+
throw TypeError(message);
|
|
22
|
+
}
|
|
23
|
+
if (size === 0)
|
|
24
|
+
return;
|
|
25
|
+
if (size > buffer.length)
|
|
26
|
+
throw Error("native gzip reader returned an invalid output length");
|
|
27
|
+
yield size === buffer.length ? buffer : buffer.subarray(0, size);
|
|
28
|
+
if (startProducer) {
|
|
29
|
+
native.symbols.csv_gzip_reader_enable_read_ahead(handle, chunkSize);
|
|
30
|
+
startProducer = !1;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
} finally {
|
|
34
|
+
gzipReaderFinalizer.unregister(lifetime);
|
|
35
|
+
native.symbols.csv_gzip_reader_destroy(handle);
|
|
36
|
+
}
|
|
37
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export type { CsvApiFileOptions, CsvBatchesOptions, CsvColumn, CsvColumnBytesCallback, CsvColumnRangeCallback, CsvColumns, CsvColumnSelection, CsvCompression, CsvCountOptions, CsvDelimiter, CsvEncoding, CsvEqualsFilter, CsvFieldRange, CsvFieldValue, CsvFileEncoding, CsvFileOptions, CsvFilter, CsvFilterColumn, CsvInFilter, CsvNativeEncoding, CsvNativeFilter, CsvNativeFilterOperator, CsvNativeFilterProgramEntry, CsvNativeProjectionOptions, CsvNotEqualsFilter, CsvNotInFilter, CsvParseOptions, CsvParserOptions, CsvProjectedRow, CsvRegex, CsvRegexFilter, CsvRow, CsvRowsOptions, CsvScanColumnsCallback, CsvShard, CsvShardingOptions, CsvStartsWithFilter, CsvTransform, CsvTransformChain, CsvTransformMethods, CsvTransformOptions, CsvZipCompression, NativeCsvParserOptions, NativeCsvRowCallback, } from './types.js';
|
|
1
|
+
export type { CsvApiFileOptions, CsvBatchesOptions, CsvColumn, CsvColumnBytesCallback, CsvColumnRangeCallback, CsvColumns, CsvColumnSelection, CsvCompression, CsvCountOptions, CsvDelimiter, CsvEncoding, CsvEqualsFilter, CsvFieldRange, CsvFieldValue, CsvFileEncoding, CsvFileOptions, CsvFilter, CsvFilterColumn, CsvHeaderColumn, CsvHeaderSource, CsvInFilter, CsvInput, CsvMappedRow, CsvNamedCountOptions, CsvNamedRowsOptions, CsvNativeEncoding, CsvNativeFilter, CsvNativeFilterOperator, CsvNativeFilterProgramEntry, CsvNativeProjectionOptions, CsvNotEqualsFilter, CsvNotInFilter, CsvParseOptions, CsvParserOptions, CsvProjectedRow, CsvRawRecordBatchesOptions, CsvRegex, CsvRegexFilter, CsvRow, CsvRowsOptions, CsvScanColumnsCallback, CsvShard, CsvShardingOptions, CsvStartsWithFilter, CsvTransform, CsvTransformChain, CsvTransformMethods, CsvTransformOptions, CsvZipCompression, NativeCsvParserOptions, NativeCsvRowCallback, } from './types.js';
|
|
2
2
|
export { csv } from './api.js';
|
|
3
|
-
export { NativeCsvBatch, NativeCsvRowView } from './batches.js';
|
|
4
|
-
export { countCsvFile,
|
|
3
|
+
export { NativeCsvBatch, NativeCsvRawRecordBatch, NativeCsvRowView } from './batches.js';
|
|
4
|
+
export { countCsvFile, parseCsvBuffer, parseCsvFile, parseCsvFileProjected } from './files.js';
|
|
5
5
|
export { defineCountOptions, defineRowsOptions } from './options.js';
|
|
6
6
|
export { NativeCsvParser } from './parser.js';
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { requireBunRuntime } from "./runtime.js";
|
|
2
2
|
requireBunRuntime();
|
|
3
3
|
export { csv } from "./api.js";
|
|
4
|
-
export { NativeCsvBatch, NativeCsvRowView } from "./batches.js";
|
|
5
|
-
export { countCsvFile,
|
|
4
|
+
export { NativeCsvBatch, NativeCsvRawRecordBatch, NativeCsvRowView } from "./batches.js";
|
|
5
|
+
export { countCsvFile, parseCsvBuffer, parseCsvFile, parseCsvFileProjected } from "./files.js";
|
|
6
6
|
export { defineCountOptions, defineRowsOptions } from "./options.js";
|
|
7
7
|
export { NativeCsvParser } from "./parser.js";
|
package/dist/inspect-file.d.ts
CHANGED
|
@@ -1,21 +1,44 @@
|
|
|
1
|
+
import { type ResolvedCompression } from './file-stream.js';
|
|
2
|
+
import { type NestedZipArchive, type ZipTree } from './inspect-zip.js';
|
|
3
|
+
export declare const MAX_INSPECTION_SAMPLE_SIZE: number;
|
|
4
|
+
type FormatSource = 'explicit' | 'inferred';
|
|
1
5
|
interface InspectionOptions {
|
|
2
6
|
readonly zipEntry?: string;
|
|
3
7
|
readonly delimiter?: string;
|
|
4
8
|
readonly encoding?: string;
|
|
9
|
+
readonly compression?: ResolvedCompression | 'auto';
|
|
10
|
+
readonly sampleSize?: number;
|
|
11
|
+
readonly explain?: boolean;
|
|
12
|
+
}
|
|
13
|
+
interface InspectionExplanation {
|
|
14
|
+
encoding: string;
|
|
15
|
+
delimiter: string;
|
|
5
16
|
}
|
|
6
17
|
interface FileInspection {
|
|
7
18
|
fileSizeBytes: number;
|
|
8
19
|
sampleBytes: number;
|
|
9
20
|
sampleReachedEof: boolean;
|
|
10
|
-
compression:
|
|
21
|
+
compression: ResolvedCompression;
|
|
22
|
+
compressionSource: FormatSource;
|
|
11
23
|
zipEntry: string | null;
|
|
24
|
+
zipEntries?: readonly string[];
|
|
25
|
+
zipArchives?: readonly NestedZipArchive[];
|
|
12
26
|
encoding: string;
|
|
13
|
-
encodingSource:
|
|
27
|
+
encodingSource: FormatSource;
|
|
14
28
|
delimiter: string | null;
|
|
15
|
-
delimiterSource:
|
|
29
|
+
delimiterSource: FormatSource | null;
|
|
16
30
|
delimiterReason: string | null;
|
|
17
31
|
lineEnding: string;
|
|
18
32
|
firstRecordColumns: number | null;
|
|
33
|
+
sampledRecords: number | null;
|
|
34
|
+
minRecordColumns: number | null;
|
|
35
|
+
maxRecordColumns: number | null;
|
|
36
|
+
explanation?: InspectionExplanation;
|
|
37
|
+
}
|
|
38
|
+
export declare class ZipProbeError extends Error {
|
|
39
|
+
readonly fileSizeBytes: number;
|
|
40
|
+
readonly archive: ZipTree;
|
|
41
|
+
constructor(cause: Error, fileSizeBytes: number, archive: ZipTree);
|
|
19
42
|
}
|
|
20
43
|
/** Inspect a bounded sample of the CSV payload; size always refers to the file on disk. */
|
|
21
44
|
export declare function inspectCsvFile(path: string, options?: InspectionOptions): Promise<FileInspection>;
|