Module
Data.String.Base64
- Package
- purescript-b64
- Repository
- menelaos/purescript-b64
#btoa Source
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 Source
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