3 * Copyright(c) 2014 Jonathan Ong
10 * Module dependencies.
14 var ReadStream = require('fs').ReadStream
15 var Stream = require('stream')
22 module.exports = destroy
27 * @param {object} stream
31 function destroy(stream) {
32 if (stream instanceof ReadStream) {
33 return destroyReadStream(stream)
36 if (!(stream instanceof Stream)) {
40 if (typeof stream.destroy === 'function') {
48 * Destroy a ReadStream.
50 * @param {object} stream
54 function destroyReadStream(stream) {
57 if (typeof stream.close === 'function') {
58 // node.js core bug work-around
59 stream.on('open', onOpenClose)
66 * On open handler to close stream.
70 function onOpenClose() {
71 if (typeof this.fd === 'number') {
72 // actually close down the fd