View Source base64 (stdlib v6.0)

Provides base64 encode and decode, see RFC 2045.

Provides base64 encode and decode, see RFC 2045.

Summary

Types

Base 64 Encoding alphabet, see RFC 4648.

Base 64 encoded binary.

Selector for the Base 64 Encoding alphabet used for encoding and decoding. See RFC 4648 Sections 4 and 5.

Base 64 encoded string.

Arbitrary sequences of octets.

Customises the behaviour of the encode and decode functions. Default value if omitted entirely or partially is #{mode => standard, padding => true}.

Functions

Encodes a plain ASCII string into base64 using the standard alphabet according to RFC 4648 Section 4. The result is 33% larger than the data.

Encodes a plain ASCII string into base64 using the alphabet indicated by the mode option. The result is 33% larger than the data.

Decodes a base64 string encoded using the standard alphabet according to RFC 4648 Section 4 to plain ASCII.

Decodes a base64 string encoded using the alphabet indicated by the mode option to plain ASCII.

Types

Link to this type

base64_alphabet()

View Source (not exported)
-type base64_alphabet() :: $A..$Z | $a..$z | $0..$9 | $+ | $/ | $- | $_ | $=.

Base 64 Encoding alphabet, see RFC 4648.

Link to this type

base64_binary()

View Source (not exported)
-type base64_binary() :: binary().

Base 64 encoded binary.

Link to this type

base64_mode()

View Source (not exported)
-type base64_mode() :: standard | urlsafe.

Selector for the Base 64 Encoding alphabet used for encoding and decoding. See RFC 4648 Sections 4 and 5.

Link to this type

base64_string()

View Source (not exported)
-type base64_string() :: [base64_alphabet()].

Base 64 encoded string.

Link to this type

byte_string()

View Source (not exported)
-type byte_string() :: [byte()].

Arbitrary sequences of octets.

Link to this type

options()

View Source (not exported)
-type options() :: #{padding => boolean(), mode => base64_mode()}.

Customises the behaviour of the encode and decode functions. Default value if omitted entirely or partially is #{mode => standard, padding => true}.

Functions

-spec decode(Base64) -> Data when Base64 :: base64_string() | base64_binary(), Data :: binary().

Equivalent to mime_decode_to_string/1

Link to this function

decode(Base64, Options)

View Source (since OTP 26.0)
-spec decode(Base64, Options) -> Data
          when Base64 :: base64_string() | base64_binary(), Options :: options(), Data :: binary().

Equivalent to mime_decode_to_string/2

Link to this function

decode_to_string(Base64)

View Source
-spec decode_to_string(Base64) -> DataString
                    when Base64 :: base64_string() | base64_binary(), DataString :: byte_string().

Equivalent to mime_decode_to_string/1

Link to this function

decode_to_string(Base64, Options)

View Source (since OTP 26.0)
-spec decode_to_string(Base64, Options) -> DataString
                    when
                        Base64 :: base64_string() | base64_binary(),
                        Options :: options(),
                        DataString :: byte_string().

Equivalent to mime_decode_to_string/2

-spec encode(Data) -> Base64 when Data :: byte_string() | binary(), Base64 :: base64_binary().

Equivalent to encode_to_string/1

Link to this function

encode(Data, Options)

View Source (since OTP 26.0)
-spec encode(Data, Options) -> Base64
          when Data :: byte_string() | binary(), Options :: options(), Base64 :: base64_binary().

Equivalent to encode_to_string/2

-spec encode_to_string(Data) -> Base64String
                    when Data :: byte_string() | binary(), Base64String :: base64_string().

Encodes a plain ASCII string into base64 using the standard alphabet according to RFC 4648 Section 4. The result is 33% larger than the data.

Always appends correct number of = padding characters to the encoded string.

Link to this function

encode_to_string(Data, Options)

View Source (since OTP 26.0)
-spec encode_to_string(Data, Options) -> Base64String
                    when
                        Data :: byte_string() | binary(),
                        Options :: options(),
                        Base64String :: base64_string().

Encodes a plain ASCII string into base64 using the alphabet indicated by the mode option. The result is 33% larger than the data.

The mode option can be one of the following:

  • standard - Default. Encode the given string using the standard base64 alphabet according to RFC 4648 Section 4.

  • urlsafe - Encode the given string using the alternative "URL and Filename safe" base64 alphabet according to RFC 4648 Section 5.

The padding option can be one of the following:

  • true - Default. Appends correct number of = padding characters to the encoded string.

  • false - Skips appending = padding characters to the encoded string.

-spec mime_decode(Base64) -> Data when Base64 :: base64_string() | base64_binary(), Data :: binary().

Equivalent to mime_decode_to_string/1

Link to this function

mime_decode(Base64, Options)

View Source (since OTP 26.0)
-spec mime_decode(Base64, Options) -> Data
               when
                   Base64 :: base64_string() | base64_binary(),
                   Options :: options(),
                   Data :: binary().

Equivalent to mime_decode_to_string/2

Link to this function

mime_decode_to_string(Base64)

View Source
-spec mime_decode_to_string(Base64) -> DataString
                         when
                             Base64 :: base64_string() | base64_binary(),
                             DataString :: byte_string().

Decodes a base64 string encoded using the standard alphabet according to RFC 4648 Section 4 to plain ASCII.

mime_decode/1 and mime_decode_to_string/1 strip away illegal characters, while decode/1 and decode_to_string/1 only strip away whitespace characters.

Checks the correct number of = padding characters at the end of the encoded string.

Link to this function

mime_decode_to_string(Base64, Options)

View Source (since OTP 26.0)
-spec mime_decode_to_string(Base64, Options) -> DataString
                         when
                             Base64 :: base64_string() | base64_binary(),
                             Options :: options(),
                             DataString :: byte_string().

Decodes a base64 string encoded using the alphabet indicated by the mode option to plain ASCII.

mime_decode/2 and mime_decode_to_string/2 strip away illegal characters, while decode/2 and decode_to_string/2 only strip away whitespace characters.

The mode option can be one of the following:

  • standard - Default. Decode the given string using the standard base64 alphabet according to RFC 4648 Section 4, that is "+" and "/" are representing bytes 62 and 63 respectively, while "-" and "_" are illegal characters.

  • urlsafe - Decode the given string using the alternative "URL and Filename safe" base64 alphabet according to RFC 4648 Section 5, that is "-" and "_" are representing bytes 62 and 63 respectively, while "+" and "/" are illegal characters.

The padding option can be one of the following:

  • true - Default. Checks the correct number of = padding characters at the end of the encoded string.

  • false - Accepts an encoded string with missing = padding characters at the end.