# stream-splice

> Splice multiple streams into a single pipeline. Useful for exposing multi-step piped streams as a single stream.

Latest version **1.1.0** (published 2016-08-25) · MIT license · 0 weekly downloads

## Install

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

## 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.0 |
| Published | 2016-08-25 |
| First published | 2013-08-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Bryce B. Baril |
| Maintainers | bryce |
| Keywords | stream, streams, streams2, transform, pipeline, splice |

## Links

- npm: https://www.npmjs.com/package/stream-splice
- Repository: https://github.com/brycebaril/stream-splice
- Homepage: https://github.com/brycebaril/stream-splice#readme
- Issues: https://github.com/brycebaril/stream-splice/issues
- npm.io page: https://npm.io/package/stream-splice

## 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.0 (latest) — 2016-08-25
- 1.0.9 — 2015-01-21
- 1.0.8 — 2014-01-31
- 1.0.7 — 2013-10-26
- 1.0.6 — 2013-10-03
- 1.0.5 — 2013-09-26
- 1.0.4 — 2013-09-20
- 1.0.3 — 2013-08-28
- 1.0.2 — 2013-08-17
- 1.0.0 — 2013-08-17

## README

stream-splice
=====

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

Compose multi-step streams into a single pipeline segment.

E.g. your transform module is actually two consecutive transform operations, but you want it exposed as a single "stream.Transform" object.

```javascript
// In your module
module.exports = tx
var filter = require("through2-filter")
var map = require("through2-map")
var splice = require("stream-splice")

function tx() {
  var noBs = filter(function (chunk) { return /[^bB]/.exec(chunk) })
  var uc = map(function (chunk) { return chunk.toString().toUpperCase() })
  var zz = map(function (chunk) { return chunk.toString() + "z" })

  return splice(noBs, uc, zz)
}

// Using your module:
var tx = require("my-module")

source.pipe(tx()).pipe(/* ... */)

// That is equivalent to:
source.pipe(noBs)
  .pipe(uc)
  .pipe(zz)
  .pipe(/* ... */)

// A less contrived example:
// catLines is equivalent to fs.createReadStream except stream chunks
// will be the lines of the file
module.exports = catLines

var fs = require("fs")
var split = require("split")
var map = require("through2-map")
var splice = require("stream-splice")

function catLines(filename, options) {
  var rs = fs.createReadStream(filename, options)
  var reAddNewline = map(function (chunk) { return chunk.toString() + "\n" })
  return splice(rs, split(), reAddNewline)
}


```

API
===

`splice(stream1 [,stream2] [,...streamN])`
---

Creates a pipeline that can be piped into/out of which is composed of all of the spliced streams piped together.

E.g.

```javascript
source.pipe(splice(a, b, c)).pipe(drain)

// is roughly equivalent to

source.pipe(a)
  .pipe(b)
  .pipe(c)
  .pipe(drain)

```

Error Handling:
---

Just like `pipe`, `splice` does **NOT** attempt to do error forwarding. Sure, it could do something where all the errors in the pipeline are forwarded onto the topmost stream, however this would create a hidden requirement of code organization where your error handlers would have to be above the `splice` call to avoid double-handled errors.

So do this:
```js
a.on("error", someErrHandler)
b.on("error", someErrHandler)
c.on("error", someErrHandler)

source.pipe(splice(a, b, c)).pipe(drain)
```

This will let you keep the maximum flexibility with your error handling.

LICENSE
=======

MIT

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