Adobe ColdFusion 8

Binary data type and binary encoding

Binary data (also referred to as a binary object) is raw data, such as the contents of a GIF file or an executable program file. You do not normally use binary data directly, but you can use the cffile tag to read a binary file into a variable, typically for conversion to a string binary encoding before transmitting the file using e-mail.

A string binary encoding represents a binary value in a string format that can be transmitted over the web. ColdFusion supports three binary encoding formats:

Encoding

Format

Base64

Encodes the binary data in the lowest six bits of each byte. It ensures that binary data and non-ANSI character data can be transmitted using e-mail without corruption. The Base64 algorithm is specified by IETF RFC 2045, at www.ietf.org/rfc/rfc2045.txt.

Hex

Uses two characters in the range 0-9 and A-F represent the hexadecimal value of each byte; for example, 3A.

UU

Uses the UNIX UUencode algorithm to convert the data.

ColdFusion provides the following functions that convert among string data, binary data, and string encoded binary data:

Function

Description

BinaryDecode

Converts a string that contains encoded binary data to a binary object.

BinaryEncode

Converts binary data to an encoded string.

CharsetDecode

Converts a string to binary data in a specified character encoding.

CharsetEncode

Converts a binary object to a string in a specified character encoding.

ToBase64

Converts string and binary data to Base64 encoded data.

ToBinary

Converts Base64 encoded data to binary data. The BinaryDecode function provides a superset of the ToBase64 functionality.

ToString

Converts most simple data types to string data. It can convert numbers, date-time objects, and boolean values. (It converts date-time objects to ODBC timestamp strings.) Adobe recommends that you use the CharsetEncode function to convert binary data to a string in new applications.