Skip to content

Instantly share code, notes, and snippets.

@Raynos

Raynos/pump.js Secret

Last active December 15, 2015 23:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Raynos/6b3b2b99aa0972e58b71 to your computer and use it in GitHub Desktop.
Save Raynos/6b3b2b99aa0972e58b71 to your computer and use it in GitHub Desktop.
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)
}
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