Repository navigation
Buffer.fromHex and Buffer.fromBase64 should return Buffer instances #61146
Description
Activity
Removing this makes sense to me, because
Buffer.from(string, 'hex')already does this> Buffer.from("00ff", 'hex') <Buffer 00 ff> >Those are not equivalent
Buffer.from('...', 'hex')is loose and is garbage-in-garbage-out, whileUint8Array.fromHexperforms validation> Buffer.from('abggcd00','hex') <Buffer ab> > Uint8Array.fromHex('abggcd00') Uncaught SyntaxError: Input string must contain hex characters in even length >
Also, it's already shipped in 25.
Reacted by Mert Can AltinRemoving these doesn't make sense as these APIs come from Buffer's superclass. Having them return a Buffer does make sense to me.
Reacted by Mert Can Altin and Nikita SkovorodaThanks for answers, I thought this method did the same thing, I'll open an PR for identification.
My personal feeling is that these can just be left alone. These methods aren't part of the documented Buffer API, users aren't just going to stumble across them by accident, and we're not adding new functionality by overriding them, nor are they causing any particular harm by existing.
We don't override the prototypes of returned objects from non-species-aware ES2023 TypedArray methods (
with,toReversed, etc.) either, and this doesn't seem to have caused any complaint.- addedbufferIssues and PRs related to the buffer subsystem.Issues and PRs related to the buffer subsystem.
on Dec 30, 2025 We don't override the prototypes of returned objects from non-species-aware ES2023 TypedArray methods (
with,toReversed, etc.) either, and this doesn't seem to have caused any complaint.Nice catch. I think these should be fixed as well anyway, it's wrong to have
buffer.subarray()andbuffer.sort()returningBuffers whilebuffer.with()andbuffer.toSorted()returnUint8Arrays for the samebuffer.github-actions commented
on Jul 20, 2026 on Jul 20, 2026 – with GitHub ActionsContributorMore actionsThis issue has been marked as stale due to 90 days of inactivity.
It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.- addedstaleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.Issues and PRs marked stale due to inactivity and scheduled for automatic closure.
on Jul 20, 2026
Those should either be removed from the
BufferAPI, or should returnBuffersCurrently:
Since 25