Base64 (.b64)

Background & Context

    • Base64 binary-to-text encoding.
    • Encodes binary data as a sequence of printable ASCII characters.
    • Commonly used for the transfer of binary content by email.
    • The Base64 encoding is described in internet standard recommendations RFC 1421 and 2045.
    • ASCII format.
    • Uses the 52 uppercase and lowercase letters of the Roman alphabet, the numerals 0 to 9, and the characters "+" and "/" to form a positional numeral system using a base of 64.
    • The "=" character is used for padding Base64-encoded data.

Import & Export

  • Import["file.ext.b64"] imports a Base64-encoded .ext file.
  • Export["file.ext.b64",expr] exports an expression to a Base64-encoded .ext file.
  • Import["file.b64"] decodes a Base64-encoded file and imports its contents as an expression, automatically inferring the format from the file contents.
  • The import format can be given explicitly with Import["file",{"Base64","format"}].
  • Import["file.ext.b64",elem] imports the specified element from a Base64-encoded .ext file.
  • Import["file.ext.b64",{elem,suba,subb,}] imports a subelement.
  • Import["file.ext.b64",{{elem1,elem2,}}] imports multiple elements.
  • The import format and file encoding can be explicitly specified with Import["file",{"Base64","format",elems1,elems2,}].
  • Export["file.ext.b64",expr,elem] creates a Base64-encoded .ext file by treating expr as specifying element elem.
  • Export["file.ext.b64",{expr1,expr2,},{{elem1,elem2,}}] treats each expri as specifying the corresponding elemi.
  • Export["file.ext.b64",expr,opt1->val1,] exports expr with the specified option elements taken to have the specified values.
  • Export["file.ext.b64",{elem1->expr1,elem2->expr2,},"Rules"] uses rules to specify the elements to be exported.
  • The export format and file encoding can be explicitly specified with Export["file",exprs,{"Base64","format",elems}].
  • See the following reference pages for full general information:
  • Import, Exportimport from or export to a file
    CloudImport, CloudExportimport from or export to a cloud object
    ImportString, ExportStringimport from or export to a string
    ImportByteArray, ExportByteArrayimport from or export to a byte array

Import Elements

  • General Import elements:
  • "Elements" list of elements and options available in this file
    "Summary"summary of the file
    "Rules"list of rules for all available elements


open allclose all

Basic Examples  (2)

Convert a string to Base64 encoding:

The format "Base64" must be specified when reading Base64-encoded data:

Arbitrary expressions can be encoded as Base64:

Scope  (1)

Characters with code points above 255 are converted to their long names: