npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

stream-chop

v1.0.0

Published

Chop a single stream of data into a series of readable streams with rewind

Downloads

7

Readme

NPM version Build Status Dependency Status Dev dependency Status Greenkeeper badge Coverage Status

Chop a single stream of data into a series of readable streams with rewind

What's it for

The use case is:

  • You are transfering data from a stream to a service/process which needs it in chunks
  • Each chunk can be streamed
  • If a chunk fails to transfer, you need to be able to "rewind" to send it again

An example is upload to Google Drive with the "resumable" method for large files (the use case that this package was created for).

Usage

Installation

npm install stream-chop

Usage

const ChopStream = require('stream-chop');

const inputStream = fs.createReadStream('file.mov');
const chopStream = new ChopStream();

inputStream.pipe(chopStream);

// Stream 1st 1024 bytes of data to file
const subStream1 = chopStream.chunk(0, 1024);
const outStream1 = fs.createWriteStream('part1.mov');
subStream1.pipe(outStream1);

outStream1.on('finish', () => {
  console.log('Done!');
});

Methods

`.chunk( start, length )

Get a stream for specified chunk of the input stream.

// Get stream for 1st 256 KiB of input stream
const subStream1 = chopStream.chunk(0, 256 * 1024);

The chunk is buffered internally, so .chunk() can be called again with same start if transferring the chunk fails and it needs to be sent again.

When .chunk() is called again, any data buffered before the start point is discarded. i.e. You cannot stream 2 chunks concurrently. It must be one at a time.

Calling .chunk() will cause any existing unfinished chunk stream to emit an error event and stop streaming.

.clearBuffer( [end] )

Clear data from internal buffer before byte end.

If end is undefined, then entire buffer will be cleared.

// Discard any data in buffer
chopStream.clearBuffer();

// Discard first 128 KiB of stream data if it's buffered
chopStream.clearBuffer(1024 * 128);

.chunk(1000) automatically calls .clearBuffer(1000) internally.

Once data has been discarded from the buffer, the stream can no longer be "rewound" to stream that data out again.

Properties

.bufferStart

Returns byte position of start of buffer.

.bufferEnd

Returns byte position of end of buffer.

.bufferLength

Returns number of bytes in buffer.

Tests

Use npm test to run the tests. Use npm run cover to check coverage.

Changelog

See changelog.md

Issues

If you discover a bug, please raise an issue on Github. https://github.com/overlookmotel/stream-chop/issues

Contribution

Pull requests are very welcome. Please:

  • ensure all tests pass before submitting PR
  • add tests for new features
  • document new functionality/API additions in README
  • do not add an entry to Changelog (Changelog is created when cutting releases)