Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fwd-stream

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fwd-stream

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

  • 1.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
135K
increased by0.84%
Maintainers
1
Weekly downloads
 
Created
Source

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

FAQs

Package last updated on 12 Apr 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc