Parsing options.
Async iterable iterator of records.
If you want array of records, use parseStringStream.toArray function.
Stream Execution Strategies:
For streams, the engine configuration supports two worker strategies:
By default, streams use main thread execution. To use workers with streams:
import { parseStringStream, EnginePresets } from 'web-csv-toolbox';
// Use worker with automatic stream-transfer (falls back if not supported)
for await (const record of parseStringStream(stream, {
engine: EnginePresets.workerStreamTransfer()
})) {
console.log(record);
}
Note: WASM execution is not supported for streams. If you specify
engine: { wasm: true } with a stream, it will fall back to main thread.
import { parseStringStream } from 'web-csv-toolbox';
const csv = `name,age
Alice,42
Bob,69`;
const stream = new ReadableStream({
start(controller) {
controller.enqueue(csv);
controller.close();
},
});
for await (const record of parseStringStream(stream)) {
console.log(record);
}
// Prints:
// { name: 'Alice', age: '42' }
// { name: 'Bob', age: '69' }
import { parseStringStream } from 'web-csv-toolbox';
const response = await fetch('large-file.csv');
const stream = response.body
.pipeThrough(new TextDecoderStream());
// Use worker with stream-transfer strategy
for await (const record of parseStringStream(stream, {
engine: { worker: true, workerStrategy: 'stream-transfer' }
})) {
console.log(record);
}
Parse CSV string stream to records.
Optionaloptions: ParseOptions<Header, ",", "\"">Parsing options.
Async iterable iterator of records.
If you want array of records, use parseStringStream.toArray function.
Stream Execution Strategies:
For streams, the engine configuration supports two worker strategies:
By default, streams use main thread execution. To use workers with streams:
import { parseStringStream, EnginePresets } from 'web-csv-toolbox';
// Use worker with automatic stream-transfer (falls back if not supported)
for await (const record of parseStringStream(stream, {
engine: EnginePresets.workerStreamTransfer()
})) {
console.log(record);
}
Note: WASM execution is not supported for streams. If you specify
engine: { wasm: true } with a stream, it will fall back to main thread.
import { parseStringStream } from 'web-csv-toolbox';
const csv = `name,age
Alice,42
Bob,69`;
const stream = new ReadableStream({
start(controller) {
controller.enqueue(csv);
controller.close();
},
});
for await (const record of parseStringStream(stream)) {
console.log(record);
}
// Prints:
// { name: 'Alice', age: '42' }
// { name: 'Bob', age: '69' }
import { parseStringStream } from 'web-csv-toolbox';
const response = await fetch('large-file.csv');
const stream = response.body
.pipeThrough(new TextDecoderStream());
// Use worker with stream-transfer strategy
for await (const record of parseStringStream(stream, {
engine: { worker: true, workerStrategy: 'stream-transfer' }
})) {
console.log(record);
}
Parse CSV string stream to records.
CSV string stream to parse
Optionaloptions: ParseOptions<Header, ",", "\"">Parsing options.
Async iterable iterator of records.
If you want array of records, use parseStringStream.toArray function.
Stream Execution Strategies:
For streams, the engine configuration supports two worker strategies:
By default, streams use main thread execution. To use workers with streams:
import { parseStringStream, EnginePresets } from 'web-csv-toolbox';
// Use worker with automatic stream-transfer (falls back if not supported)
for await (const record of parseStringStream(stream, {
engine: EnginePresets.workerStreamTransfer()
})) {
console.log(record);
}
Note: WASM execution is not supported for streams. If you specify
engine: { wasm: true } with a stream, it will fall back to main thread.
import { parseStringStream } from 'web-csv-toolbox';
const csv = `name,age
Alice,42
Bob,69`;
const stream = new ReadableStream({
start(controller) {
controller.enqueue(csv);
controller.close();
},
});
for await (const record of parseStringStream(stream)) {
console.log(record);
}
// Prints:
// { name: 'Alice', age: '42' }
// { name: 'Bob', age: '69' }
import { parseStringStream } from 'web-csv-toolbox';
const response = await fetch('large-file.csv');
const stream = response.body
.pipeThrough(new TextDecoderStream());
// Use worker with stream-transfer strategy
for await (const record of parseStringStream(stream, {
engine: { worker: true, workerStrategy: 'stream-transfer' }
})) {
console.log(record);
}
Parse CSV string stream to records.