npm

npm’s 2019 JavaScript ecosystem survey analysis is now available!Get your copy here »

stream-head

1.1.1 • Public • Published

npm version build status coverage status

stream-head

This package is a Promise-based alternative to buffer-peek-stream, or a "POSIX head(1) for Node.js streams". It depends only on through2.

This package provides TypeScript types.

API

The default (and only) exported function takes a readable stream and returns a new stream (together with a buffer). The old stream must not be used anymore, it will be piped to the returned stream. The returned stream will contain everything from the input stream, the first n bytes will be copied to the returned buffer, not consumed.

import streamHead from 'stream-head'
 
inputStream; // We get this from somewhere
 
// Peek the first 64 bytes from the stream.
const { stream, head } = await streamHead( inputStream, { bytes: 64 } );
 
stream; // The new stream (don't use inputStream anymore!)
head; // A Buffer with the first 64 bytes (or less if the stream was smaller)

install

npm i stream-head

Downloadsweekly downloads

5

version

1.1.1

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability