Skip to content

cool-Blue/tapit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node.js Intercept write streams

tapit captures or modifies a node js write stream.

Based on intercept-stdout by Steve Farthing

Capture

var intercept = require("tapit"),
	captured_text = "",
	_stream = fs.createWriteStream(outFile);

var unhook_intercept = intercept(_stream, function(txt) {
	captured_text += txt;
});

_stream.write("This text is being captured");

// Let's stop capturing stdout.
unhook_intercept();

_stream.write("This text is not being captured");

Modify

var intercept = require("tapit");

var unhook_intercept = intercept(_stream, function(txt) {
	return txt.replace( /this/i , 'that' );
});

_stream.write("This text is being modified");
// -> that text is being modified

Test

npm install
npm test

About Colorization

Popular modules such as mocha and winston may colorize output by inserting ANSI escape codes into the output stream. Both mocha and winston make multiple calls to the output streams while colorizing a line -- in order to be robust, your code should anticipate and deal with this.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published