Compression Settings
RadZipLibrary allows you to compress and decompress data in your application. There are different settings that you can use for compression. This article discusses all of them.
Deflate Settings
Deflate settings compress data using a combination of the LZ77 algorithm and Huffman coding.
You can find more information on the Deflate data compression algorithm in Wikipedia.
The DeflateSettings class exposes the following configurable parameters:
-
CompressionLevel—Property of typeCompressionLevelthat represents the level of compression of the algorithm. -
HeaderType—Represents the compression stream header type. The possible values areNoneandZLib.
Example 1: Create DeflateSettings
DeflateSettings compressionSettings = new DeflateSettings();
compressionSettings.CompressionLevel = CompressionLevel.Best;
compressionSettings.HeaderType = CompressedStreamHeader.ZLib;
LZMA Settings
LZMA settings compress data using the Lempel-Ziv-Markov chain algorithm (LZMA).
You can read more about LZMA in Wikipedia.
The configurable parameters of the LzmaSettings class are as follows:
-
DictionarySize—The size of the used dictionary. Allowed values are in the range [0–27] and the default value is 23 (8 MB). -
PositionStateBits—The number of position state bits. Allowed values are in the range [0–4]. The default value is 2. -
LiteralContextBits—The number of literal context bits. Allowed values are in the range [0–4]. The default value is 3. -
LiteralPositionBits—The number of literal position bits. Allowed values are in the range [0–4]. The default value is 3. -
FastBytes—The number of fast bytes. Allowed values are in the range [5–273]. The default value is 32. -
MatchFinderType—The type of the match finder. Allowed values are BT2 (match finder that uses two bytes for the hash) and BT4 (uses four bytes for the hash).
Example 2: Create LzmaSettings
LzmaSettings compressionSettings = new LzmaSettings();
compressionSettings.DictionarySize = 23;
compressionSettings.FastBytes = 32;
compressionSettings.LiteralContextBits = 3;
compressionSettings.LiteralPositionBits = 3;
compressionSettings.MatchFinderType = LzmaMatchFinderType.BT4;
compressionSettings.PositionStateBits = 2;
Store Settings
Store settings store the data without applying any compression.
Example 3: Create StoreSettings
StoreSettings compressionSettings = new StoreSettings();