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 🙏

© 2024 – Pkg Stats / Ryan Hefner

stream-chunker

v1.2.8

Published

A transform stream which chunks incoming data into chunkSize byte chunks

Downloads

9,449

Readme

stream-chunker

A transform stream which chunks incoming data into chunkSize byte chunks.

NPM

Build Status Coverage Status Dependency Status devDependency Status

API

var chunker = require('stream-chunker')(chunkSize, [opts])

Returns a new chunker. Chunker is a duplex (transform) stream. You can write data into the chunker, and regardless of the incoming data, the readable side will emit data in chunkSize byte chunks. This modules has no notion of objectMode, everything written to this stream must be a string or a buffer.

  • chunkSize: integer - Size in bytes of the desired chunks.
  • opts
    • flush: boolean - Optional. Flush incomplete chunk data on stream end. Default is false.
    • align: boolean - Optional. Pad incomplete chunk data on stream end. Should be used in combination with flush. Default is false.
    • encoding: string - Optional. Encoding of String chunks. Must be a valid Buffer encoding, such as utf8 or ascii.

Simple Example

var fs = require('fs');
var chunker = require('stream-chunker');

fs.createReadStream('/someFile')
  	.pipe(chunker(16))
  	.pipe(somethingThatExpects16ByteChunks());

Full Working Example

// Create sample input stream with 10 byte chunks
var Lorem = require('loremipstream');
var sampleStream = new Lorem({
	size: 100,
	dataSize: 10,
	dataInteval: 100
});

// Create stream chunker with 16 byte chunks
var Chunker = require('stream-chunker');
var opts = {
	flush: true,
	encoding: 'utf8'
};
var chunker = Chunker(16, opts);
// make sure to add any data event listeners to chunker stream
// before you write any data to it
chunker.on('data', function(data) {
    // do something with a chunk of data
    // notice the last chunk is the flushed data
    console.log('Chunk: ' + data);
});
sampleStream.pipe(chunker); // write some data to chunker to get chunked

License

MIT