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

1.0.0 • Public • Published

node-aline

Align last bytes to newline boundary of stream chunks

Install

NPM

npm install aline

Yarn

yarn add aline

Sample Node.js Stream Transform

const {Aline} = require('aline');
const {Readable} = require('stream');

async function* generate() {
    yield 'foo\nba';
    yield 'ar\nbaz';
}

const stream = Readable.from(generate()).pipe(new Aline());

stream.on('data', function(chunk) {
    console.log(chunk.toString());
});

Sample Web TransformStream

const {AlineWeb} = require('aline');

async function main() {
    const response = await fetch('https://example.com/big.jsonl');

    if (!response.body) {
        return;
    }

    const readable = response.body
        .pipeThrough(new TransformStream(new AlineWeb()))
        .pipeThrough(new TextDecoderStream());

    for await (const batch of readable) {
        const jsonLines = batch.split(/\n/g).map(line => JSON.parse(line));
    }
}

Readme

Keywords

Package Sidebar

Install

npm i aline

Weekly Downloads

9

Version

1.0.0

License

MIT

Unpacked Size

19.6 kB

Total Files

12

Last publish

Collaborators

  • tugrul