Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: replace into-stream to Readable.from #290

Merged
merged 14 commits into from
Mar 29, 2024
12 changes: 6 additions & 6 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,28 @@ 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) {
Uzlopak marked this conversation as resolved.
Show resolved Hide resolved
for (const chunk of payload) {
yield chunk
}
return
}

// 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
}
Expand Down
Loading