Skip to content

Buffer.fromHex and Buffer.fromBase64 should return Buffer instances #61146

Description

@ChALkeR

Those should either be removed from the Buffer API, or should return Buffers

Currently:

> Buffer.fromHex('00ff').toString()
'0,255'

Since 25

Activity

  1. mertcanaltin commented on Dec 22, 2025

    @mertcanaltin
    Member

    Removing this makes sense to me, because Buffer.from(string, 'hex') already does this

    > Buffer.from("00ff", 'hex')
    <Buffer 00 ff>
    > 
    
  2. ChALkeR commented on Dec 22, 2025

    @ChALkeR
    MemberAuthor

    Those are not equivalent
    Buffer.from('...', 'hex') is loose and is garbage-in-garbage-out, while Uint8Array.fromHex performs 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.

  3. panva commented on Dec 22, 2025

    @panva
    Member

    Removing these doesn't make sense as these APIs come from Buffer's superclass. Having them return a Buffer does make sense to me.

  4. mertcanaltin commented on Dec 22, 2025

    @mertcanaltin
    Member

    Thanks for answers, I thought this method did the same thing, I'll open an PR for identification.

  5. Renegade334 commented on Dec 23, 2025

    @Renegade334
    Member

    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.

  6. added
    bufferIssues and PRs related to the buffer subsystem.
    on Dec 30, 2025
  7. LiviaMedeiros commented on Jan 6, 2026

    @LiviaMedeiros
    Member

    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() and buffer.sort() returning Buffers while buffer.with() and buffer.toSorted() return Uint8Arrays for the same buffer.

  8. github-actions commented on Jul 20, 2026

    @github-actions
    Contributor

    This 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.

  9. added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bufferIssues and PRs related to the buffer subsystem.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions