Data Compression and Decompression
Data compression is useful because it helps to economize on resources, such as storage or transmission capacity. Audio, video and images are examples of bulky data which are often stored in a compressed format. Accessing the compressed data involves a process called decompression.
VA Smalltalk’s compression support is split into codecs and streams. Codecs are the actual algorithms that perform (de)compression of some block of data. Streams use codecs internally to provide an API for the user to repeatably push/pull (de)compressed data through the streams. In doing so, multiple calls to the codec may be happening, but this is invisible to the stream API user.
VA Smalltalk classes enable the programmer to compress and decompress data in-memory, files or even sockets. VA Smalltalk has support for Deflate/GZip/LZ4 compression. Additionally, there are implementations of Zip Archives (Zip64 support) from the filesystem or in-memory.
Each codec library has its own Application. The LZ4 codec implementation is in LZ4CompressionApp. The Brotli codec implementation is in BrotliCompressionApp. The ZStandard codec implementation is in ZstdCompressionApp. The Deflate and Gzip implementations are in MZZipUnzipApp.
The streaming code can be found in the EsCompressionStreamsApp. This provides a unified API for all compression streams, and this API is consistent with that of other streams in the system. Compression Streams are decorators that can wrap other In-Memory, File or Socket streams to give the desired (de)compression behavior transparently. Compression Streams are also very high-performance. They implement front and back buffers to give maximum performance for small reads and writes. They also have advanced handling of lookahead APIs (i.e. peek) which can be very difficult to implement on codec based streams. These streams collaborate with the classes found in the LZ4CompressionApp and MzZipUnzipApp applications.
The self-contained examples in this section illustrate how to
•Compress a string into a compressed stream
•Restore a string to its decompressed version from a compressed stream
•Make a round trip of compression and decompression
•Illustrate the more common workflow of decompression, data manipulation and compression with the .ZIP file format.
Last modified date: 04/09/2019