All files / piscosour/lib/utils stream-write-hook.js

0% Statements 0/10
100% Branches 0/0
0% Functions 0/3
0% Lines 0/10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22                                           
'use strict';
 
let _hooks = {};
 
const hook = function hook(stream, hook) { //eslint-disable-line no-shadow
  let _write = _hooks[stream] = stream.write;
  let _hook = hook;
 
  stream.write = function(chunk, encoding, cb) {
    _write.apply(stream, arguments);
    _hook(chunk, encoding, cb);
  };
};
 
const unhook = function unhook(stream) {
  stream.write = _hooks[stream];
};
 
module.exports = {
  hook: hook,
  unhook: unhook
};