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 default_file_compression 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:
- open_file_ex (when creating a new file or alternate stream)
- set_file_compression
- copy_to_vault (CBVault class only)
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 on_data_compress and on_data_decompress 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. |
(Note: All API members discussed in this topic are available in both CBDrive, CBMemDrive, and CBVault, unless otherwise noted.)