Archived
1
0
Fork 0
This repository has been archived on 2019-02-05. You can view files and clone it, but cannot push or open issues or pull requests.
Pong/node_modules/destroy/index.js

37 lines
664 B
JavaScript
Raw Normal View History

2017-01-20 22:42:49 +00:00
var ReadStream = require('fs').ReadStream
var Stream = require('stream')
module.exports = function destroy(stream) {
if (stream instanceof ReadStream) {
return destroyReadStream(stream)
}
if (!(stream instanceof Stream)) {
return stream
}
if (typeof stream.destroy === 'function') {
stream.destroy()
}
return stream
}
function destroyReadStream(stream) {
stream.destroy()
if (typeof stream.close === 'function') {
// node.js core bug work-around
stream.on('open', onopenClose)
}
return stream
}
function onopenClose() {
if (typeof this.fd === 'number') {
// actually close down the fd
this.close()
}
}