promise-readable
Advanced tools
Comparing version 3.0.0 to 3.0.1
# Changelog | ||
## v3.0.1 2018-02-04 | ||
* Minor refactoring. | ||
## v3.0.0 2018-02-03 | ||
@@ -4,0 +8,0 @@ |
@@ -32,6 +32,3 @@ 'use strict' | ||
if (chunk != null) { | ||
stream.removeListener('close', closeHandler) | ||
stream.removeListener('error', errorHandler) | ||
stream.removeListener('end', endHandler) | ||
stream.removeListener('readable', readableHandler) | ||
removeListeners() | ||
resolve(chunk) | ||
@@ -42,5 +39,3 @@ } | ||
const closeHandler = () => { | ||
stream.removeListener('end', endHandler) | ||
stream.removeListener('error', errorHandler) | ||
stream.removeListener('readable', readableHandler) | ||
removeListeners() | ||
resolve(stream.bytesWritten || 0) | ||
@@ -50,5 +45,3 @@ } | ||
const endHandler = () => { | ||
stream.removeListener('close', closeHandler) | ||
stream.removeListener('error', errorHandler) | ||
stream.removeListener('readable', readableHandler) | ||
removeListeners() | ||
resolve() | ||
@@ -59,11 +52,16 @@ } | ||
delete this._errored | ||
removeListeners() | ||
reject(err) | ||
} | ||
const removeListeners = () => { | ||
stream.removeListener('close', closeHandler) | ||
stream.removeListener('error', errorHandler) | ||
stream.removeListener('end', endHandler) | ||
stream.removeListener('readable', readableHandler) | ||
reject(err) | ||
} | ||
stream.once('close', closeHandler) | ||
stream.once('end', endHandler) | ||
stream.once('error', errorHandler) | ||
stream.on('close', closeHandler) | ||
stream.on('end', endHandler) | ||
stream.on('error', errorHandler) | ||
stream.on('readable', readableHandler) | ||
@@ -95,5 +93,3 @@ | ||
const closeHandler = () => { | ||
stream.removeListener('data', dataHandler) | ||
stream.removeListener('end', endHandler) | ||
stream.removeListener('error', errorHandler) | ||
removeListeners() | ||
resolve(stream.bytesWritten || 0) | ||
@@ -103,5 +99,3 @@ } | ||
const endHandler = () => { | ||
stream.removeListener('close', closeHandler) | ||
stream.removeListener('data', dataHandler) | ||
stream.removeListener('error', errorHandler) | ||
removeListeners() | ||
resolve(Buffer.concat(bufferArray)) | ||
@@ -112,12 +106,17 @@ } | ||
delete this._errored | ||
removeListeners() | ||
reject(err) | ||
} | ||
const removeListeners = () => { | ||
stream.removeListener('close', closeHandler) | ||
stream.removeListener('data', dataHandler) | ||
stream.removeListener('error', errorHandler) | ||
stream.removeListener('end', endHandler) | ||
reject(err) | ||
} | ||
stream.once('close', closeHandler) | ||
stream.on('close', closeHandler) | ||
stream.on('data', dataHandler) | ||
stream.once('end', endHandler) | ||
stream.once('error', errorHandler) | ||
stream.on('end', endHandler) | ||
stream.on('error', errorHandler) | ||
@@ -153,9 +152,3 @@ stream.resume() | ||
const closeHandler = () => { | ||
if (eventHandler) { | ||
stream.removeListener(event, eventHandler) | ||
} | ||
stream.removeListener('error', errorHandler) | ||
if (endHandler) { | ||
stream.removeListener('end', endHandler) | ||
} | ||
removeListeners() | ||
resolve() | ||
@@ -165,7 +158,3 @@ } | ||
const eventHandler = event !== 'close' && event !== 'end' && event !== 'error' ? (argument) => { | ||
stream.removeListener('close', closeHandler) | ||
stream.removeListener('error', errorHandler) | ||
if (endHandler) { | ||
stream.removeListener('end', endHandler) | ||
} | ||
removeListeners() | ||
resolve(argument) | ||
@@ -175,7 +164,3 @@ } : undefined | ||
const endHandler = event !== 'close' ? () => { | ||
if (eventHandler) { | ||
stream.removeListener(event, eventHandler) | ||
} | ||
stream.removeListener('close', closeHandler) | ||
stream.removeListener('error', errorHandler) | ||
removeListeners() | ||
resolve() | ||
@@ -186,20 +171,25 @@ } : undefined | ||
delete this._errored | ||
removeListeners() | ||
reject(err) | ||
} | ||
const removeListeners = () => { | ||
if (eventHandler) { | ||
stream.removeListener(event, eventHandler) | ||
} | ||
stream.removeListener('close', closeHandler) | ||
stream.removeListener('error', errorHandler) | ||
if (endHandler) { | ||
stream.removeListener('end', endHandler) | ||
} | ||
reject(err) | ||
stream.removeListener('error', errorHandler) | ||
} | ||
if (eventHandler) { | ||
stream.once(event, eventHandler) | ||
stream.on(event, eventHandler) | ||
} | ||
stream.once('close', closeHandler) | ||
stream.on('close', closeHandler) | ||
if (endHandler) { | ||
stream.once('end', endHandler) | ||
stream.on('end', endHandler) | ||
} | ||
stream.once('error', errorHandler) | ||
stream.on('error', errorHandler) | ||
}) | ||
@@ -210,2 +200,3 @@ } | ||
this.stream.removeListener('error', this._errorHandler) | ||
delete this._errorHandler | ||
if (typeof this.stream.destroy === 'function') { | ||
@@ -212,0 +203,0 @@ this.stream.destroy() |
{ | ||
"name": "promise-readable", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "Return promise for readable stream", | ||
@@ -5,0 +5,0 @@ "main": "lib/promise-readable.js", |
@@ -147,2 +147,9 @@ ## promise-readable | ||
### See also | ||
[`PromiseWritable`](https://www.npmjs.com/package/promise-writable), | ||
[`PromiseDuplex`](https://www.npmjs.com/package/promise-duplex), | ||
[`PromiseSocket`](https://www.npmjs.com/package/promise-socket), | ||
[`PromisePiping`](https://www.npmjs.com/package/promise-piping). | ||
### License | ||
@@ -149,0 +156,0 @@ |
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
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
159
0
14130
187