This package can convert bytes to Base64 strings and vice versa.
fromBytes : Bytes -> Maybe String
Convert bytes to a Base64 string.
If you want more control over the process, you should use decoder
.
This function should never return Nothing
, but it uses
Bytes.Decode.decode
,
which returns a Maybe String
.
fromString : String -> Maybe String
Encode a string into a Base64 string.
This function is a wrapper around fromBytes
.
Similarly, it should never return Nothing
, but alas, Bytes.Decode.decode
,
which fromBytes
uses, returns a Maybe String
.
toBytes : String -> Maybe Bytes
Convert a Base64 string to bytes.
If you want more control over the process, you should use encoder
.
This function fails (returns Nothing
) if you give it an invalid Base64 sequence.
toString : String -> Maybe String
Decode a Base64 string into a string.
This function is a wrapper around toBytes
.
It will fail (return Nothing
) if you give it an invalid Base64 sequence.
Slightly lower level functions.
fromBytes
and toBytes
functions
are pretty much wrappers around these functions.
encoder : String -> Maybe Bytes.Encode.Encoder
encoder
returns a bytes encoder. It fails if the string that is passed
to it is not a valid Base64 sequence.
It's used in toBytes
:
toBytes : String -> Maybe Bytes
toBytes string =
Maybe.map Bytes.Encode.encode (encoder string)
decoder : Basics.Int -> Bytes.Decode.Decoder String
decoder width
is a bytes decoder that will convert width
bytes into a
Base64 string.
It's used in fromBytes
:
fromBytes : Bytes -> Maybe String
fromBytes bytes =
Bytes.Decode.decode (decoder (Bytes.width bytes)) bytes