Acts as a proxy for decompressing and compressing data streams between objects.
Use the CompressedStream class to compress and decompress data on the fly without the need for a temporary storage area. The default compression algorithm is DEFLATE with gzip header data. It is compatible with common command-line tools such as gzip.
To decompress data, set the Input field with a source object that supports the Read() action, such as a File. Repeatedly reading from the CompressedStream will automatically handle the decompression process. If the decompressed size of the incoming data is defined in the source header, it will be reflected in the Size field.
To compress data, set the Output field with a source object that supports the Write() action, such as a File. Repeatedly writing to the CompressedStream with raw data will automatically handle the compression process for you. Once all of the data has been written, call the Write() action with a null empty Buffer to finalise the stream. In Tiri, call acWrite(nil).
The CompressedStream class consists of the following fields:
Access | Name | Type | Comment | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Format | CF | The format of the compressed stream. The default is GZIP. | |||||||||
| |||||||||||
| Input | OBJECTPTR | An input object that will supply data for decompression. | |||||||||
To create a stream that decompresses data from a compressed source, set the Input field with a reference to an object that will provide the source data. It is most common for the source object to be a File type, however any class that supports the Read() action is permitted. The source object must be in a readable state. The Input field is mutually exclusive to the Output field. | |||||||||||
| Output | OBJECTPTR | A target object that will receive data compressed by the stream. | |||||||||
To create a stream that compresses data to a target object, set the Output field with an object reference. It is most common for the target object to be a File type, however any class that supports the Write() action is permitted. The target object must be in a writeable state. The Output field is mutually exclusive to the Input field. | |||||||||||
| Size | INT64 | The uncompressed size of the input source, if known. | |||||||||
The Size field will reflect the uncompressed size of the input source, if this can be determined from the header. In the case of GZIP decompression, the size will not be known until the parser has consumed the header. This means that at least one call to the Read() action is required before the Size is known. If the size is unknown, a value of | |||||||||||
| TotalOutput | INT64 | A live counter of total bytes that have been output by the stream. | |||||||||
The following actions are currently supported:
| Read | Decompress data from the input stream and write it to the supplied buffer. | |||||||
|---|---|---|---|---|---|---|---|---|
ERR acRead(*Object, std::span<int8_t> Buffer, INT *Result)
| ||||||||
| Reset | Reset the state of the stream. | |||||||
| Seek | For use in decompressing streams only. Seeks to a position within the stream. | |||||||
ERR acSeek(*Object, DOUBLE Offset, INT Position)
| ||||||||
| Write | Compress raw data in a buffer and write it to the Output object. | |||||||
ERR acWrite(*Object, std::span<const int8_t> Buffer, INT *Result)
| ||||||||
Compression stream formats
| Name | Description |
|---|---|
| CF::DEFLATE | The 'deflate' format |
| CF::GZIP | The 'gzip' format |
| CF::ZLIB | The 'zlib' format |