v140 · javascript

Uint8Array to/from base64 and hex

base64 is a common way to represent arbitrary binary data as ASCII. JavaScript has Uint8Arrays to work with binary data, but no built-in mechanism to encode that data as base64, nor to take base64'd data and produce a corresponding Uint8Arrays. This is a proposal to fix that. It also adds methods for converting between hex strings and Uint8Arrays.

concepts

  1. Uint8Array <-> Base64/Hex

    First-class base64 and hex methods on Uint8Array. Stop importing yet another encoder; the platform owns it now.

  2. Credential Roundtrip

    WebAuthn-style challenge flow: generate, encode to base64url + hex, decode, equality check. Includes a 100k-encode microbenchmark vs. the legacy btoa path.

  3. Streaming Decoder

    Decode a base64 stream chunk by chunk using setFromBase64's read/written counters and lastChunkHandling. Shows how a quadruplet that straddles a chunk boundary gets carried over.

  4. Alphabet Explorer

    Side-by-side encoder for the standard alphabet vs. base64url, with padding toggle and a one-click roundtrip. Highlights the URL-unsafe characters the URL alphabet replaces.

  5. Hex Inspector

    Paste any hex string, see it rendered as a coloured byte grid with ASCII preview, hash input with WebCrypto and watch the digest fall out of a single toHex() call.

why it shipped

base64 is a common way to represent arbitrary binary data as ASCII. JavaScript has Uint8Arrays to work with binary data, but no built-in mechanism to encode that data as base64, nor to take base64'd data and produce a corresponding Uint8Arrays. This is a proposal to fix that. It also adds methods for converting between hex strings and Uint8Arrays.

references