/ cloudformation-templates / node_modules / aws-cdk / node_modules / exit-on-epipe / exit-on-epipe.js
exit-on-epipe.js
1 /* exit-on-epipe.js (C) 2015-present SheetJS -- http://sheetjs.com */ 2 /* vim: set ts=2: */ 3 /*jshint eqnull:true, node:true */ 4 var eoepipe = function eoepipeit(S/*:events$EventEmitter*/, bail/*:?()=>any*/) { 5 if(!S || !S.on) return; 6 if(!bail && typeof process !== 'undefined') bail = process.exit; 7 var eoe = function eoeit(err/*:ErrnoError*/) { 8 if(err.code === 'EPIPE' || err.errno === /*EPIPE*/32) { if(bail) bail(); else return; } 9 var cnt = S.listenerCount ? S.listenerCount('error') : S.listeners('error').length; 10 if(cnt == 1) { 11 S.removeListener('error', eoe); 12 S.emit('error', err); 13 S.on('error', eoe); 14 } 15 }; 16 S.on('error', eoe); 17 }; 18 19 if(typeof module !== 'undefined') module.exports = eoepipe; 20 if(typeof process !== 'undefined') eoepipe(process.stdout);