npm

Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript.Learn more »

next-chunk

1.0.2 • Public • Published

npm version build status coverage status

next-chunk

This package provides an easy mechanism to read the first chunk in a readable stream. It returns a promise which will be resolved with the chunk (either a Buffer or a string), or null if the stream was ended. It rejects the promise if an error occured on the stream.

API

Importing

If importing using TypeScript or ES6 modules:

import nextChunk from 'next-chunk'

and if importing using CommonJS require:

const { nextChunk } = require( 'next-chunk' );
// or, if preferred
const nextChunk = require( 'next-chunk' ).default;

Usage

const readable = getSomeReadableStream( );
 
const firstChunk = await nextChunk( readable );
const secondChunk = await nextChunk( readable );
// ... eventually the stream may end, we get
const endedChunk = await nextChunk( readable );
const againChunk = await nextChunk( readable );
 
// These chunks contain buffers or strings
expect( firstChunk ).to.not.be.null;
expect( secondChunk ).to.not.be.null;
// These are all null
expect( endedChunk ).to.be.null;
expect( againChunk ).to.be.null;

install

npm i next-chunk

Downloadsweekly downloads

6

version

1.0.2

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability