ASCII 85 or Base 85 encoding

The ascii85 provides an ASCII 85 or base 85 decoding algorithm. It is class and stream based: the stream can be used to decode any stream with ASCII85 encoded data.

Currently, no ASCII85 encoder stream is available.

It's usage and purpose is similar to the IDEA or base64 units.

Encoder state enumeration TASCII85State is for internal use, it contains the current state of the decoder. Initial state One encoded character in buffer. Two encoded characters in buffer. Three encoded characters in buffer. Four encoded characters in buffer. No encoded characters in buffer. Prefix processing Internal buffer class TASCII85RingBuffer is an internal buffer class: it maintains a memory buffer of 1Kb, for faster reading of the stream. It should not be necessary to instantiate an instance of this class, the decoder stream will create an instance of this class automatically. Number of bytes in buffer FillCount is the available amount of bytes in the buffer. Size of buffer Size is the total size of the memory buffer. This is currently hardcoded to 1024Kb. Write data to the internal buffer Write writes aSize bytes from aBuffer to the internal memory buffer. Only as much bytes are written as will fit in the buffer. Buffer to get data from Total amount of bytes to read from aBuffer Read data from the internal buffer Read will read aSize bytes from the internal buffer and writes them to aBuffer. If not enough bytes are available, only as much bytes as available will be written. The function returns the number of bytes transferred. Number of actually transferred bytes Buffer to write data to Number of bytes to transfer ASCII 85 decoder stream.

TASCII85DecoderStream is a read-only stream: it takes an input stream with ASCII 85 encoded data, and decodes the data as it is read. To this end, it overrides the TSTream.Read method.

The stream cannot be written to, trying to write to the stream will result in an exception.

Create new ASCII 85 decoder stream Create instantiates a new TASCII85DecoderStream instance, and sets aStream as the source stream. Source data Decode source byte Decode decodes a source byte, and transfers it to the buffer. It is an internal routine and should not be used directly. Byte to decode Close decoder Close closes the decoder mechanism: it checks if all data was read and performs a check to see whether all input data was consumed. If the input stream was invalid, an EConvertError exception is raised. Check if the state is correct ClosedP checks if the decoder state is one of ascInitial, ascNoEncodedChar, ascPrefix, and returns True if it is. State is one of ascInitial, ascNoEncodedChar or ascPrefix. Expect ~ character BExpectBoundary is True if a encoded data boundary is to be expected ("~>"). ClosedP Clean up instance Destroy closes the input stream using Close and cleans up the TASCII85DecoderStream instance from memory. In case the input stream was invalid, an exception may occur. Read data from stream

Read attempts to read aCount bytes from the stream and places them in aBuffer. It reads only as much data as is available. The actual number of read bytes is returned.

The read method reads as much data from the input stream as needed to get to aCount bytes, in general this will be aCount*5/4 bytes.

Actual number of bytes transferred to buffer. Buffer to transfer data to Number of bytes to transfer to buffer Set stream position Seek sets the stream position. It only allows to set the position to the current position of this file, and returns then the current position. All other arguments will result in an EReadError exception. In case the arguments are different from soCurrent and 0, an EReadError exception will be raised. new position in stream. Offset from current position (should be zero). Origin for seek operation (should be soCurrent). ASCII 85 encoding stream

TASCII85EncoderStream is the counterpart to the decoder stream: what TASCII85EncoderStream encodes, can be decoded by .

The encoder stream works using a destination stream: whatever data is written to the encoder stream is encoded and written to the destination stream. The stream must be passed on in the constructor.

Note that all encoded data is only written to the destination stream when the encoder stream is destroyed.

Create a new instance of TASCII85EncoderStream Create creates a new instance ofTASCII85EncoderStream. It stores ADest as the destination stream for the encoded data. The Width parameter indicates the width of the lines that are written by the encoder: after this amount of characters, a linefeed is put in the data stream. If ABoundary is True then a boundary delineator is written to the stream before and after the data. Width Boundary Is a boundary delineator written before and after the data Boundary indicates whether the stream will write a boundary delineator before and after the encoded data. It is passed to the constructor and cannot be changed. Width Create Width of the lines written to the data stream Width is the width of the lines of encoded data written to the stream. After Width lines, a line ending will be written to the stream. The value is passed to the constructor and cannot be changed afterwards. Boundary Create Write data encoded to the destination stream

Write encodes the aCount bytes of data in aBuffer and writes the encoded data to the destination stream.

Not all data is written immediatly to the destination stream. Only after the encoding stream is destroyed will the destination stream contain the full data.

Flushed the data to the output stream and cleans up the encoder instance. Destroy writes the data remaining in the internal buffer to the destination stream (possibly followed by a boundary delineator) and then destroys the encoder instance.