Skip to content

fundamentool


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

NameTypeDefined 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

ParameterTypeDescription
pathstringPath to the JSONL file.
options?anyOptional 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

ParameterTypeDescription
pathstringPath to the JSONL file.
options?anyOptions including optional limit (number of records).

Returns

ILimitStream

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

ParameterTypeDescription
pathstringPath to the JSONL file.
options?anyOptional 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

ParameterTypeDescription
pathstringPath to the JSONL file.
options?anyOptions including optional limit (number of records).

Returns

ILimitStream

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

ParameterTypeDescription
pathstringThe path to the file to write to.
options?CreateWriteStreamOptionsThe 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();

MIT License