GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — btoa() and atob() · Issue #3462 · nodejs/node

btoa() and atob() #3462

New issue
Copy link
New issue
Copy link
Closed
Closed
btoa() and atob()#3462
Copy link
Labels
feature requestIssues requesting new Node.js features.

Description

@silverwind
silverwind
opened on Oct 21, 2015
Issue body actions

All major browsers expose the btoa and atob globals for encoding ASCII strings as base64 and vice versa. It'd be beneficial for the "isomorphic" javascript topic if we'd provide these too:

  • https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/btoa
  • https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/atob

As for the implementation, we can't Buffer('string').toString('base64') because that would encode unicode while atob and btoa must per spec throw on charcodes > 255. https://github.com/mathiasbynens/base64 looks like a solid implemenation we could pretty much drop in.

Reacted by Radu-Sebastian Amarie, jungor, Thibaut, Busticated, fregante, zer0Id0l, Leah Vashevko, Kevin Fox, Alan Hogan, Chris and 41 more
Reacted by Anna Henningsen

Activity

Next
  1. silverwind
    added
    feature requestIssues requesting new Node.js features.
    on Oct 21, 2015
  2. MylesBorins commented on Oct 21, 2015

    @MylesBorins
    MylesBorins
    on Oct 21, 2015
    Contributor
    More actions

    I'd be up for writing a bunch of tests if people want to see this happen

  3. jasnell commented on Oct 21, 2015

    @jasnell
    jasnell
    on Oct 21, 2015
    Member
    More actions

    While I understand the desire on this, it could just as easily be implemented as a userland module that registers the globals. I'm -0 on adding it in to core.

    Reacted by Frederic Charette
    Reacted by curt, Golo Roden, Evgeny Kochetkov, miller46, Braden Snell, Alex, Jordan Brennan, MythologicalEngineer, Luke Tanner, Manuel K and 25 more
  4. mscdex commented on Oct 21, 2015

    @mscdex
    mscdex
    on Oct 21, 2015
    Contributor
    More actions

    I think I'm -1 on this for the same reason.

    Reacted by curt, Golo Roden, miller46, MythologicalEngineer, Luke Tanner, Manuel K, Jimmy Wärting, Sylvie Fox, 2qx, Merlin Westphal and 11 more
  5. trevnorris commented on Oct 21, 2015

    @trevnorris
    trevnorris
    on Oct 21, 2015
    Contributor
    More actions
    function btoa(str) {
      if (Buffer.byteLength(str) !== str.length)
        throw new Error('bad string!');
      return Buffer(str, 'binary').toString('base64');
    }

    Think that will about cover it.

    Update: actually, that's a bad length check and I'm too tired to work the correct one. we'd probably have to expose v8::String::ContainsOnlyOneByte() for the fastest option.

    Reacted by Shyam, Christophe Marois, Avindra Goolcharan, Busticated, Akonwi Ngoh, Arkadiusz Wieczorek, Blas Rodriguez Irizar, Tripp Lyons, Ostap Skryshevskyi, Spencer Jones and 16 more
  6. Fishrock123 commented on Oct 21, 2015

    @Fishrock123
    Fishrock123
    on Oct 21, 2015
    Contributor
    More actions

    I'd rather not add more globals, ever if possible.

  7. tflanagan commented on Oct 21, 2015

    @tflanagan
    tflanagan
    on Oct 21, 2015
    Contributor
    More actions

    The fact that you are linking to a userland package that already gets over a 1000 downloads a week (via npm) is solid evidence that the need for this, in core at least, is very minimal

    Reacted by curt, Golo Roden, Eric Newland, Kevin Stech, Matthew Ludwig, Miriam Vellacott, Almeida, Jon Telles and Nato Boram
  8. silverwind commented on Oct 21, 2015

    @silverwind
    silverwind
    on Oct 21, 2015
    ContributorAuthor
    More actions

    By the way: Why doesn't v8 provide functions like these?

  9. bnoordhuis commented on Oct 21, 2015

    @bnoordhuis
    bnoordhuis
    on Oct 21, 2015
    Member
    More actions

    They're browser extensions, they're not part of the ECMAScript spec: https://html.spec.whatwg.org/multipage/webappapis.html#atob

    Reacted by chpio, Steven Barnett, gcbw and Matthew Ludwig
  10. jasnell commented on Oct 21, 2015

    @jasnell
    jasnell
    on Oct 21, 2015
    Member
    More actions

    Feel free to continue discussing, but given the -1's, I'm closing.

    Reacted by Yves M., Kevin Stech and Frederic Charette
    Reacted by Nikolay Kuchumov, curt, Golo Roden, truelecter, miller46, Joshua Harms, Manuel K, Jeff Baranski, sliftist, Jędrzej Majko and 12 more
  11. jasnell
    closed this as completedon Oct 21, 2015
  12. henvic
    added 3 commits that reference this issue on Nov 30, 2015

    Fixing BasicAuth due to missing btoa().

    49b5b04

    Fixing BasicAuth due to missing btoa().

    91ae789

    Fixing BasicAuth due to missing btoa().

    c9c6563
  13. henvic
    added a commit that references this issue on Dec 15, 2015

    Fixing BasicAuth due to missing btoa().

    8b7e2ad
  14. 53 remaining items

  15. bmeck commented on Oct 6, 2020

    @bmeck
    bmeck
    on Oct 6, 2020
    Member
    More actions

    looking at WHAT spec btoa/atob only handle strings with 8bits, so emoji etc. will throw errors, likely those APIs are not sufficient, but I do not see a web API that does universal base64 transformation except FileReader.prototype.readAsDataURL.

  16. MylesBorins commented on Oct 6, 2020

    @MylesBorins
    MylesBorins
    on Oct 6, 2020
    Contributor
    More actions

    for base 64 there is https://en.wikipedia.org/wiki/Base64#RFC_4648

    I have helped to maintain a library that has quite a bit of usage in this space

    https://github.com/brianloveswords/base64url with 877k weekly downloads.

    Could be worth looking at that for API inspiration

  17. jasnell commented on Feb 27, 2021

    @jasnell
    jasnell
    on Feb 27, 2021
    Member
    More actions

    Opened a pr that implemented this and the immediate reaction was meh given that our current mechanisms for this are better and it's something that is easily handled by userland. Closing the issue as it's not something we're likely to land.

  18. jasnell
    closed this as completedon Feb 27, 2021
  19. jasnell
    added 2 commits that reference this issue on Mar 18, 2021

    buffer: implement btoa and atob

    08770bc

    test: app atob web platform tests

    c6855eb
  20. ruyadorno
    added 2 commits that reference this issue on Mar 20, 2021

    buffer: implement btoa and atob

    dc9cd43

    test: app atob web platform tests

    505f9c9
  21. devinivy commented on Apr 10, 2021

    @devinivy
    devinivy
    on Apr 10, 2021
    More actions

    In nodejs/citgm#852 (comment) it was flagged that there are some new globals in node v16 including atob() and btoa() that our test suites should account for. If these are here to stay we'll ensure our test suites allow these globals, but based on what @jasnell mentioned above it seems like they may not land in node v16. Any clarity on this would be much appreciated!

  22. cjihrig commented on Apr 10, 2021

    @cjihrig
    cjihrig
    on Apr 10, 2021
    Contributor
    More actions

    @devinivy these landed already, so I think it's safe for lab to start tracking them as allowed globals.

    Reacted by devin ivy, Beth Griggs, Jon Telles and Charles Crossan
  23. targos
    added 2 commits that reference this issue on May 1, 2021

    buffer: implement btoa and atob

    bf2d9f2

    test: app atob web platform tests

    5c60087
  24. Tofandel commented on Jun 19, 2021

    @Tofandel
    Tofandel
    on Jun 19, 2021
    Contributor
    More actions

    It's weird, so most people were against it but it landed anyway under the radar..

  25. jasnell commented on Jun 19, 2021

    @jasnell
    jasnell
    on Jun 19, 2021
    Member
    More actions

    @Tofandel ... there is no "under the radar" here. All changes go through the same review and approval process before landing, and all discussions/reviews are public.

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

    feature requestIssues requesting new Node.js features.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.