ndjson-stream
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

NDJSON Stream

This is a library to provide TransformStream for NDJSON.

Usage

import { NdjsonStream } from "ndjson-stream/index";

async function processStream<T>(stream: ReadableStreamDefaultReader<T>): Promise<void> {
    while (true) {
        const { done, value } = await stream.read();
        if (done) {
            return;
        }

        console.log(value);
    }
}

async function main(): Promise<void> {
    const ndjsonStream = new NdjsonStream();

    const input = '{"abc": 123}\r\n\r\n{"def": 456}\n';
    const stream = new Blob([input]).stream();
    const chained = stream.pipeThrough(ndjsonStream).getReader();
    await processStream(chained);
}

Dependencies (0)

    Dev Dependencies (4)

    Package Sidebar

    Install

    npm i ndjson-stream

    Weekly Downloads

    4

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    20.1 kB

    Total Files

    14

    Last publish

    Collaborators

    • masamitsu-murase