Base 64 Conversion (B64) |
![]() ![]() ![]() |
The base64 conversion code translates data to or from a format widely used for transmission over the internet.
The full format of this conversion code is
B64
Used with OCONV() for output conversion, this operation converts data to base64 format. The data is returned as a continuous sequence of encoded characters. In common use, this data would then be divided into lines of manageable length, typically 72 characters. This can be achieved with the FOLD() function.
Used with ICONV() for input conversion, this operation converts base64 data back to its original form. Newlines and other filler characters are ignored.
Example
OPENPATH '$HOLD' TO FVAR ELSE STOP 'Cannot open file' MARK.MAPPING FVAR, OFF READ TEXT FROM FVAR, 'REPORT.PDF' ELSE STOP 'Cannot read data' MARK.MAPPING FVAR, ON B64 = OCONV(TEXT, 'B64') WRITE FOLD(B64, 72) TO FVAR, 'REPORT.B64'
The above program opens the $HOLD file. It then suppresses the normal directory file translation of newlines to field marks because the item to be read contains binary data (a PDF document). Having read this record, mark translation is re-enabled. The B64 conversion is used to translate the PDF to its base64 encoded equivalent. Finally, the FOLD() function is used to wrap the encoded data into 72 character lines. |