Hyperlinkv0.8.0-beta.28

Encoding

Encoding.decodeBase64Stringconsteffect/Encoding.ts:257
(str: string): Result.Result<string, EncodingError>

Decodes a base64 (RFC4648) string into a UTF-8 string safely.

When to use

Use to decode a standard padded Base64 string into UTF-8 text without throwing on invalid input.

Details

Returns Result.succeed with the decoded text when decoding succeeds, or Result.fail with an EncodingError when the input is not valid base64.

Example (Decoding Base64 strings)

import { Encoding, Result } from "effect"

const result = Encoding.decodeBase64String("aGVsbG8=")
if (Result.isSuccess(result)) {
  console.log(result.success) // "hello"
}
decoding
export const decodeBase64String = (str: string) => Result.map(decodeBase64(str), (_) => decoder.decode(_))
Referenced by 1 symbols