You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
664 B

8 years ago
  1. var ReadStream = require('fs').ReadStream
  2. var Stream = require('stream')
  3. module.exports = function destroy(stream) {
  4. if (stream instanceof ReadStream) {
  5. return destroyReadStream(stream)
  6. }
  7. if (!(stream instanceof Stream)) {
  8. return stream
  9. }
  10. if (typeof stream.destroy === 'function') {
  11. stream.destroy()
  12. }
  13. return stream
  14. }
  15. function destroyReadStream(stream) {
  16. stream.destroy()
  17. if (typeof stream.close === 'function') {
  18. // node.js core bug work-around
  19. stream.on('open', onopenClose)
  20. }
  21. return stream
  22. }
  23. function onopenClose() {
  24. if (typeof this.fd === 'number') {
  25. // actually close down the fd
  26. this.close()
  27. }
  28. }