fwd-stream
Forward a readable stream to another readable stream or a writable stream to another writable stream
Last updated 12 years ago by mafintosh .
Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install fwd-stream 
SYNC missed versions from official npm registry.

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

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

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

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

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

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

Current Tags

  • 1.0.4                                ...           latest (12 years ago)

5 Versions

  • 1.0.4                                ...           12 years ago
  • 1.0.3                                ...           12 years ago
  • 1.0.2                                ...           12 years ago
  • 1.0.1                                ...           12 years ago
  • 1.0.0                                ...           12 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (1)
Dev Dependencies (1)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |