Socket
Book a DemoInstallSign in
Socket

hook-writable-stream

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hook-writable-stream

Hooking into Node.js writable stream

latest
Source
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

NPM version Build Status Dependency Status Coverage Status

Hooking into Node.js writable stream

Based on this gist. Useful when you need to test Node writable streams such as stdout.

Install

$ npm install --save-dev hook-writable-stream

Usage

Use a callback

var hookWritableStream = require('hook-writable-stream');
var hook = hookWritableStream(process.stdout, false, function(string) {
  //=> string === 'hooked!\n'
});

console.log('hooked!');
hook.unhook();
console.log('unhooked!');
//=> 'unhooked!' is shown on your console

Use as a stream

var hookWritableStream = require('hook-writable-stream');
var through = require('through2');

var hook = hookWritableStream(process.stdout, false);
var stream = hook.stream;
stream.pipe(through(function(chunk, enc, cb) {
  //=> chunk.toString() === 'hooked!\n'
  cb(chunk);
}));

console.log('hooked!');
hook.unhook();
console.log('unhooked!');
//=> 'unhooked!' is shown on your console

API

hookWritableStream(writableStream, [keepOriginal], [callback])

Returns an object.

unhook

Type: function

Call to unhook the writable stream.

stream

A stream that you can consume. The data that was going to written to the original stream is written to this stream.

writableStream

A node writable stream such as process.stdout.

keepOriginal

true to keep writing to the original stream.

callback(obj)

obj

Whatever is written to the original stream.

License

MIT © Steve Mao

Keywords

capture

FAQs

Package last updated on 08 Oct 2015

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