source: node_modules/destroy/README.md

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

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