Comparing version 1.0.3 to 1.0.4
45
index.js
@@ -0,5 +1,32 @@ | ||
/*! | ||
* destroy | ||
* Copyright(c) 2014 Jonathan Ong | ||
* MIT Licensed | ||
*/ | ||
'use strict' | ||
/** | ||
* Module dependencies. | ||
* @private | ||
*/ | ||
var ReadStream = require('fs').ReadStream | ||
var Stream = require('stream') | ||
module.exports = function destroy(stream) { | ||
/** | ||
* Module exports. | ||
* @public | ||
*/ | ||
module.exports = destroy | ||
/** | ||
* Destroy a stream. | ||
* | ||
* @param {object} stream | ||
* @public | ||
*/ | ||
function destroy(stream) { | ||
if (stream instanceof ReadStream) { | ||
@@ -20,2 +47,9 @@ return destroyReadStream(stream) | ||
/** | ||
* Destroy a ReadStream. | ||
* | ||
* @param {object} stream | ||
* @private | ||
*/ | ||
function destroyReadStream(stream) { | ||
@@ -26,3 +60,3 @@ stream.destroy() | ||
// node.js core bug work-around | ||
stream.on('open', onopenClose) | ||
stream.on('open', onOpenClose) | ||
} | ||
@@ -33,3 +67,8 @@ | ||
function onopenClose() { | ||
/** | ||
* On open handler to close stream. | ||
* @private | ||
*/ | ||
function onOpenClose() { | ||
if (typeof this.fd === 'number') { | ||
@@ -36,0 +75,0 @@ // actually close down the fd |
{ | ||
"name": "destroy", | ||
"description": "destroy a stream if possible", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"author": { | ||
@@ -17,4 +17,4 @@ "name": "Jonathan Ong", | ||
"devDependencies": { | ||
"istanbul": "0", | ||
"mocha": "1" | ||
"istanbul": "0.4.2", | ||
"mocha": "2.3.4" | ||
}, | ||
@@ -27,3 +27,4 @@ "scripts": { | ||
"files": [ | ||
"index.js" | ||
"index.js", | ||
"LICENSE" | ||
], | ||
@@ -30,0 +31,0 @@ "keywords": [ |
@@ -6,3 +6,2 @@ # Destroy | ||
[![Test coverage][coveralls-image]][coveralls-url] | ||
[![Dependency Status][david-image]][david-url] | ||
[![License][license-image]][license-url] | ||
@@ -14,2 +13,5 @@ [![Downloads][downloads-image]][downloads-url] | ||
This module is meant to ensure a stream gets destroyed, handling different APIs | ||
and Node.js bugs. | ||
## API | ||
@@ -19,5 +21,27 @@ | ||
var destroy = require('destroy') | ||
``` | ||
### destroy(stream) | ||
Destroy the given stream. In most cases, this is identical to a simple | ||
`stream.destroy()` call. The rules are as follows for a given stream: | ||
1. If the `stream` is an instance of `ReadStream`, then call `stream.destroy()` | ||
and add a listener to the `open` event to call `stream.close()` if it is | ||
fired. This is for a Node.js bug that will leak a file descriptor if | ||
`.destroy()` is called before `open`. | ||
2. If the `stream` is not an instance of `Stream`, then nothing happens. | ||
3. If the `stream` has a `.destroy()` method, then call it. | ||
The function returns the `stream` passed in as the argument. | ||
## Example | ||
```js | ||
var destroy = require('destroy') | ||
var fs = require('fs') | ||
var stream = fs.createReadStream('package.json') | ||
// ... and later | ||
destroy(stream) | ||
@@ -34,4 +58,2 @@ ``` | ||
[coveralls-url]: https://coveralls.io/r/stream-utils/destroy?branch=master | ||
[david-image]: http://img.shields.io/david/stream-utils/destroy.svg?style=flat-square | ||
[david-url]: https://david-dm.org/stream-utils/destroy | ||
[license-image]: http://img.shields.io/npm/l/destroy.svg?style=flat-square | ||
@@ -38,0 +60,0 @@ [license-url]: LICENSE.md |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5197
4
59
61
1