Projekt

Obecné

Profil

Stáhnout (2.13 KB) Statistiky
| Větev: | Revize:
1
# Destroy
2

    
3
[![NPM version][npm-image]][npm-url]
4
[![Build status][travis-image]][travis-url]
5
[![Test coverage][coveralls-image]][coveralls-url]
6
[![License][license-image]][license-url]
7
[![Downloads][downloads-image]][downloads-url]
8
[![Gittip][gittip-image]][gittip-url]
9

    
10
Destroy a stream.
11

    
12
This module is meant to ensure a stream gets destroyed, handling different APIs
13
and Node.js bugs.
14

    
15
## API
16

    
17
```js
18
var destroy = require('destroy')
19
```
20

    
21
### destroy(stream)
22

    
23
Destroy the given stream. In most cases, this is identical to a simple
24
`stream.destroy()` call. The rules are as follows for a given stream:
25

    
26
  1. If the `stream` is an instance of `ReadStream`, then call `stream.destroy()`
27
     and add a listener to the `open` event to call `stream.close()` if it is
28
     fired. This is for a Node.js bug that will leak a file descriptor if
29
     `.destroy()` is called before `open`.
30
  2. If the `stream` is not an instance of `Stream`, then nothing happens.
31
  3. If the `stream` has a `.destroy()` method, then call it.
32

    
33
The function returns the `stream` passed in as the argument.
34

    
35
## Example
36

    
37
```js
38
var destroy = require('destroy')
39

    
40
var fs = require('fs')
41
var stream = fs.createReadStream('package.json')
42

    
43
// ... and later
44
destroy(stream)
45
```
46

    
47
[npm-image]: https://img.shields.io/npm/v/destroy.svg?style=flat-square
48
[npm-url]: https://npmjs.org/package/destroy
49
[github-tag]: http://img.shields.io/github/tag/stream-utils/destroy.svg?style=flat-square
50
[github-url]: https://github.com/stream-utils/destroy/tags
51
[travis-image]: https://img.shields.io/travis/stream-utils/destroy.svg?style=flat-square
52
[travis-url]: https://travis-ci.org/stream-utils/destroy
53
[coveralls-image]: https://img.shields.io/coveralls/stream-utils/destroy.svg?style=flat-square
54
[coveralls-url]: https://coveralls.io/r/stream-utils/destroy?branch=master
55
[license-image]: http://img.shields.io/npm/l/destroy.svg?style=flat-square
56
[license-url]: LICENSE.md
57
[downloads-image]: http://img.shields.io/npm/dm/destroy.svg?style=flat-square
58
[downloads-url]: https://npmjs.org/package/destroy
59
[gittip-image]: https://img.shields.io/gittip/jonathanong.svg?style=flat-square
60
[gittip-url]: https://www.gittip.com/jonathanong/
(2-2/4)