Skip to content

Commit 1c1d894

Browse files
authored
fix: detect node stream with hasOwnProperty (#33)
* fix: destroy the stream reguardless * chore: detect PassThrough stream with source.hasOwnProperty * chore: linting
1 parent 845b8c3 commit 1c1d894

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/http.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -263,15 +263,13 @@ const ndjson = async function * (source) {
263263
const streamToAsyncIterator = function (source) {
264264
if (isAsyncIterator(source)) {
265265
// Workaround for https://github.com/node-fetch/node-fetch/issues/766
266-
if (source.writable && source.readable) {
266+
if (Object.prototype.hasOwnProperty.call(source, 'readable') && Object.prototype.hasOwnProperty.call(source, 'writable')) {
267267
const iter = source[Symbol.asyncIterator]()
268268

269269
const wrapper = {
270270
next: iter.next.bind(iter),
271271
return: () => {
272-
if (source.writableEnded) {
273-
source.destroy()
274-
}
272+
source.destroy()
275273

276274
return iter.return()
277275
},

0 commit comments

Comments
 (0)