From 1c1d894e72ce4be97da071aae0553592955571cc Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Wed, 8 Apr 2020 15:06:18 +0100 Subject: [PATCH] fix: detect node stream with hasOwnProperty (#33) * fix: destroy the stream reguardless * chore: detect PassThrough stream with source.hasOwnProperty * chore: linting --- src/http.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/http.js b/src/http.js index 2106335..7ec3b0f 100644 --- a/src/http.js +++ b/src/http.js @@ -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() },