# push-chunks

> push-chunks allows you implement binary parsers in a few lines

Latest version **1.0.1** (published 2018-02-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install push-chunks
pnpm add push-chunks
yarn add push-chunks
bun add push-chunks
```

## 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.0.1 |
| Published | 2018-02-18 |
| First published | 2018-02-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 5.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | 'Dominic Tarr' |
| Maintainers | dominictarr |

## Links

- npm: https://www.npmjs.com/package/push-chunks
- Repository: https://github.com/dominictarr/push-chunks
- Issues: https://github.com/dominictarr/push-chunks/issues
- npm.io page: https://npm.io/package/push-chunks

## Dependencies (2)

- [bl](https://npm.io/package/bl.md) ^1.2.1
- [push-stream](https://npm.io/package/push-stream.md) ^10.0.0

## Recent versions

- 1.0.1 (latest) — 2018-02-18
- 1.0.0 — 2018-02-18

## README

# push-chunks

push-chunks allows you implement binary parsers in a few lines

## example

suppose we want a stream of length delimited blocks.

``` js
var chunks = new Chunks(function header (bl) {

  //check if there isn't enough input to read the header
  if(bl.length < header_length) return

  //check if there is enough input to read the body
  if(bl.readUInt32BE(0) < bl.length) return

  //we are good! go to the body
  return true
}, function body (bl) {
  var length = bl.readUInt32BE(0)

  //if the length is zero, return undefined to signal end.
  if(!length) return

  //else slice the content and return!
  var buffer = bl.slice(4, 4+length)
  bl.consume(4)
  return buffer
}

source.pipe(chunks).pipe(sink)
```

## api: new Chunks (header(bl) => boolean, body (bl) => *)

`header` and `body` take the [buffer-list](https://npm.im/bl) which is holding
the buffers written to this stream. If `header` returns true, then `body` is called.
If body returns `undefined` the stream is ended. If body returns anything else
it's written to the streams sink.

## License

MIT

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