Skip to main content
import * as Base64 from 'voltaire-effect/primitives/Base64'
import * as S from 'effect/Schema'
import { Effect } from 'effect'

const encoded = S.decodeSync(Base64.Schema)('SGVsbG8gV29ybGQ=')

Schemas

Base64.Schema — Standard Base64 validation and parsing.
S.decodeSync(Base64.Schema)('SGVsbG8gV29ybGQ=')
Base64.UrlSchema — URL-safe Base64 (uses - and _ instead of + and /).
S.decodeSync(Base64.UrlSchema)('SGVsbG8tV29ybGQ_')

Constructors (Effect-wrapped)

const b64 = await Effect.runPromise(Base64.from('SGVsbG8='))
const urlSafe = await Effect.runPromise(Base64.fromUrlSafe('SGVsbG8='))

Encoding (Pure)

Base64.encode(bytes)           // BrandedBase64
Base64.encodeString(str)       // BrandedBase64
Base64.encodeUrlSafe(bytes)    // BrandedBase64Url
Base64.encodeStringUrlSafe(str) // BrandedBase64Url

Decoding (Effect-wrapped)

const bytes = await Effect.runPromise(Base64.decode('SGVsbG8='))
const str = await Effect.runPromise(Base64.decodeToString('SGVsbG8='))
const urlBytes = await Effect.runPromise(Base64.decodeUrlSafe('SGVsbG8='))
const urlStr = await Effect.runPromise(Base64.decodeUrlSafeToString('SGVsbG8='))

Conversion (Pure)

Base64.toBytes(b64)        // Uint8Array
Base64.toBytesUrlSafe(b64) // Uint8Array
Base64.toString(b64)       // string
Base64.toStringUrlSafe(b64) // string
Base64.toBase64(bytes)     // BrandedBase64
Base64.toBase64Url(bytes)  // BrandedBase64Url

Validation (Pure)

Base64.isValid('SGVsbG8=')        // true
Base64.isValidUrlSafe('SGVsbG8=') // true

Size Calculation (Pure)

Base64.calcEncodedSize(5)         // 8
Base64.calcDecodedSize('SGVsbG8=') // 5

Types

type BrandedBase64 = Base64.BrandedBase64
type BrandedBase64Url = Base64.BrandedBase64Url

Errors

Throws ParseError on invalid Base64 input.