Appearance
jsonl
Namespaces
Variables
TransformFrom
ts
const TransformFrom: IJsonlTransformFrom;Defined in: src/node/jsonl/TransformFrom.ts:12
Node.js Transform stream that decodes a JSONL byte stream into parsed JS objects.
Example
ts
const stream = new TransformFrom();
stream.on('data', (obj) => console.log(obj));TransformTo
ts
const TransformTo: Transform & {
drain: () => Promise<void>;
};Defined in: src/node/jsonl/TransformTo.ts:11
Node.js Transform stream that serializes JS objects into a JSONL byte stream.
Type Declaration
| Name | Type | Defined in |
|---|---|---|
drain() | () => Promise<void> | src/jsonl/ProviderOfTransformTo.ts:31 |
Example
ts
const stream = new TransformTo();
stream.write({ a: 1 }); // emits '{"a":1}\n'Functions
read()
ts
function read(path, options?): ReadableStream;Defined in: src/node/jsonl/read.ts:13
Creates a readable stream of parsed JSONL records from a file.
Parameters
| Parameter | Type | Description |
|---|---|---|
path | string | Path to the JSONL file. |
options? | any | Optional fs.createReadStream options. |
Returns
ReadableStream
A readable stream emitting parsed JSON objects one per line.
Example
ts
read('./data.jsonl').on('data', (record) => console.log(record));readLimited()
ts
function readLimited(path, options?): ILimitStream;Defined in: src/node/jsonl/readLimited.ts:14
Like read, but limits the number of JSONL records emitted.
Parameters
| Parameter | Type | Description |
|---|---|---|
path | string | Path to the JSONL file. |
options? | any | Options including optional limit (number of records). |
Returns
A limited readable stream of parsed JSON objects.
Example
ts
readLimited('./data.jsonl', { limit: 100 }).on('data', (rec) => console.log(rec));readUnopened()
ts
function readUnopened(path, options?): ReadableStream;Defined in: src/node/jsonl/readUnopened.ts:14
Creates a JSONL readable stream that polls the file until it becomes available. Useful for reading files that are not yet opened/created.
Parameters
| Parameter | Type | Description |
|---|---|---|
path | string | Path to the JSONL file. |
options? | any | Optional read options. |
Returns
ReadableStream
A readable stream of parsed JSON objects.
Example
ts
readUnopened('./data.jsonl').on('data', (rec) => console.log(rec));readUnopenedLimited()
ts
function readUnopenedLimited(path, options?): ILimitStream;Defined in: src/node/jsonl/readUnopenedLimited.ts:14
Like readUnopened, but limits the number of JSONL records emitted.
Parameters
| Parameter | Type | Description |
|---|---|---|
path | string | Path to the JSONL file. |
options? | any | Options including optional limit (number of records). |
Returns
A limited readable stream of parsed JSON objects.
Example
ts
readUnopenedLimited('./data.jsonl', { limit: 10 }).on('data', (rec) => console.log(rec));write()
ts
function write(path, options?): WritableStream;Defined in: src/node/jsonl/write.ts:17
Creates a writable stream for writing JSONL data to a file.
Parameters
| Parameter | Type | Description |
|---|---|---|
path | string | The path to the file to write to. |
options? | CreateWriteStreamOptions | The options to pass to the writable stream. |
Returns
WritableStream
A writable stream for writing JSONL data to a file.
Example
ts
const out = write('./data.jsonl');
out.write({ a: 1 });
out.end();