/usr/lib/nodejs/hook-std/index.js is in node-hook-std 0.2.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | 'use strict';
function hook(type, opts, cb) {
if (typeof opts !== 'object') {
cb = opts;
opts = {};
}
var std = process[type];
var write = std.write;
std.write = function (str, enc, cb2) {
var cbRet = cb(str, enc);
if (opts.silent) {
return typeof cbRet === 'boolean' ? cbRet : true;
}
var ret = Buffer.isBuffer(cbRet) || typeof cbRet === 'string' ? cbRet : str;
return write.call(std, ret, enc, cb2);
};
return function () {
std.write = write;
};
}
var x = module.exports = function (opts, cb) {
var unhookStdout = hook('stdout', opts, cb);
var unhookStderr = hook('stderr', opts, cb);
return function () {
unhookStdout();
unhookStderr();
};
};
x.stdout = hook.bind(null, 'stdout');
x.stderr = hook.bind(null, 'stderr');
|