# fwd-stream

> Forward a readable stream to another readable stream or a writable stream to another writable stream

Latest version **1.0.4** (published 2014-04-12) · 0 weekly downloads

## Install

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

## 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.4 |
| Published | 2014-04-12 |
| First published | 2014-04-12 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 13 |
| Maintainers | mafintosh |

## Links

- npm: https://www.npmjs.com/package/fwd-stream
- Repository: https://github.com/mafintosh/fwd-stream
- Issues: https://github.com/mafintosh/fwd-stream/issues
- npm.io page: https://npm.io/package/fwd-stream

## Dependencies (1)

- [readable-stream](https://npm.io/package/readable-stream.md) ~1.0.26-4

## Recent versions

- 1.0.4 (latest) — 2014-04-12
- 1.0.3 — 2014-04-12
- 1.0.2 — 2014-04-12
- 1.0.1 — 2014-04-12
- 1.0.0 — 2014-04-12

## README

# fwd-stream

Forward a readable stream to another readable stream or a writable stream to another writable stream.
Featuring streams2 support and async instantiating.

	npm install fwd-stream

[![build status](https://secure.travis-ci.org/mafintosh/fwd-stream.png)](http://travis-ci.org/mafintosh/fwd-stream)

## When should I use this?

This module makes it easy to return a stream synchroniously that wraps another stream from an async context.
Say for example you wanted to create a folder before writing a write you could do

``` js
var fs = require('fs');
var fwd = require('fwd-stream');

var ws = fwd.writable(function(cb) {
	fs.mkdir('my-folder', function() {
		cb(null, fs.createWriteStream('my-folder/my-file.txt'));
	});
});

ws.write('content of my-file.txt');
```

## Usage

Forward readable streams

``` js
var fwd = require('fwd-stream');

// rs will be a stream that forwards someReadableStream's data and events
// backpressure etc will still be respected

var rs = fwd.readable(someReadableStream);

// or using async instantiating

var rs = fwd.readable(function(cb) {
	setTimeout(function() {
		cb(null, someReadableStream);
	}, 1000);
});

// or using objectMode

var rs = fwd.readable({objectMode:true}, someReadableObjectStream);
```

Forward writable streams

``` js
var ws = fwd.writable(someWritableStream);

// or using async instantiating

var ws = fwd.writable(function(cb) {
	setTimeout(function() {
		cb(null, ws);
	}, 1000);
});

// or using objectMode

var ws = fwd.writable({objectMode:true}, someWritableObjectStream);
```

Forward duplex streams

``` js
var dupl = fwd.duplex(someWritableStream, someReadableStream);

// or using async instantiating

var dupl = fwd.duplex(
	function(cb) {
		setTimeout(function() {
			cb(null, someWritableStream);
		}, 1000);
	},
	function(cb) {
		setTimeout(function() {
			cb(null, someReadableStream);
		}, 1000);
	}
);

// or using objectMode

var dupl = fwd.duplex({objectMode:true}, someReadableObjStream, someWritableObjStream);
```

## License

MIT

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