Skip to content

Commit

Permalink
fix: detect node stream with hasOwnProperty (#33)
Browse files Browse the repository at this point in the history
* fix: destroy the stream reguardless
* chore: detect PassThrough stream with source.hasOwnProperty
* chore: linting
  • Loading branch information
achingbrain authored Apr 8, 2020
1 parent 845b8c3 commit 1c1d894
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,15 +263,13 @@ const ndjson = async function * (source) {
const streamToAsyncIterator = function (source) {
if (isAsyncIterator(source)) {
// Workaround for https://github.com/node-fetch/node-fetch/issues/766
if (source.writable && source.readable) {
if (Object.prototype.hasOwnProperty.call(source, 'readable') && Object.prototype.hasOwnProperty.call(source, 'writable')) {
const iter = source[Symbol.asyncIterator]()

const wrapper = {
next: iter.next.bind(iter),
return: () => {
if (source.writableEnded) {
source.destroy()
}
source.destroy()

return iter.return()
},
Expand Down

0 comments on commit 1c1d894

Please sign in to comment.