mimic-response
Advanced tools
Comparing version 3.0.0 to 3.1.0
20
index.js
@@ -25,2 +25,6 @@ 'use strict'; | ||
module.exports = (fromStream, toStream) => { | ||
if (toStream._readableState.autoDestroy) { | ||
throw new Error('The second stream must have the `autoDestroy` option set to `false`'); | ||
} | ||
const fromProperties = new Set(Object.keys(fromStream).concat(knownProperties)); | ||
@@ -54,6 +58,22 @@ | ||
fromStream.once('aborted', () => { | ||
toStream.destroy(); | ||
toStream.emit('aborted'); | ||
}); | ||
fromStream.once('close', () => { | ||
if (fromStream.complete) { | ||
if (toStream.readable) { | ||
toStream.once('end', () => { | ||
toStream.emit('close'); | ||
}); | ||
} else { | ||
toStream.emit('close'); | ||
} | ||
} else { | ||
toStream.emit('close'); | ||
} | ||
}); | ||
return toStream; | ||
}; |
{ | ||
"name": "mimic-response", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "Mimic a Node.js HTTP response stream", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -51,30 +51,2 @@ # mimic-response [![Build Status](https://travis-ci.com/sindresorhus/mimic-response.svg?branch=master)](https://travis-ci.com/sindresorhus/mimic-response) | ||
**Note #2:** The `aborted` and `close` events are not proxied. You have to add them manually: | ||
```js | ||
const stream = require('stream'); | ||
const mimicResponse = require('mimic-response'); | ||
const responseStream = getHttpResponseStream(); | ||
const myStream = new stream.PassThrough({ | ||
destroy(error, callback) { | ||
responseStream.destroy(); | ||
callback(error); | ||
} | ||
}); | ||
responseStream.once('aborted', () => { | ||
myStream.destroy(); | ||
myStream.emit('aborted'); | ||
}); | ||
responseStream.once('closed', () => { | ||
myStream.emit('closed'); | ||
}); | ||
responseStream.pipe(myStream); | ||
``` | ||
#### from | ||
@@ -81,0 +53,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
78
6003
79