Module

Data.String.Base64

#atob

atob :: String -> Either Error String

Decode a Base64-encoded String via the native atob function. Returns an Error for malformed input strings.

Example:

atob "UHVyZVNjcmlwdCByb2NrcyE="
Right "PureScript rocks!"

atob "∀"
-- ✗ Invalid input string

#btoa

btoa :: String -> Either Error String

Create a Base64-encoded ASCII String from a String. Each character in the input string is treated as one byte of binary data, hence this function returns an Error if a character's code point is outside the range 0x00 .. 0xFF.

Example:

btoa "PureScript rocks!"
-- Right "UHVyZVNjcmlwdCByb2NrcyE="

btoa "∀"
-- ✗ Invalid input string

#decode

decode :: String -> Either Error String

Decode a Base64-encoded String. This function handles both normal (RFC 4648) and URL-safe input strings. Returns an Error for invalid input strings.

Example:

decode "5p+/44GP44G444Gw6ZCY44GM6bO044KL44Gq44KK5rOV6ZqG5a+6"
-- Right "柿くへば鐘が鳴るなり法隆寺"

decode "5p-_44GP44G444Gw6ZCY44GM6bO044KL44Gq44KK5rOV6ZqG5a-6"
-- Right "柿くへば鐘が鳴るなり法隆寺"

decode "∀"
-- ✗ Invalid input string

#encode

encode :: String -> String

Encode a String to its (RFC 4648) Base64 representation.

Example:

encode "柿くへば鐘が鳴るなり法隆寺"
-- "5p+/44GP44G444Gw6ZCY44GM6bO044KL44Gq44KK5rOV6ZqG5a+6"

#encodeUrl

encodeUrl :: String -> String

Encode a String to a URL-safe Base64 representation.

Example:

encodeUrl "柿くへば鐘が鳴るなり法隆寺"
-- "5p-_44GP44G444Gw6ZCY44GM6bO044KL44Gq44KK5rOV6ZqG5a-6"

Modules