effect-io-ai

Package: effect
Module: Encoding

Encoding.decodeBase64Url

Decodes a URL-safe base64 string into bytes safely.

When to use

Use to decode padded or unpadded Base64Url text into bytes without throwing on invalid input.

Details

Returns Result.succeed with a Uint8Array when decoding succeeds, or Result.fail with an EncodingError when the input is not valid URL-safe base64. Both padded and unpadded URL-safe base64 forms are accepted when otherwise valid.

Example (Decoding URL-safe Base64 bytes)

import { Encoding, Result } from "effect"

const result = Encoding.decodeBase64Url("SGVsbG8_")
if (Result.isSuccess(result)) {
  console.log(Array.from(result.success)) // [72, 101, 108, 108, 111, 63]
}

Signature

declare const decodeBase64Url: (str: string) => Result.Result<Uint8Array, EncodingError>

Source

Since v2.0.0