STDLIB

Reference Manual

Version 3.4.5.1

Table of Contents

base64

Module

base64

Module Summary

Provides base64 encode and decode, see RFC 2045.

Description

Provides base64 encode and decode, see RFC 2045.

Data Types

base64_alphabet() =
    65..90 | 97..122 | 48..57 | 43 | 47 | 45 | 95 | 61

Base 64 Encoding alphabet, see RFC 4648.

base64_mode() = standard | urlsafe

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

Base 64 encoded string.

base64_binary() = binary()

Base 64 encoded binary.

byte_string() = [byte()]

Arbitrary sequences of octets.

Exports

decode(Base64) -> Data
decode_to_string(Base64) -> DataString
mime_decode(Base64) -> Data
mime_decode_to_string(Base64) -> DataString

Types

Data = 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.

decode(Base64, Mode) -> Data
decode_to_string(Base64, Mode) -> DataString
mime_decode(Base64, Mode) -> Data
mime_decode_to_string(Base64, Mode) -> DataString

Types

Data = binary()
DataString = byte_string()

Decodes a base64 string encoded using the alphabet indicated by the Mode parameter 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 parameter can be one of the following:

standard
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.

encode(Data) -> Base64
encode_to_string(Data) -> Base64String

Types

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.

encode(Data, Mode) -> Base64
encode_to_string(Data, Mode) -> Base64String

Types

Data = byte_string() | binary()
Base64String = base64_string()

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

The Mode parameter can be one of the following:

standard
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.