Skip to content

Commit

Permalink
method stream.read refactored.
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed Nov 2, 2015
1 parent a548fe9 commit 73a42f4
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions lib/ext/stream/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,24 +83,11 @@ function read(stream, receiver, closable, readSize) {
process();
}

function onEnd() {
if (!closable) {
success();
}
}

function onClose() {
success();
}

function onError(error) {
fail(error);
}

stream.on('readable', onReadable);
stream.on('end', onEnd);
stream.on('close', onClose);
stream.on('error', onError);
stream.once(closable ? 'close' : 'end', success);
stream.once('error', function (error) {
fail(error);
});

function process() {
if (!ready || stop || waiting) {
Expand Down Expand Up @@ -168,9 +155,6 @@ function read(stream, receiver, closable, readSize) {

function cleanup() {
stream.removeListener('readable', onReadable);
stream.removeListener('close', onClose);
stream.removeListener('error', onError);
stream.removeListener('end', onEnd);
}
});
}
Expand Down

0 comments on commit 73a42f4

Please sign in to comment.