You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
parttimejob/node_modules/end-or-error/index.js

40 lines
613 B

/**!
* end-or-error - index.js
*
* Copyright(c) stream-utils and other contributors.
* MIT Licensed
*
* Authors:
* fengmk2 <m@fengmk2.com> (http://fengmk2.com)
*/
'use strict';
/**
* Module dependencies.
*/
module.exports = function eoe(stream, cb) {
if (!stream.readable) {
return cb();
}
stream.on('error', onerror);
stream.on('end', onend);
function onerror(err) {
cleanup();
cb(err);
}
function onend(data) {
cleanup();
cb(null, data);
}
function cleanup() {
stream.removeListener('error', onerror);
stream.removeListener('end', onend);
}
};