Please enable JavaScript to view this site.

A-Shell Reference

Updated October 2017

xcall B64ENC, infile, och, status {,flag}

xcall B64ENC, indata, outdata, status, flag

B64ENC provides Base 64 (aka MIME) encoding and decoding. The first format encodes a file, writing the encoded output to another file, while the second format may be used for encoding and decoding of memory buffers.  

Parameters

infile  (String)  [in]

Specification of file to encode in AMOS or native format

och  (Num) [in]

Channel of a file, previously opened for output, to which the encoded version of the input file will be written. The file remains open on return.

status (Signed Num)  [out]

On return, will be set to the number of bytes written, or <0 for errors

Value

Description

>=0

Number of bytes written

-1

infile not found

-2

unable to open infile

-3

och not valid (not open for OUTPUT)

-4

file error during input of file

-5

error during output

-6

outdata too small to hold encrypted output

 

indata (X or String)  [in]

Variable containing data to encode or decode

outdata  (X or String)  [out]

Variable containing encoded or decoded version of indata.  Since encoded data is 4/3 larger than raw data, the determination of whether the operation is encode or decode is based on the relative sizes of the indata and outdata parameters. If the physical variable outdata is larger than indata, then the operation will be to encode; otherwise it will be to decode. If using a dynamic string (S,0), you'll need to initialize it so that it's effective size is greater than or less than the size of the indata string, depending on whether you are encoding or decoding. See the BASIC string function FILL$() for a convenient way to do this.

flag (Num)  [in]

If not specified, or set to 0, the format is assumed to be that given in the first syntax line above (encode a file).  Otherwise, to encode a memory buffer, flag must be set to the number of bytes in indata to encode.  (Since raw data may contain binary values, including 0, we can not use the normal string length method of determining the logical size of the input data.)  To decode data, flag should be set to 1.

Comments

Base 64 encoded data uses only 64 distinct bytes (all printable) for representation, which is often convenient for including binary data within formats that are otherwise string-oriented (such as email). Because only six bits are used in each byte of the encoded representation, the encoded version of the data is 4/3 larger than the raw data. The raw data does not have to be a multiple of three.

When using the first forma, to encode to an output file, the base64 data is split into lines of 72 characters. The decoding routine, however, expects the base64 data in the indata parameter to be a single linear string with no line breaks.

See the module fnb64.sbi in SOSLIB:[907,10] for a collection of convenience function wrappers for B64ENC.

Also, for a more symmetrical implementation of base64 encoding/decoding, including other encoding formats such as hex, see CRYPTO.