Fix license issues
[sdnc/oam.git] / dgbuilder / dgeflows / node_modules / express / node_modules / send / node_modules / destroy / index.js
1 var ReadStream = require('fs').ReadStream
2 var Stream = require('stream')
3
4 module.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
20 function 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
31 function onopenClose() {
32   if (typeof this.fd === 'number') {
33     // actually close down the fd
34     this.close()
35   }
36 }