1.0.0 • Published 1 year ago

aline v1.0.0

Weekly downloads
4
License
MIT
Repository
github
Last release
1 year ago

node-aline

Align last bytes to newline boundary of stream chunks

npm.io

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));
    }
}
1.0.0

1 year ago

0.0.9

1 year ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.2

8 years ago

0.0.1

8 years ago