A NEW TODAY IS DAWNING!

Tutorial: Encode / Decode using base64


Introduction

The following provides details on using the base64 encode and decode features available as of 8.03.00.29.


Extension Package

As the encode and decode commands are provided through INTERNAL commands, you should use the BuildProfessional Extensions package that provide wrapper functions for encode / decode.

To install the Extensions package, use Tools / Import Component Package from the xdev Developer.

Note. The extension package uses "bpext" name prefix on all its components. Components using this prefix will be deleted prior to applying the package.


Base 64 Encoding

Base64 is a commonly used standard to represent binary data in ascii format. It does this by reading the binary stream and representing them as printable ascii characters. For formatting purposes it adds newline characters every 76 characters. The standard is most widely used to encode binary attachments in common e-mail programs. The encoded representation of binary data therefore looks something like this:

Na/dNa/do9bly+Xr2Ons2Ons2Ons2Ons2Ons2Ons2Ons2Ons2Ons2Ons2Ons2OnsNa/dn9nsF6XW
AZnMKqnSYLzbldHjvuDp2Ons2Ons2Ons2Ons2Ons2Ons2Ons2OnsNa/decnmoOb/d9z/W8zyPrzm
EZy5AZnMHKPRUrjZldHj2Ons2Ons2Ons2Ons2OnsNa/dUbzmyPT/g+j/g+j/g+j/CnARKY5RY9Hm
TsbsNbXey+Xr2Ons2Ons2Ons2OnsNa/dV8Dqwer1jPL/jPL/jPL/R6yBG4wnG4Exe+Dved/1iMvh
2Ons2Ons2Ons2OnsNa/dg9T8ccbirP//mf//mf//huzfH5QvQMVgLpNhqfL/Tr3e2Ons2Ons2Ons


Using Extension Functions

The extension functions make use of buffers to perform the encoding or decoding.


Examples:

NOTE Encode a text string and write the result to a file.
TEXT *BUFFER "raw"
TEXT *STRING "raw" "This is a test"
VISIT bpextEncode "raw" "encoded"
TEXT *WRITE *FILE= "text.txt" "encoded"
TEXT *RELEASE "raw" "encoded"

NOTE Load binary data from a file:
TEXT *LOAD "bin" "c:\buildpro\bin\logic.exe"
NOTE Encode it:
VISIT bpextEncode "bin" "text"
NOTE Insert into an XML document:
XML *MODIFY "mysubset" *ELEMENT= "/FileData" *BUFFER("text")
TEXT *RELEASE "bin" "text"

NOTE Read encoded contents from an XML subset, decode it and write to file:
TEXT *BUFFER "text"
XML *READ "mysubset" *ELEMENT= "/FileData" *BUFFER("text")
VISIT bpextDecode "text" "bin"
TEXT *WRITE *FILE= "test.exe" "bin"
TEXT *RELEASE "bin" "text"