# stream-stack

> Filter low-level `Stream` instances into stackable, protocol-based streams.

Latest version **1.1.4** (published 2012-05-04) · 0 weekly downloads

## Install

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

## 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.4 |
| Published | 2012-05-04 |
| First published | 2011-01-02 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.3.0 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Nathan Rajlich |
| Maintainers | TooTallNate, tootallnate |
| Keywords | stream, stack, protocol, filter |

## Links

- npm: https://www.npmjs.com/package/stream-stack
- npm.io page: https://npm.io/package/stream-stack

## 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.4 (latest) — 2012-05-04
- 1.1.3 — 2011-06-25
- 1.1.2 — 2011-05-10
- 1.1.1 — 2011-02-04
- 0.0.1 — 2011-01-02
- 0.0.2 — 2011-01-02
- 0.1.0 — 2011-01-02
- 1.0.0 — 2011-01-02
- 1.0.1 — 2011-01-02
- 1.1.0 — 2011-01-02

## README

node-stream-stack
=================
### Filter low-level `Stream` instances into stackable, protocol-based streams.

This module exposes the `StreamStack` interface, which starts off as a node
`Stream` subclass that accepts a "parent" Stream to work with. `StreamStack` is
meant to be subclassed in order to implement the layers of a protocol, or run the
parent Stream's data through some kind of filter (i.e. compression).

By default, a `StreamStack` instance proxies all events downstream (from the
parent stream to the child stream), and proxies all functions calls upstream
(from the child stream to the parent stream).

Keeping the `StreamStack` subclass' implementation independent of the parent
`Stream` instance allows for the backend transport to be easily swapped out
for flexibility and code re-use. For example, storing `netcat` results to a file,
and using `fs.ReadStream` as your parent stream, rather than `net.Stream`, in your
test cases.

Since `StreamStack` inherits from the regular node `Stream`, all it's prototypal
goodies can be used along with your subclass instances. This makes it extremely
easy for you to call `Stream#pipe(writable)`, in order to utilize node's data
transfer philosophies.


A Simple Example
----------------

Here's a simple, kinda silly example:

``` js
var util = require('util');
var StreamStack = require('stream-stack').StreamStack;

// The first argument is the parent stream
function DoubleWrite(stream) {
  StreamStack.call(this, stream);
}
util.inherits(DoubleWrite, StreamStack);

// Overwrite the default `write()` function to call
// write() on the parent stream twice!
DoubleWrite.prototype.write = function(data) {
  this.stream.write(data);
  this.stream.write(data);
}


// How to Use:
var doubleStdout = new DoubleWrite(process.stdout);
doubleStdout.write("this will be printed twice!\n");
```

We've defined a `DoubleWrite` class. It accepts a writable stream, and
whenever `write()` is called on the DoubleWrite instance, then in return
`write()` get called _twice_ on the parent stream. In this example, our
writable stream, `process.stdout`, will get the string printed to it twice.


Known Subclasses
----------------

Check out the [Wiki][] page to see the list of [Known Subclasses][Wiki].

[Wiki]: https://github.com/TooTallNate/node-stream-stack/wiki

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