Compression
The CBFS Storage filesystem stores data in a vault as a series of one or more pages. To reduce space usage, CBFS Storage can compress files and alternate streams with an application-selected compression algorithm using the following mechanism, which is optimized to provide optimal performance for both sequential and random data access:
- A block of data composed of a specific number of pages is passed to the compression routine, which attempts to compress the data.
- If the compressed data can be stored using fewer pages than before, it is written to the vault. Otherwise, the original (uncompressed) data is written instead.
- Steps 1 and 2 are repeated until all of the data pages associated with the file or alternate stream have been processed.
Compressing Files and Alternate Streams
To specify a default compression mode for files and alternate streams, applications can set the DefaultFileCompression property (and, if applicable, the DefaultFileCompressionLevel configuration setting). Additionally, the following methods allow applications to set a file or alternate stream's compression mode explicitly:
- OpenFileEx (when creating a new file or alternate stream)
- SetFileCompression
- CopyToVault
Using Custom Compression
CBFS Storage includes built-in support for zlib and RLE data compression. However, applications can also choose to provide their own custom compression implementation using the DataCompress and DataDecompress events.
Supported Compression Modes
CBFS Storage supports the following compression modes:
CBFSSTORAGE_CM_NONE | 0 | Don't use compression. |
CBFSSTORAGE_CM_DEFAULT | 1 | Use default compression (zlib). |
CBFSSTORAGE_CM_CUSTOM | 2 | Use event-based custom compression.
Compression level is not used. |
CBFSSTORAGE_CM_ZLIB | 3 | Use zlib compression.
Valid compression levels are 1-9. |
CBFSSTORAGE_CM_RLE | 4 | Use RLE compression.
Compression level is not used. |