-
-
Save Raynos/6b3b2b99aa0972e58b71 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fastPump(source, onChunk, onError, onFinish) { | |
function onRead(err, chunk) { | |
if (err === true) { | |
return onFinish() | |
} else if (err) { | |
onError(err) | |
} else { | |
onChunk(chunk) | |
} | |
source.read(onRead) | |
} | |
source.read(onRead) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var s = StreamThing() | |
s.read(function callback(err, chunk) { | |
// read from the stream | |
if (err === true) { | |
// end of stream | |
} else if (err) { | |
// OOPS. err | |
} else { | |
// got a chunk | |
} | |
}) | |
// close the damned thing. | |
s.abort(function errorListener(err) { | |
if (err) { | |
// Something went wrong with abort | |
} else { | |
// successful abort | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment