arnaucube
arnaucube/socketioMEANseedPublic Self-hosted repository
socketioMEANseed/server/node_modules/destroy/index.js
server/node_modules/destroy/index.jsRaw
 1var ReadStream = require('fs').ReadStream
 2var Stream = require('stream')
 3
 4module.exports = function destroy(stream) {
 5  if (stream instanceof ReadStream) {
 6    return destroyReadStream(stream)
 7  }
 8
 9  if (!(stream instanceof Stream)) {
10    return stream
11  }
12
13  if (typeof stream.destroy === 'function') {
14    stream.destroy()
15  }
16
17  return stream
18}
19
20function destroyReadStream(stream) {
21  stream.destroy()
22
23  if (typeof stream.close === 'function') {
24    // node.js core bug work-around
25    stream.on('open', onopenClose)
26  }
27
28  return stream
29}
30
31function onopenClose() {
32  if (typeof this.fd === 'number') {
33    // actually close down the fd
34    this.close()
35  }
36}