Socket
Socket
Sign inDemoInstall

stream-chunker

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stream-chunker

A transform stream which chunks incoming data into chunkSize byte chunks


Version published
Weekly downloads
1.8K
increased by6.51%
Maintainers
1
Weekly downloads
 
Created
Source

stream-chunker

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

build status

NPM

api

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

Returns a new chunker. Chunker is a duplex (tansform) stream. You can write data into the chunker, and regardless of the incoming data, the readable side will emit data in chunkSize byte chunks.

  • chunkSize: integer - Size in bytes of the desired chunks
  • flush: boolean - Optional. Flush inclomplete chunk data on stream end. Default is false.

An example

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

// Create stream chunker with 4 byte chunks
var CHUNK_SIZE = 4;
Chunker = require('stream-chunker');
var chunker = Chunker(CHUNK_SIZE) // split the stream of data into 4 byte chunks
// 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 16 byte chunk of data
    console.log('Handle '+CHUNK_SIZE+'bytes at a time: ' + data.toString('utf8'));
});
sampleStream.pipe(chunker); // write some data to chunker to get chunked

License

MIT

Keywords

FAQs

Package last updated on 20 Jun 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc