@konstit/csv 0.4.3 → 0.5.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.
- package/README.md +50 -28
- package/THIRD_PARTY_NOTICES.md +7 -1
- package/dist/api.d.ts +39 -249
- package/dist/api.js +56 -394
- package/dist/batches.d.ts +8 -57
- package/dist/batches.js +77 -52
- package/dist/cli-command.d.ts +7 -0
- package/dist/cli-command.js +315 -0
- package/dist/cli-schema.d.ts +127 -0
- package/dist/cli-schema.js +234 -0
- package/dist/cli.js +2 -604
- package/dist/file-stream.d.ts +62 -3
- package/dist/file-stream.js +242 -36
- package/dist/files.d.ts +11 -11
- package/dist/files.js +38 -79
- package/dist/filter.d.ts +5 -8
- package/dist/format-bytes.d.ts +1 -0
- package/dist/format-bytes.js +11 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -14
- package/dist/inspect-file.d.ts +22 -0
- package/dist/inspect-file.js +138 -0
- package/dist/latin1-rows.d.ts +4 -3
- package/dist/latin1-rows.js +72 -24
- package/dist/materialize-field.d.ts +2 -0
- package/dist/materialize-field.js +20 -15
- package/dist/native.d.ts +50 -78
- package/dist/native.js +36 -112
- package/dist/normalize.d.ts +14 -40
- package/dist/normalize.js +66 -64
- package/dist/options-snapshot.js +3 -2
- package/dist/options.d.ts +4 -30
- package/dist/options.js +0 -6
- package/dist/parser.d.ts +23 -209
- package/dist/parser.js +146 -261
- package/dist/strict-schema.d.ts +6 -4
- package/dist/strict-schema.js +4 -3
- package/dist/types.d.ts +119 -221
- package/dist/zip-reader.d.ts +13 -1
- package/dist/zip-reader.js +36 -17
- package/package.json +36 -33
- 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 +9 -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/worker-count.d.ts +0 -34
- package/dist/worker-count.js +0 -101
- package/dist/worker-factory.d.ts +0 -3
- package/dist/worker-factory.js +0 -9
- package/dist/worker-filter.d.ts +0 -29
- package/dist/worker-filter.js +0 -46
- package/dist/worker-module.d.ts +0 -1
- package/dist/worker-module.js +0 -4
- package/dist/worker-pool.d.ts +0 -93
- package/dist/worker-pool.js +0 -298
- package/dist/worker-rows.d.ts +0 -36
- package/dist/worker-rows.js +0 -127
- package/dist/workers/count.worker.d.ts +0 -1
- package/dist/workers/count.worker.js +0 -36
- package/dist/workers/rows.worker.d.ts +0 -1
- package/dist/workers/rows.worker.js +0 -56
package/README.md
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
# @konstit/csv
|
|
2
2
|
|
|
3
|
-
A CSV
|
|
3
|
+
A high-performance streaming CSV parsing library for Bun using a native C++ parser with SIMD acceleration (AVX2/NEON), streaming file access, filtering, and column selection.
|
|
4
4
|
|
|
5
5
|
[Quick start](#quick-start) · [Choose an API](#choose-an-api) · [CLI](#cli) · [Documentation](#documentation)
|
|
6
6
|
|
|
7
7
|
- Stream large files in batches, or parse a buffer you already have in memory.
|
|
8
8
|
- Filter records and select columns before materializing results as JavaScript rows.
|
|
9
|
-
-
|
|
10
|
-
-
|
|
9
|
+
- Reads [RFC 4180](https://www.rfc-editor.org/info/rfc4180) CSV. Set `strict: true` to reject malformed quoting.
|
|
10
|
+
- Tested against [csv-spectrum](https://github.com/maxogden/csv-spectrum), selected [W3C CSVW](https://w3c.github.io/csvw/tests/) cases,
|
|
11
|
+
and fixtures derived from [csvkit](https://github.com/wireservice/csvkit).
|
|
12
|
+
- Stream compressed files:
|
|
13
|
+
- zip
|
|
14
|
+
- gzip
|
|
15
|
+
- brotli
|
|
16
|
+
- zstd
|
|
17
|
+
- deflate
|
|
18
|
+
- Auto detect delimiters, encoding and compression.
|
|
19
|
+
- UTF-8 and Latin-1 have specialized native fast paths.
|
|
20
|
+
- More encodings are supported out of the box, including Windows-1252, UTF-16LE, and Shift_JIS.
|
|
11
21
|
|
|
12
22
|
## Installation
|
|
13
23
|
|
|
@@ -49,7 +59,10 @@ bun parse.ts
|
|
|
49
59
|
```
|
|
50
60
|
|
|
51
61
|
Each row is an array of strings. Headers remain ordinary records, and numeric-looking fields remain strings.
|
|
52
|
-
|
|
62
|
+
File and buffer APIs default to a comma delimiter. Buffers default to UTF-8; file readers detect UTF-8, Latin-1,
|
|
63
|
+
Windows-1252 or BOM-marked UTF-16 from the first 64 KiB after decompression. Set `delimiter: 'auto'` on a file
|
|
64
|
+
to detect both from the same sample. To skip detection, pass the encoding and delimiter explicitly.
|
|
65
|
+
UTF-8 and Latin-1 use native paths; other supported `Bun.Encoding` labels are transcoded to UTF-8.
|
|
53
66
|
|
|
54
67
|
## Stream a file
|
|
55
68
|
|
|
@@ -71,8 +84,11 @@ for await (const batch of csv.rows('data.csv')) {
|
|
|
71
84
|
}
|
|
72
85
|
```
|
|
73
86
|
|
|
74
|
-
Each iteration yields a **batch of rows
|
|
75
|
-
they arrive to avoid collecting the complete file in memory. The header is returned as the first row.
|
|
87
|
+
Each iteration yields a **batch of rows** in file order, so use the inner loop to process individual records. Process
|
|
88
|
+
batches as they arrive to avoid collecting the complete file in memory. The header is returned as the first row.
|
|
89
|
+
|
|
90
|
+
Pass `{ skipRows: 1, limit: 10 }` to skip the header and emit up to ten rows. With a filter, `skipRows` counts
|
|
91
|
+
input records and `limit` counts matches across all batches.
|
|
76
92
|
|
|
77
93
|
To count records without materializing rows:
|
|
78
94
|
|
|
@@ -84,20 +100,19 @@ console.log(await csv.count('data.csv')); // 3, including the header
|
|
|
84
100
|
|
|
85
101
|
## Choose an API
|
|
86
102
|
|
|
87
|
-
| Task | API
|
|
88
|
-
| ---------------------------- |
|
|
89
|
-
| Parse an in-memory buffer | `await csv.parse(buffer)`
|
|
90
|
-
| Stream a file | `csv.rows(path)`
|
|
91
|
-
| Count records | `await csv.count(path)`
|
|
92
|
-
| Access native batches | `csv.
|
|
93
|
-
|
|
|
94
|
-
|
|
|
95
|
-
|
|
|
96
|
-
| Supply your own input chunks | `NativeCsvParser` | Manual parser and batch disposal |
|
|
103
|
+
| Task | API | Result or lifecycle |
|
|
104
|
+
| ---------------------------- | ----------------------------------------------------------- | --------------------------------------------------- |
|
|
105
|
+
| Parse an in-memory buffer | `await csv.parse(buffer)` | All rows as arrays of strings |
|
|
106
|
+
| Stream a file | `csv.rows(path)` | Async stream of row batches |
|
|
107
|
+
| Count records | `await csv.count(path)` | Record count, optionally filtered |
|
|
108
|
+
| Access native batches | `csv.batches(path, options)` | Use `using` to close each batch after its iteration |
|
|
109
|
+
| Visit rows or scan columns | `batch.forEachRow()` / `batch.scanColumns()` | Read projected fields by position within the batch |
|
|
110
|
+
| Supply your own input chunks | `NativeCsvParser` | Manual parser and batch disposal |
|
|
111
|
+
| Find record-safe boundaries | `csv.findCsvSafeSplitOffsets()` / `csv.findCsvSafeShards()` | Advanced byte-range processing |
|
|
97
112
|
|
|
98
113
|
Start with `csv.rows()` for streaming records. Use batches or views when you need byte access or lower allocation
|
|
99
|
-
overhead.
|
|
100
|
-
|
|
114
|
+
overhead. Advanced applications can use the record-safe boundary helpers to divide an uncompressed CSV file into
|
|
115
|
+
byte ranges for their own processing pipeline. See the [API guide](https://github.com/Konstit-Engenharia/csv-parser/blob/main/docs/api.md)
|
|
101
116
|
for options and resource lifetimes.
|
|
102
117
|
|
|
103
118
|
## Common operations
|
|
@@ -141,7 +156,6 @@ import { csv } from '@konstit/csv';
|
|
|
141
156
|
|
|
142
157
|
for await (
|
|
143
158
|
const batch of csv.rows('data.csv.gz', {
|
|
144
|
-
compression: 'auto',
|
|
145
159
|
delimiter: 'auto',
|
|
146
160
|
})
|
|
147
161
|
) {
|
|
@@ -151,10 +165,12 @@ for await (
|
|
|
151
165
|
}
|
|
152
166
|
```
|
|
153
167
|
|
|
154
|
-
|
|
155
|
-
|
|
168
|
+
File APIs and the CLI detect compression by default and read plain CSV, TSV, and text files directly.
|
|
169
|
+
For a plain file with an unrecognized name, use `compression: 'none'` or `--compression none`.
|
|
170
|
+
Decompression streams into the parser.
|
|
156
171
|
|
|
157
|
-
|
|
172
|
+
ZIP archives automatically select the only data file, ignoring directories and OS metadata.
|
|
173
|
+
For archives with multiple data files, select an entry with `compression: { format: 'zip', entry: 'data.csv' }`. See
|
|
158
174
|
[Compression](https://github.com/Konstit-Engenharia/csv-parser/blob/main/docs/api.md#compression-and-delimiter-detection)
|
|
159
175
|
for supported formats, detection rules, and limits.
|
|
160
176
|
|
|
@@ -176,31 +192,37 @@ console.log(rows.length); // 3
|
|
|
176
192
|
```
|
|
177
193
|
|
|
178
194
|
Strict mode validates quote syntax and can check header and row-count requirements. It supports column selection
|
|
179
|
-
with `csv.parse()` and `csv.rows()`, but cannot be combined with filters
|
|
195
|
+
with `csv.parse()` and `csv.rows()`, but cannot be combined with filters. See
|
|
180
196
|
[Strict validation](https://github.com/Konstit-Engenharia/csv-parser/blob/main/docs/api.md#strict-validation)
|
|
181
197
|
for supported combinations.
|
|
182
198
|
|
|
183
199
|
## CLI
|
|
184
200
|
|
|
185
|
-
|
|
201
|
+
Inspect a file, count its records, or emit the first records as newline-delimited JSON:
|
|
186
202
|
|
|
187
203
|
```sh
|
|
204
|
+
bunx @konstit/csv probe data.csv
|
|
205
|
+
bunx @konstit/csv probe tables.zip --zip-entry parts.tsv --json
|
|
206
|
+
|
|
188
207
|
bunx @konstit/csv count data.csv
|
|
189
208
|
# 3
|
|
190
209
|
|
|
191
|
-
bunx @konstit/csv lines data.csv --json --limit 2
|
|
192
|
-
# ["id","name","state"]
|
|
210
|
+
bunx @konstit/csv lines data.csv --json --skip-rows 1 --limit 2
|
|
193
211
|
# ["1","Ada","SP"]
|
|
212
|
+
# ["2","Grace","RJ"]
|
|
194
213
|
```
|
|
195
214
|
|
|
196
|
-
|
|
215
|
+
The CLI detects input encoding and delimiter by default. `probe --json` reports the file size in bytes,
|
|
216
|
+
how much of the decompressed payload it inspected, and whether it reached the end. Use `--delimiter` or
|
|
217
|
+
`--encoding` to inspect a known format. Without `--json`, `lines` writes normalized UTF-8 CSV.
|
|
218
|
+
`count` and `lines` support column filters; `lines` also supports
|
|
197
219
|
column selection. Use `bunx @konstit/csv lines --help` or read the
|
|
198
220
|
[CLI guide](https://github.com/Konstit-Engenharia/csv-parser/blob/main/docs/cli.md) for flags and output behavior.
|
|
199
221
|
|
|
200
222
|
## Documentation
|
|
201
223
|
|
|
202
224
|
- [API guide](https://github.com/Konstit-Engenharia/csv-parser/blob/main/docs/api.md): filters, encoding, compression,
|
|
203
|
-
validation, typed options, batches, views,
|
|
225
|
+
validation, typed options, batches, views, advanced byte boundaries, and manual parsing.
|
|
204
226
|
- [CLI guide](https://github.com/Konstit-Engenharia/csv-parser/blob/main/docs/cli.md): commands, filters, output formats,
|
|
205
227
|
and option constraints.
|
|
206
228
|
- [Benchmarks](https://github.com/Konstit-Engenharia/csv-parser/blob/main/docs/benchmarks.md): datasets, commands,
|
package/THIRD_PARTY_NOTICES.md
CHANGED
|
@@ -325,7 +325,7 @@ SOFTWARE.
|
|
|
325
325
|
- Source: https://github.com/zlib-ng/zlib-ng
|
|
326
326
|
- Version: 2.3.3
|
|
327
327
|
- License: zlib License
|
|
328
|
-
- Use in this project: compiled into the
|
|
328
|
+
- Use in this project: compiled into the Linux x64 and macOS x64 native libraries for ZIP DEFLATE and CRC32 processing. The macOS arm64 library uses the operating system's zlib.
|
|
329
329
|
|
|
330
330
|
Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler
|
|
331
331
|
|
|
@@ -350,6 +350,12 @@ it and redistribute it freely, subject to the following restrictions:
|
|
|
350
350
|
- Use in this repo: compatibility fixtures loaded by `test/csv-parser/spectrum.test.ts`.
|
|
351
351
|
- Notice: csv-spectrum is copyright its authors and contributors. Redistribution of source or binary forms must retain the BSD-2-Clause copyright notice, conditions, and disclaimer.
|
|
352
352
|
|
|
353
|
+
## TurboCSV
|
|
354
|
+
|
|
355
|
+
- Source: [TurboCSV library comparison](https://github.com/bytebrujo/bun-csv/blob/d1217818230788a8a4f48ebc023a71cd1a57feb4/test/benchmark-comparison.ts)
|
|
356
|
+
- License: [MIT](./LICENSE), TurboCSV Contributors.
|
|
357
|
+
- Use in this repo: synthetic fixture recipe and file parsing workloads adapted in `bench/comparison/libs-comparison.ts`.
|
|
358
|
+
|
|
353
359
|
## csvkit
|
|
354
360
|
|
|
355
361
|
- Source: https://github.com/wireservice/csvkit
|
package/dist/api.d.ts
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
import type { NativeCsvBatch } from './batches.js';
|
|
2
|
+
import type { CsvFileProbe } from './file-stream.js';
|
|
2
3
|
import { all, any, column, not, re } from './filter.js';
|
|
3
|
-
import type { CsvBatchesOptions,
|
|
4
|
-
import { parallelCount } from './worker-count.js';
|
|
5
|
-
import { CsvWorkerPool } from './worker-pool.js';
|
|
6
|
-
import { parallelRows } from './worker-rows.js';
|
|
4
|
+
import type { CsvBatchesOptions, CsvColumns, CsvCountOptions, CsvParseOptions, CsvProjectedRow, CsvRowsOptions, CsvShard, CsvShardingOptions } from './types.js';
|
|
7
5
|
/**
|
|
8
6
|
* Parse one in-memory CSV buffer into materialized rows.
|
|
9
7
|
*
|
|
10
8
|
* Use this when the input is already buffered and a single promise containing all rows is suitable.
|
|
11
9
|
* The buffer is parsed as one complete input, so a record may not be split across calls. Use
|
|
12
|
-
* {@link rows} for file streaming
|
|
10
|
+
* {@link rows} for file streaming. `columns` projects the
|
|
13
11
|
* returned rows, while strict validation (when enabled) still validates the complete row.
|
|
14
12
|
*
|
|
15
13
|
* @typeParam TColumns - Literal projected column indexes, when a projection is supplied.
|
|
16
14
|
* @param buffer - CSV bytes in a typed array or `DataView`.
|
|
17
|
-
* @param suppliedOptions - Parser options
|
|
18
|
-
* are not supported for in-memory parsing.
|
|
15
|
+
* @param suppliedOptions - Parser options for uncompressed bytes with a fixed delimiter.
|
|
19
16
|
* @returns A promise that resolves to the materialized rows in input order.
|
|
20
17
|
* @throws {Error} If the options request compression, automatic delimiter detection, or an
|
|
21
18
|
* unsupported filtered strict-validation combination.
|
|
@@ -26,221 +23,81 @@ export declare function parse<TColumns extends CsvColumns | undefined = undefine
|
|
|
26
23
|
*
|
|
27
24
|
* Each yielded value is one parser batch represented as ordinary string arrays. Options are
|
|
28
25
|
* captured when this function is called, before iteration starts, so mutating the caller-owned
|
|
29
|
-
* options object later does not change the stream.
|
|
30
|
-
*
|
|
31
|
-
* detection.
|
|
26
|
+
* options object later does not change the stream. With `reuseArrays: true`, batches and their
|
|
27
|
+
* rows are borrowed until the next iteration. Copy a row with `row.slice()` to retain it.
|
|
32
28
|
*
|
|
33
29
|
* @typeParam TColumns - Literal projected column indexes, when a projection is supplied.
|
|
34
30
|
* @param path - Path to the CSV file.
|
|
35
|
-
* @param options - File, projection, filter,
|
|
36
|
-
* @returns An async generator of row batches
|
|
37
|
-
* parsing yields batches as worker shards report them, so global file order is not guaranteed.
|
|
31
|
+
* @param options - File, projection, filter, and validation settings.
|
|
32
|
+
* @returns An async generator of row batches in file order.
|
|
38
33
|
* @throws {Error} During iteration when the file cannot be read or the selected options are
|
|
39
|
-
* incompatible, such as
|
|
34
|
+
* incompatible, such as a filter combined with strict validation.
|
|
40
35
|
*/
|
|
41
36
|
export declare function rows<TColumns extends CsvColumns | undefined = undefined>(path: string, options?: CsvRowsOptions<TColumns>): AsyncGenerator<CsvProjectedRow<TColumns>[], void>;
|
|
42
|
-
|
|
43
|
-
* Stream materialized rows through record-safe worker shards.
|
|
44
|
-
*
|
|
45
|
-
* `workerCount` must be greater than one. Workers require uncompressed input, an explicit
|
|
46
|
-
* delimiter, and non-strict validation; use {@link rows} for serial parsing or strict validation.
|
|
47
|
-
*
|
|
48
|
-
* @typeParam TColumns - Literal projected column indexes, when a projection is supplied.
|
|
49
|
-
* @param path - Path to the CSV file.
|
|
50
|
-
* @param options - Parallel row options, including the required worker count.
|
|
51
|
-
* @returns An async generator of materialized row batches.
|
|
52
|
-
* @throws {RangeError} If `workerCount` is not an integer greater than one.
|
|
53
|
-
* @throws {Error} If compression, automatic delimiter detection, or strict validation is enabled.
|
|
54
|
-
*/
|
|
55
|
-
export { parallelRows };
|
|
56
|
-
export { CsvWorkerPool };
|
|
37
|
+
export declare function iterateRows<TColumns extends CsvColumns | undefined>(path: string, options: CsvRowsOptions<TColumns>, probeFormat?: CsvFileProbe): AsyncGenerator<CsvProjectedRow<TColumns>[], void>;
|
|
57
38
|
/**
|
|
58
39
|
* Stream native batches with explicit lifetime control.
|
|
59
40
|
*
|
|
60
41
|
* Use this when you want low-allocation access to row views, byte ranges, and native-backed
|
|
61
42
|
* column data. Every yielded batch owns native memory and must be closed after use; prefer
|
|
62
|
-
* `for await (using batch of csv.batches(...))`
|
|
63
|
-
* Options are captured at invocation time.
|
|
64
|
-
*
|
|
43
|
+
* `for await (using batch of csv.batches(...))` to close each batch at the end of the iteration.
|
|
44
|
+
* Options are captured at invocation time. Projection selects the stored fields in the requested
|
|
45
|
+
* order. Accessors use output positions and filters use physical input indexes.
|
|
65
46
|
*
|
|
66
47
|
* @param path - Path to the CSV file.
|
|
67
|
-
* @param options -
|
|
48
|
+
* @param options - File and parser options.
|
|
68
49
|
* @returns An async generator of disposable native batches.
|
|
69
|
-
* @throws {Error} During iteration when the file or validation fails, or when
|
|
70
|
-
*
|
|
50
|
+
* @throws {Error} During iteration when the file or validation fails, or when strict validation
|
|
51
|
+
* is combined with projection or filtering.
|
|
71
52
|
*/
|
|
72
53
|
export declare function batches(path: string, options?: CsvBatchesOptions): AsyncGenerator<NativeCsvBatch, void>;
|
|
73
|
-
/**
|
|
74
|
-
* Process native CSV batches while managing each batch's lifetime.
|
|
75
|
-
*
|
|
76
|
-
* The callback may be asynchronous. Its batch remains valid until the callback settles and is
|
|
77
|
-
* closed in a `finally` block afterward, including when the callback throws.
|
|
78
|
-
*
|
|
79
|
-
* @param path - Path to the CSV file.
|
|
80
|
-
* @param options - Serial file and parser options.
|
|
81
|
-
* @param callback - Function invoked once per non-empty batch.
|
|
82
|
-
* @returns A promise that resolves after all batches have been processed.
|
|
83
|
-
* @throws {Error} The callback error, file error, or parser/validation error.
|
|
84
|
-
*/
|
|
85
|
-
export declare function withBatches(path: string, options: CsvBatchesOptions, callback: (batch: NativeCsvBatch) => void | Promise<void>): Promise<void>;
|
|
86
|
-
/**
|
|
87
|
-
* Visit reusable columnar batch views without materializing one JavaScript string per field.
|
|
88
|
-
*
|
|
89
|
-
* The callback must be synchronous. A single view object is rebound for each batch and becomes
|
|
90
|
-
* invalid as soon as the callback returns, so copy any data that must outlive the callback. When
|
|
91
|
-
* `columns` is defined, batch column indexes are relative to the projected output order. Worker
|
|
92
|
-
* parsing and strict validation with selected columns are not supported by this API.
|
|
93
|
-
*
|
|
94
|
-
* @typeParam TColumns - Literal projected column indexes, when a projection is supplied.
|
|
95
|
-
* @param path - Path to the CSV file.
|
|
96
|
-
* @param options - Serial file and columnar projection options.
|
|
97
|
-
* @param callback - Synchronous function invoked with a reusable view and batch index.
|
|
98
|
-
* @returns A promise that resolves after all batches have been visited.
|
|
99
|
-
* @throws {TypeError} If the callback returns a promise.
|
|
100
|
-
* @throws {Error} If worker parsing or an unsupported strict selected projection is requested.
|
|
101
|
-
*/
|
|
102
|
-
export declare function forEachColumnarBatches<TColumns extends CsvColumns | undefined = undefined>(path: string, options: CsvColumnarBatchOptions<TColumns>, callback: CsvColumnarBatchCallback<TColumns>): Promise<void>;
|
|
103
|
-
/**
|
|
104
|
-
* Visit columnar batches when the selected-column tuple is not statically known.
|
|
105
|
-
* The callback must be synchronous and the reusable view is valid only during the callback.
|
|
106
|
-
*
|
|
107
|
-
* @param path - Path to the CSV file.
|
|
108
|
-
* @param options - Serial columnar options, or `undefined` for defaults.
|
|
109
|
-
* @param callback - Synchronous batch handler.
|
|
110
|
-
* @returns A promise that resolves after all batches are visited.
|
|
111
|
-
*/
|
|
112
|
-
export declare function forEachColumnarBatches(path: string, options: CsvColumnarBatchOptions | undefined, callback: CsvColumnarBatchCallback): Promise<void>;
|
|
113
|
-
/**
|
|
114
|
-
* Visit reusable columnar batch views with the same lifetime guarantees as
|
|
115
|
-
* {@link forEachColumnarBatches}. The callback is synchronous and the view is invalid after it
|
|
116
|
-
* returns.
|
|
117
|
-
*
|
|
118
|
-
* @typeParam TColumns - Literal projected column indexes, when a projection is supplied.
|
|
119
|
-
* @param path - Path to the CSV file.
|
|
120
|
-
* @param options - Serial file and columnar projection options.
|
|
121
|
-
* @param callback - Synchronous function invoked for each batch.
|
|
122
|
-
* @returns A promise that resolves after all batches have been visited.
|
|
123
|
-
*/
|
|
124
|
-
export declare function withColumnarBatches<TColumns extends CsvColumns | undefined = undefined>(path: string, options: CsvColumnarBatchOptions<TColumns>, callback: CsvColumnarBatchCallback<TColumns>): Promise<void>;
|
|
125
|
-
/**
|
|
126
|
-
* Visit reusable row views without materializing row arrays.
|
|
127
|
-
*
|
|
128
|
-
* The callback must be synchronous. A single view object is rebound for each row and becomes
|
|
129
|
-
* invalid when the callback returns, so copy strings or bytes that must be retained. The
|
|
130
|
-
* `selectedColumns` property records the requested source columns. Without `where`, accessors
|
|
131
|
-
* use physical CSV indexes. With both `where` and a projection, only projected fields may be
|
|
132
|
-
* stored, so accessor indexes are projected positions; use the metadata to map them back to
|
|
133
|
-
* source indexes. Worker parsing is not supported.
|
|
134
|
-
*
|
|
135
|
-
* @typeParam TColumns - Literal projected column indexes recorded in `selectedColumns`.
|
|
136
|
-
* @param path - Path to the CSV file.
|
|
137
|
-
* @param options - Serial file, projection, filter, and validation options.
|
|
138
|
-
* @param callback - Synchronous function invoked once per row.
|
|
139
|
-
* @returns A promise that resolves after all rows have been visited.
|
|
140
|
-
* @throws {TypeError} If the callback returns a promise.
|
|
141
|
-
* @throws {Error} If worker parsing is requested or the file/parser fails.
|
|
142
|
-
*/
|
|
143
|
-
export declare function forEachRowViews<TColumns extends CsvColumns | undefined = undefined>(path: string, options: CsvRowViewsOptions<TColumns>, callback: CsvRowViewCallback<TColumns>): Promise<void>;
|
|
144
|
-
/**
|
|
145
|
-
* Visit row views when the selected-column tuple is not statically known.
|
|
146
|
-
* The callback must be synchronous and the reusable view is valid only during the callback.
|
|
147
|
-
*
|
|
148
|
-
* @param path - Path to the CSV file.
|
|
149
|
-
* @param options - Serial row-view options, or `undefined` for defaults.
|
|
150
|
-
* @param callback - Synchronous row handler.
|
|
151
|
-
* @returns A promise that resolves after all rows are visited.
|
|
152
|
-
*/
|
|
153
|
-
export declare function forEachRowViews(path: string, options: CsvRowViewsOptions | undefined, callback: CsvRowViewCallback): Promise<void>;
|
|
154
|
-
/**
|
|
155
|
-
* Visit reusable row views with the same lifetime guarantees as {@link forEachRowViews}.
|
|
156
|
-
*
|
|
157
|
-
* The callback is synchronous and the view is invalid after it returns.
|
|
158
|
-
*
|
|
159
|
-
* @typeParam TColumns - Literal projected column indexes recorded in `selectedColumns`.
|
|
160
|
-
* @param path - Path to the CSV file.
|
|
161
|
-
* @param options - Serial file, projection, filter, and validation options.
|
|
162
|
-
* @param callback - Synchronous function invoked once per row.
|
|
163
|
-
* @returns A promise that resolves after all rows have been visited.
|
|
164
|
-
*/
|
|
165
|
-
export declare function withRowViews<TColumns extends CsvColumns | undefined = undefined>(path: string, options: CsvRowViewsOptions<TColumns>, callback: CsvRowViewCallback<TColumns>): Promise<void>;
|
|
166
54
|
/**
|
|
167
55
|
* Count CSV records without materializing them.
|
|
168
56
|
*
|
|
169
57
|
* Filters created with `csv.column()` and composed with `csv.all()`, `csv.any()`, or `csv.not()`
|
|
170
|
-
* are evaluated by native fast paths.
|
|
171
|
-
*
|
|
172
|
-
* supports compression and automatic delimiter detection.
|
|
58
|
+
* are evaluated by native fast paths. The input may be compressed or use automatic delimiter
|
|
59
|
+
* detection.
|
|
173
60
|
*
|
|
174
61
|
* @param path - Path to the CSV file.
|
|
175
|
-
* @param suppliedOptions -
|
|
62
|
+
* @param suppliedOptions - File, filter, and validation settings.
|
|
176
63
|
* @returns A promise containing the record count.
|
|
177
|
-
* @throws {Error} If strict validation is combined with a filter
|
|
178
|
-
* file/parser errors are encountered.
|
|
64
|
+
* @throws {Error} If strict validation is combined with a filter or reading or parsing fails.
|
|
179
65
|
*/
|
|
180
66
|
export declare function count(path: string, suppliedOptions?: CsvCountOptions): Promise<number>;
|
|
181
|
-
/**
|
|
182
|
-
* Count records through record-safe worker shards.
|
|
183
|
-
*
|
|
184
|
-
* `workerCount` must be greater than one. Workers require uncompressed input, an explicit
|
|
185
|
-
* delimiter, and non-strict validation; use {@link count} for serial counting or strict checks.
|
|
186
|
-
*
|
|
187
|
-
* @param path - Path to the CSV file.
|
|
188
|
-
* @param options - Parallel count options, including the required worker count.
|
|
189
|
-
* @returns A promise containing the total record count.
|
|
190
|
-
* @throws {RangeError} If `workerCount` is not an integer greater than one.
|
|
191
|
-
* @throws {Error} If compression, automatic delimiter detection, or strict validation is enabled.
|
|
192
|
-
*/
|
|
193
|
-
export { parallelCount };
|
|
194
67
|
/**
|
|
195
68
|
* Find byte offsets that divide a CSV file only at record boundaries.
|
|
196
69
|
*
|
|
197
70
|
* The returned array contains shard start offsets followed by the terminal file boundary. Quoted
|
|
198
|
-
* fields and embedded newlines are respected. The operation
|
|
199
|
-
*
|
|
71
|
+
* fields and embedded newlines are respected. The operation scans original UTF-8 or Latin-1
|
|
72
|
+
* bytes in an uncompressed file with a fixed delimiter.
|
|
200
73
|
*
|
|
201
74
|
* @param path - Path to the uncompressed CSV file.
|
|
202
75
|
* @param shardCount - Desired number of partitions; the result may contain fewer non-empty shards.
|
|
203
76
|
* @param suppliedOptions - Explicit delimiter and file parser options. Compression is unavailable.
|
|
204
77
|
* @returns Monotonically increasing byte offsets, including `0` and the file-length boundary.
|
|
205
78
|
* @throws {RangeError} If `shardCount` is not a positive integer.
|
|
206
|
-
* @throws {Error} If the
|
|
79
|
+
* @throws {Error} If the input is compressed, the encoding requires transcoding, or the delimiter is automatic or invalid.
|
|
207
80
|
*/
|
|
208
|
-
|
|
81
|
+
declare function findCsvSafeSplitOffsets(path: string, shardCount: number, suppliedOptions?: CsvShardingOptions): number[];
|
|
209
82
|
/**
|
|
210
83
|
* Find non-empty CSV byte ranges that begin and end at record boundaries.
|
|
211
84
|
*
|
|
212
85
|
* Shards use inclusive `start` and `end` offsets and never split quoted fields or embedded
|
|
213
|
-
* newlines. A small file can produce fewer non-empty shards than requested. The operation
|
|
214
|
-
*
|
|
86
|
+
* newlines. A small file can produce fewer non-empty shards than requested. The operation
|
|
87
|
+
* requires original UTF-8 or Latin-1 bytes in an uncompressed file with a fixed delimiter.
|
|
215
88
|
*
|
|
216
89
|
* @param path - Path to the uncompressed CSV file.
|
|
217
90
|
* @param shardCount - Desired number of partitions; the result may contain fewer shards.
|
|
218
91
|
* @param suppliedOptions - Explicit delimiter and file parser options. Compression is unavailable.
|
|
219
|
-
* @returns Non-empty, ordered byte ranges
|
|
92
|
+
* @returns Non-empty, ordered byte ranges with inclusive endpoints.
|
|
220
93
|
* @throws {RangeError} If `shardCount` is not a positive integer.
|
|
221
|
-
* @throws {Error} If the
|
|
94
|
+
* @throws {Error} If the input is compressed, the encoding requires transcoding, or the delimiter is automatic or invalid.
|
|
222
95
|
*/
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* Create a reusable pool for repeated parallel row and count operations.
|
|
226
|
-
*
|
|
227
|
-
* The pool captures its file options when created. `workerCount` must be greater than one, and
|
|
228
|
-
* pooled operations require uncompressed input, an explicit delimiter, and non-strict validation.
|
|
229
|
-
* Call `close()` (or use `using`) when the pool is no longer needed.
|
|
230
|
-
*
|
|
231
|
-
* @typeParam TColumns - Literal projected column indexes for pooled row operations.
|
|
232
|
-
* @param path - Path to the uncompressed CSV file.
|
|
233
|
-
* @param options - Parallel worker-pool options, including `workerCount`.
|
|
234
|
-
* @returns A reusable worker pool. Its `rows()` and `count()` methods are asynchronous.
|
|
235
|
-
* @throws {RangeError} If `workerCount` is not an integer greater than one.
|
|
236
|
-
* @throws {Error} If compression or automatic delimiter detection is enabled. Strict validation
|
|
237
|
-
* is rejected when `count()` or `rows()` is called on the returned pool.
|
|
238
|
-
*/
|
|
239
|
-
export declare function workerPool<TColumns extends CsvColumns | undefined = undefined>(path: string, options: CsvWorkerPoolOptions<TColumns>): CsvWorkerPool<TColumns>;
|
|
96
|
+
declare function findCsvSafeShards(path: string, shardCount: number, suppliedOptions?: CsvShardingOptions): CsvShard[];
|
|
240
97
|
/**
|
|
241
98
|
* The package's file-oriented API namespace.
|
|
242
99
|
*
|
|
243
|
-
* The namespace combines materialization, counting, filtering,
|
|
100
|
+
* The namespace combines materialization, counting, filtering, native batches, and
|
|
244
101
|
* record-safe sharding helpers in one discoverable object.
|
|
245
102
|
*/
|
|
246
103
|
export declare const csv: {
|
|
@@ -276,18 +133,9 @@ export declare const csv: {
|
|
|
276
133
|
* @returns An immutable `CsvRegex` descriptor for low-level filter values.
|
|
277
134
|
*/
|
|
278
135
|
re: typeof re;
|
|
279
|
-
/**
|
|
280
|
-
* Create a reusable pool for parallel row and count operations.
|
|
281
|
-
* The pool captures its options at construction; close it when finished, and note that strict
|
|
282
|
-
* validation is rejected when `rows()` or `count()` starts.
|
|
283
|
-
* @param path - Path to an uncompressed CSV file.
|
|
284
|
-
* @param options - Parallel options with `workerCount` greater than one.
|
|
285
|
-
* @returns A reusable `CsvWorkerPool`.
|
|
286
|
-
*/
|
|
287
|
-
workerPool: typeof workerPool;
|
|
288
136
|
/**
|
|
289
137
|
* Parse one in-memory buffer into materialized rows.
|
|
290
|
-
*
|
|
138
|
+
* Supply uncompressed bytes with a fixed delimiter.
|
|
291
139
|
* @param buffer - CSV bytes in a typed array or `DataView`.
|
|
292
140
|
* @param suppliedOptions - In-memory parser and projection options.
|
|
293
141
|
* @returns A promise containing materialized rows in input order.
|
|
@@ -301,10 +149,9 @@ export declare const csv: {
|
|
|
301
149
|
parse: typeof parse;
|
|
302
150
|
/**
|
|
303
151
|
* Stream materialized row batches from a CSV file.
|
|
304
|
-
* Options are captured at invocation.
|
|
305
|
-
* as each shard reports them, without a global file-order guarantee.
|
|
152
|
+
* Options are captured at invocation. Batches are yielded in file order.
|
|
306
153
|
* @param path - Path to the CSV file.
|
|
307
|
-
* @param options - File, projection, filter,
|
|
154
|
+
* @param options - File, projection, filter, and validation settings.
|
|
308
155
|
* @returns An async generator of row batches.
|
|
309
156
|
* @example
|
|
310
157
|
* ```ts
|
|
@@ -315,78 +162,20 @@ export declare const csv: {
|
|
|
315
162
|
* ```
|
|
316
163
|
*/
|
|
317
164
|
rows: typeof rows;
|
|
318
|
-
/**
|
|
319
|
-
* Count records through record-safe worker shards.
|
|
320
|
-
* Workers require an explicit delimiter, uncompressed input, and non-strict validation.
|
|
321
|
-
* @param path - Path to the CSV file.
|
|
322
|
-
* @param options - Parallel count options with `workerCount` greater than one.
|
|
323
|
-
* @returns A promise containing the total record count.
|
|
324
|
-
*/
|
|
325
|
-
parallelCount: typeof parallelCount;
|
|
326
|
-
/**
|
|
327
|
-
* Stream materialized rows through record-safe worker shards.
|
|
328
|
-
* Worker batches are yielded as shards report them and are not globally ordered.
|
|
329
|
-
* @param path - Path to the CSV file.
|
|
330
|
-
* @param options - Parallel row options with `workerCount` greater than one.
|
|
331
|
-
* @returns An async generator of projected row batches.
|
|
332
|
-
*/
|
|
333
|
-
parallelRows: typeof parallelRows;
|
|
334
165
|
/**
|
|
335
166
|
* Stream disposable native-backed batches.
|
|
336
|
-
*
|
|
167
|
+
* Columns select stored fields in output order. Filters address the input record.
|
|
168
|
+
* Close each yielded batch, or use `for await (using batch of ...)`.
|
|
337
169
|
* @param path - Path to the CSV file.
|
|
338
|
-
* @param options -
|
|
170
|
+
* @param options - File and parser options.
|
|
339
171
|
* @returns An async generator of `NativeCsvBatch` objects.
|
|
340
172
|
*/
|
|
341
173
|
batches: typeof batches;
|
|
342
|
-
/**
|
|
343
|
-
* Process native batches and close each one after the callback settles.
|
|
344
|
-
* @param path - Path to the CSV file.
|
|
345
|
-
* @param options - Serial file and parser options.
|
|
346
|
-
* @param callback - Synchronous or asynchronous batch handler.
|
|
347
|
-
* @returns A promise that resolves after all batches are processed.
|
|
348
|
-
*/
|
|
349
|
-
withBatches: typeof withBatches;
|
|
350
|
-
/**
|
|
351
|
-
* Visit reusable columnar batch views with a synchronous callback.
|
|
352
|
-
* The view is invalid after the callback returns; selected indexes are relative to projection.
|
|
353
|
-
* @param path - Path to the CSV file.
|
|
354
|
-
* @param options - Serial columnar options; workers are unsupported.
|
|
355
|
-
* @param callback - Synchronous batch handler.
|
|
356
|
-
* @returns A promise that resolves after all batches are visited.
|
|
357
|
-
*/
|
|
358
|
-
forEachColumnarBatches: typeof forEachColumnarBatches;
|
|
359
|
-
/**
|
|
360
|
-
* Visit reusable columnar batch views, closing native storage after each callback.
|
|
361
|
-
* The callback is synchronous and the view cannot be retained.
|
|
362
|
-
* @param path - Path to the CSV file.
|
|
363
|
-
* @param options - Serial columnar options.
|
|
364
|
-
* @param callback - Synchronous batch handler.
|
|
365
|
-
* @returns A promise that resolves after all batches are visited.
|
|
366
|
-
*/
|
|
367
|
-
withColumnarBatches: typeof withColumnarBatches;
|
|
368
|
-
/**
|
|
369
|
-
* Visit reusable row views with a synchronous callback.
|
|
370
|
-
* The view is invalid after the callback returns; workers are unsupported.
|
|
371
|
-
* @param path - Path to the CSV file.
|
|
372
|
-
* @param options - Serial row-view options.
|
|
373
|
-
* @param callback - Synchronous row handler.
|
|
374
|
-
* @returns A promise that resolves after all rows are visited.
|
|
375
|
-
*/
|
|
376
|
-
forEachRowViews: typeof forEachRowViews;
|
|
377
|
-
/**
|
|
378
|
-
* Visit reusable row views with the same lifetime rules as `forEachRowViews`.
|
|
379
|
-
* @param path - Path to the CSV file.
|
|
380
|
-
* @param options - Serial row-view options.
|
|
381
|
-
* @param callback - Synchronous row handler.
|
|
382
|
-
* @returns A promise that resolves after all rows are visited.
|
|
383
|
-
*/
|
|
384
|
-
withRowViews: typeof withRowViews;
|
|
385
174
|
/**
|
|
386
175
|
* Count CSV records without materializing them.
|
|
387
|
-
*
|
|
176
|
+
* Counting supports compression and automatic encoding and delimiter detection. Filters require non-strict parsing.
|
|
388
177
|
* @param path - Path to the CSV file.
|
|
389
|
-
* @param suppliedOptions -
|
|
178
|
+
* @param suppliedOptions - File, filter, and validation settings.
|
|
390
179
|
* @returns A promise containing the record count.
|
|
391
180
|
* @example
|
|
392
181
|
* ```ts
|
|
@@ -414,3 +203,4 @@ export declare const csv: {
|
|
|
414
203
|
*/
|
|
415
204
|
findCsvSafeShards: typeof findCsvSafeShards;
|
|
416
205
|
};
|
|
206
|
+
export {};
|