1.0.0 • Published 1 year ago

nanochunk v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Chunked-Encoding Stream Parser

import { readChunkedStream } from 'nanochunk';

const stream = Readable.from(async* stream() => {
    yield Buffer.from('1');
    yield Buffer.from('1\nH');
    yield Buffer.from('ello worl');
    yield Buffer.from('d7');
    yield Buffer.from('\nkthxby');
    yield Buffer.from('e');
});

const payloads: string[] = [];
for await (const payload of readChunkedStream(stream)) {
    payloads.push(payload);
}

assert.deepStrictEqual(payloads, [
    'Hello world',
    'kthxbye'
]);

Highlights

  • 🔥 Zero dependencies
  • 🗜 Tidy and compact
  • 💻 Works in browser
  • 🔬 Strongly typed