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

Make Buffer more compliant with official implementation #285

Closed
wants to merge 1 commit into from
Closed

Make Buffer more compliant with official implementation #285

wants to merge 1 commit into from

Conversation

Soremwar
Copy link

This fixes all the instances where Uint8Array is a valid parameter but errors due to the parameter "not being a buffer"

@Soremwar
Copy link
Author

@feross I know this is a small change, but this is needed to land nodejs/readable-stream#452 so your review will be very appreciated

@addaleax
Copy link

addaleax commented May 7, 2021

@feross Any chance you could take a look at this? :)

@addaleax
Copy link

ping @feross? :)

@@ -1688,7 +1688,7 @@ Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert

// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
Buffer.prototype.copy = function copy (target, targetStart, start, end) {
if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer')
if (!Buffer.isBuffer(target) && !(target instanceof Uint8Array)) throw new TypeError('argument should be a Buffer')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s probably nicer to use Object.prototype.toString.call(target) === '[object Uint8Array]' here instead of instanceof, because instanceof still won’t work across multiple realms (e.g. iframes)

@Soremwar Soremwar closed this Nov 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants