# through2-batch

> A stream that transforms chunks to batches form the stream

Latest version **1.1.1** (published 2018-11-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install through2-batch
pnpm add through2-batch
yarn add through2-batch
bun add through2-batch
```

## 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.1.1 |
| Published | 2018-11-04 |
| First published | 2015-10-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 5.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Nima Gardideh |
| Maintainers | nimsical |
| Keywords | through2, streams, streams2, through, transform, batch, chunk, batches |

## Links

- npm: https://www.npmjs.com/package/through2-batch
- Repository: https://github.com/nemo/through2-batch
- Homepage: https://github.com/nemo/through2-batch#readme
- Issues: https://github.com/nemo/through2-batch/issues
- npm.io page: https://npm.io/package/through2-batch

## Dependencies (1)

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

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 1.1.1 (latest) — 2018-11-04
- 1.1.0 — 2017-10-16
- 1.0.1 — 2015-10-23
- 1.0.0 — 2015-10-23

## README

[![Build Status](https://circleci.com/gh/nemo/through2-batch.svg?style=svg)](https://circleci.com/gh/nemo/through2-batch)

through2-batch
===================

A stream that transforms chunks to batches form the stream.
[![NPM](https://nodei.co/npm/through2-batch.png?downloads&downloadRank)](https://nodei.co/npm/through2-batch/)

A way to use a Node.JS Transform stream that batches chunks into an array (default is 10).
Objects/chunks will still come in the same order, just in batched arrays.

Built using [through2](https://github.com/rvagg/through2) and has the
same API with the addition of a `batchSize` option.

Non-`objectMode` streams are supported for completeness.

Written by Nima Gardideh ([halfmoon.ws](http://halfmoon.ws)) and used in production by [Taplytics](http://taplytics.com).



Install
-------

```bash
npm install --save through2-batch
```

Examples
--------

Process rows from a CSV in batches.

```javascript
var through2Batch = require('through2-batch');

fs.createReadStream('data.csv')
  .pipe(csv2())
  .pipe(through2Batch.obj(
    {batchSize: 100},
    function (batch, enc, callback) {
      var self = this;
      console.log(batch.length); // 100
      someThingAsync(batch, function (newChunk) {
        self.push(newChunk);
      });
  }));
```

Don't specify a transform fn, and let the batches be processed by another stream
```javascript
var through2Batch = require('through2-batch');

fs.createReadStream('data.csv')
  .pipe(csv2())
  .pipe(through2Batch.obj())
  .pipe(getSomeOtherStreamProcessingBatches());
```


Contributing
------------

Fixed or improved stuff? Great! Send me a pull request [through GitHub](http://github.com/nemo/through2-batch)
or get in touch on Twitter [@ngardideh](@ngardideh).

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