The procedure EncodeASCII85 encodes the data of the stream InStream into a base85 encoded data stream OutStream. Base85 encoded data is primarily used in PDF and PostScript files. The encoding process starts at the current position of the input stream InStream and writes the resulting data to the current position of Outstream (overwriting all data after the current position). The parameter InsertCRLF controls whether the output stream is structured by <CR> (ASCII 13) and <LF> (ASCII 10) characters. If InsertCRLF is TRUE the encoded data stream is written as lines of 60 characters each.
Following is a detailed description of ASCII85 encoding [1]:
ASCII base85 encoding produces five
ASCII printing characters from every four bytes of binary data. Each group of
four binary bytes (b1 b2 b3 b4) is converted to a group of five encoded
characters (c1 c2 c3 c4 c5) using the relation
b1*256^{3} + b2*256^{2} + b3*256^{1} + b4 =
c1*85^{4} + c2*85^{3} + c3*85^{2} +
c4*85^{1} + c5
The five
digits of the encoded base85 number are converted to printable ASCII characters
by adding 33 (the ASCII code for !) to each. The
resulting data contains only printable ASCII characters with codes in the range
33 (!) to 117 (u). Two special cases occur during encoding. First, if
all five encoded digits are zero, they are represented by the character code 122
(z), instead of by a series of five exclamation
points (!!!!!). In addition, if the length of
the binary data to be encoded is not a multiple of four bytes, the last partial
4tuple is used to produce a last, partial output 5tuple. Given n (1, 2, or 3)
bytes of binary data, the encoding first appends 4 n zero bytes to make a
complete 4tuple. This 4tuple is encoded in the usual way, but without applying
the special z case. Finally, only the first n + 1 characters of the resulting
5tuple are written out. Those characters are immediately followed by the EOD
marker, which is the twocharacter sequence ~>.
[1] Adobe Systems Inc.: "Portable Document Format Reference Manual", Version 1.3, March 1999
