Skip to content

Base64.fromBytes

Encodes a Bytes.Bytes to a Base64-encoded string (with optional padding and/or URL-safe characters).

Imports

Named
import { Base64 } from 'ox'

Examples

import { Base64, Bytes } from 'ox'
 
const value = Base64.fromBytes(Bytes.fromString('hello world'))
'aGVsbG8gd29ybGQ='

No Padding

Turn off padding of encoded data with the pad option:

import { Base64, Bytes } from 'ox'
 
const value = Base64.fromBytes(Bytes.fromString('hello world'), { pad: false })
'aGVsbG8gd29ybGQ'

URL-safe Encoding

Turn on URL-safe encoding (Base64 URL) with the url option:

import { Base64, Bytes } from 'ox'
 
const value = Base64.fromBytes(Bytes.fromString('hello wod'), { url: true })
'aGVsbG8gd29_77-9ZA=='

Definition

function fromBytes(
  value: Bytes.Bytes,
  options?: fromBytes.Options,
): string

Source: src/Base64.ts

Parameters

value

  • Type: Bytes.Bytes

The byte array to encode.

options

  • Type: fromBytes.Options
  • Optional

Encoding options.

options.pad

  • Type: boolean
  • Optional

Whether to pad the Base64 encoded string.

options.url

  • Type: boolean
  • Optional

Whether to Base64 encode with URL safe characters.

Return Type

The Base64 encoded string.

string