Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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 - npm Package Compare versions

Comparing version 1.0.5 to 1.0.7

11

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

@@ -9,11 +9,12 @@ dataInteval: 100

// Create stream chunker with 4 byte chunks
// Create stream chunker with 16 byte chunks
var Chunker = require('../index.js');
var chunker = Chunker(4); // split the stream of data into 4 byte chunks
var chunker = Chunker(16, true); // 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 4 byte chunk of data
console.log('4 byte chunk: ' + data.toString('utf8'));
// do something with a chunk of data
// notice the last chunk is the flushed data
console.log('Chunk: ' + data.toString('utf8'));
});
sampleStream.pipe(chunker); // write some data to chunker to get chunked
{
"name": "stream-chunker",
"version": "1.0.5",
"version": "1.0.7",
"description": "A transform stream which chunks incoming data into chunkSize byte chunks",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -11,6 +11,7 @@ # stream-chunker

### `var chunker = require('stream-chunker')(chunkSize, [flush])`
#### `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.
in `chunkSize` byte chunks. This modules has no notion of `objectMode`, everything
written to this stream must be a `string` or a `buffer`.

@@ -20,3 +21,13 @@ - `chunkSize`: `integer` - Size in bytes of the desired chunks.

## An example
## Simple example
```
var fs = require('fs');
var chunker = require('stream-chunker');
fs.createReadStream('/someFile')
.pipe(chunks(16))
.pipe(somethingThatExpects16ByteChunks());
```
## Full working example example
```javascript

@@ -26,3 +37,3 @@ // Create sample input stream with 10 byte chunks

var sampleStream = new Lorem({
size: 1000,
size: 100,
dataSize: 10,

@@ -32,10 +43,11 @@ dataInteval: 100

// Create stream chunker with 4 byte chunks
// Create stream chunker with 16 byte chunks
var Chunker = require('stream-chunker');
var chunker = Chunker(4); // split the stream of data into 4 byte chunks
var chunker = Chunker(16, true); // 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 4 byte chunk of data
console.log('4 byte chunk: ' + data.toString('utf8'));
// do something with a chunk of data
// notice the last chunk is the flushed data
console.log('Chunk: ' + data.toString('utf8'));
});

@@ -42,0 +54,0 @@ sampleStream.pipe(chunker); // write some data to chunker to get chunked

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