-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
fix cloning of buffers #2
base: main
Are you sure you want to change the base?
Conversation
Properly handles cloning of buffers in Node.js and browser environments.
@ljharb Could you please review after my latest changes? |
} else if (isBuffer(src)) { | ||
dst = Buffer.from(src); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} else if (isBuffer(src)) { | |
dst = Buffer.from(src); | |
} else if (isBuffer(src) && typeof Buffer.from === 'function') { | |
dst = Buffer.from(src); |
i'm a bit concerned that merely mentioning Buffer
would cause bundlers to bring in the buffer
polyfill unnecessarily, which is why the isBuffer
code is authored the way it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, yeah not sure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any updates?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still concerned here - I don't think we can use Buffer.from
without incurring a bundle size impact. I think we could use the safe-buffer
package, but then we need to add a dependency.
b680012
to
598a5c4
Compare
Properly handles cloning of
Buffer
objects in Node.js.Without this fix,
Buffer
objects would get corrupted after cloning as is demonstrated by the unit test.