diff --git a/lib/utils.js b/lib/utils.js index 852ee97..8ee2955 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -41,20 +41,20 @@ async function * intoAsyncIterator (payload) { const isBuffer = Buffer.isBuffer(payload) if ( - ( + !isBuffer && ( // ArrayBuffer payload instanceof ArrayBuffer || // NodeJS.TypedArray ArrayBuffer.isView(payload) - ) && - // Exclude Buffer to prevent double cast - !isBuffer + ) ) { payload = Buffer.from(payload) } + const isObject = typeof payload === 'object' + // Iterator - if (typeof payload === 'object' && typeof payload[Symbol.iterator] === 'function' && !isBuffer) { + if (!isBuffer && isObject && Symbol.iterator in payload) { for (const chunk of payload) { yield chunk } @@ -62,7 +62,7 @@ async function * intoAsyncIterator (payload) { } // Async Iterator - if (typeof payload === 'object' && typeof payload[Symbol.asyncIterator] === 'function' && !isBuffer) { + if (!isBuffer && isObject && Symbol.asyncIterator in payload) { for await (const chunk of payload) { yield chunk }