# stream-chunker

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

Latest version **1.2.8** (published 2016-04-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install stream-chunker
pnpm add stream-chunker
yarn add stream-chunker
bun add stream-chunker
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.8 |
| Published | 2016-04-27 |
| First published | 2014-04-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Kristian Lyngbaek |
| Maintainers | klyngbaek |
| Keywords | stream, chunk, chunker, splitter, split, byte, buffer, binary, transform |

## Links

- npm: https://www.npmjs.com/package/stream-chunker
- Repository: git@github.com:klyngbaek/stream-chunker
- Homepage: https://github.com/klyngbaek/stream-chunker
- Issues: https://github.com/klyngbaek/stream-chunker/issues
- npm.io page: https://npm.io/package/stream-chunker

## Dependencies (1)

- [through2](https://npm.io/package/through2.md) ~2.0.0

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 1.2.8 (latest) — 2016-04-27
- 1.2.7 — 2016-04-27
- 1.1.8 — 2016-02-02
- 1.1.7 — 2015-12-15
- 1.1.6 — 2015-12-15
- 1.1.5 — 2015-06-21
- 1.1.4 — 2015-06-21
- 1.1.3 — 2015-06-21
- 1.1.2 — 2015-06-21
- 1.1.1 — 2015-06-21
- 1.1.0 — 2015-06-21
- 1.0.7 — 2015-06-21
- 1.0.5 — 2015-06-21
- 1.0.4 — 2015-06-20
- 1.0.3 — 2015-06-20
- … 9 more at https://npm.io/package/stream-chunker/versions

## README

# stream-chunker

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

[![NPM](https://nodei.co/npm/stream-chunker.png)](https://nodei.co/npm/stream-chunker/)

[![Build Status](https://travis-ci.org/klyngbaek/stream-chunker.svg?branch=master)](https://travis-ci.org/klyngbaek/stream-chunker)
[![Coverage Status](https://coveralls.io/repos/github/klyngbaek/stream-chunker/badge.svg?branch=master)](https://coveralls.io/github/klyngbaek/stream-chunker?branch=master)
[![Dependency Status](https://david-dm.org/klyngbaek/stream-chunker.svg)](https://david-dm.org/klyngbaek/stream-chunker)
[![devDependency Status](https://david-dm.org/klyngbaek/stream-chunker/dev-status.svg)](https://david-dm.org/klyngbaek/stream-chunker#info=devDependencies)

## 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
```javascript
var fs = require('fs');
var chunker = require('stream-chunker');

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

## Full Working Example
```javascript
// 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

---
_Source: https://npm.io/package/stream-chunker · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
