diff --git a/lib/net.js b/lib/net.js index 4a5fbe56e0..fc56918eba 100644 --- a/lib/net.js +++ b/lib/net.js @@ -461,7 +461,10 @@ function onread(buffer, offset, length) { // if it's not enough data, we'll just call handle.readStart() // again right away. self.bytesRead += length; - self._readableState.onread(null, buffer.slice(offset, end)); + + // Optimization: emit the original buffer with end points + if (self.ondata) self.ondata(buffer, offset, end); + else self._readableState.onread(null, buffer.slice(offset, end)); if (handle.reading && !self._readableState.reading) { handle.reading = false; @@ -471,9 +474,6 @@ function onread(buffer, offset, length) { self._destroy(errnoException(errno, 'read')); } - // Optimization: emit the original buffer with end points - if (self.ondata) self.ondata(buffer, offset, end); - } else if (errno == 'EOF') { debug('EOF');