JavaScript global method: base64Decode

Converts base 64 string data to its original format.

Syntax

base64Decode( data );

Arguments

The following arguments are valid for this function:

Argument Data type Required Description
data Binary Yes This argument contains the data you want the script to decode to its original format.

Return values

A binary or string object containing the original data.

Description

This method converts data in base 64 string format to its original format.

Example

This example does the following:

  • Reads the contents of a binary file
  • Converts the file to a base 64 string format
  • Writes the base 64 string data to a local file
  • Prints the number of bytes written to the local file system
  • Reads the contents of a base 64 string format file
  • Converts the data into a binary file
  • Writes the binary data to a local file
  • Prints the number of bytes written to the local file system

This example requires the following sample data:

  • A binary file on the local file system (for example, an image file)
var source = readFile( "C:\\header_left.gif", "b" );
var encode = base64Encode( source );
var encodedFile = writeFile( "C:\\base64EncodedImage.txt", "b", encode );
print( "Wrote " + encodedFile + " bytes to C:\\base64EncodedImage.txt" );
source = readFile( "C:\\base64EncodedImage.txt", "t" );
var decode = base64Decode( source );
var decodedFile = writeFile( "C:\\newImage.gif", "b", decode );
print( "Wrote " + decodedFile + " bytes to C:\\newImage.gif" );