租房小程序前端代码
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.

63 lines
2.4 KiB

3 months ago
  1. # destroy
  2. [![NPM version][npm-image]][npm-url]
  3. [![Build Status][github-actions-ci-image]][github-actions-ci-url]
  4. [![Test coverage][coveralls-image]][coveralls-url]
  5. [![License][license-image]][license-url]
  6. [![Downloads][downloads-image]][downloads-url]
  7. Destroy a stream.
  8. This module is meant to ensure a stream gets destroyed, handling different APIs
  9. and Node.js bugs.
  10. ## API
  11. ```js
  12. var destroy = require('destroy')
  13. ```
  14. ### destroy(stream [, suppress])
  15. Destroy the given stream, and optionally suppress any future `error` events.
  16. In most cases, this is identical to a simple `stream.destroy()` call. The rules
  17. are as follows for a given stream:
  18. 1. If the `stream` is an instance of `ReadStream`, then call `stream.destroy()`
  19. and add a listener to the `open` event to call `stream.close()` if it is
  20. fired. This is for a Node.js bug that will leak a file descriptor if
  21. `.destroy()` is called before `open`.
  22. 2. If the `stream` is an instance of a zlib stream, then call `stream.destroy()`
  23. and close the underlying zlib handle if open, otherwise call `stream.close()`.
  24. This is for consistency across Node.js versions and a Node.js bug that will
  25. leak a native zlib handle.
  26. 3. If the `stream` is not an instance of `Stream`, then nothing happens.
  27. 4. If the `stream` has a `.destroy()` method, then call it.
  28. The function returns the `stream` passed in as the argument.
  29. ## Example
  30. ```js
  31. var destroy = require('destroy')
  32. var fs = require('fs')
  33. var stream = fs.createReadStream('package.json')
  34. // ... and later
  35. destroy(stream)
  36. ```
  37. [npm-image]: https://img.shields.io/npm/v/destroy.svg?style=flat-square
  38. [npm-url]: https://npmjs.org/package/destroy
  39. [github-tag]: http://img.shields.io/github/tag/stream-utils/destroy.svg?style=flat-square
  40. [github-url]: https://github.com/stream-utils/destroy/tags
  41. [coveralls-image]: https://img.shields.io/coveralls/stream-utils/destroy.svg?style=flat-square
  42. [coveralls-url]: https://coveralls.io/r/stream-utils/destroy?branch=master
  43. [license-image]: http://img.shields.io/npm/l/destroy.svg?style=flat-square
  44. [license-url]: LICENSE.md
  45. [downloads-image]: http://img.shields.io/npm/dm/destroy.svg?style=flat-square
  46. [downloads-url]: https://npmjs.org/package/destroy
  47. [github-actions-ci-image]: https://img.shields.io/github/workflow/status/stream-utils/destroy/ci/master?label=ci&style=flat-square
  48. [github-actions-ci-url]: https://github.com/stream-utils/destroy/actions/workflows/ci.yml