libmspack Documentation


libmspack is a library which provides compressors and decompressors, archivers and dearchivers for Microsoft compression formats.

Formats supported

The following file formats are supported:

To determine the capabilities of the library, and the binary compatibility version of any particular compressor or decompressor, use the mspack_version() function. The UNIX library interface version is defined as the highest-versioned library component.

Getting started

The macro MSPACK_SYS_SELFTEST() should be used to ensure the library can be used. In particular, it checks if the caller is using 32-bit file I/O when the library is compiled for 64-bit file I/O and vice versa.

If compiled normally, the library includes basic file I/O and memory management functionality using the standard C library. This can be customised and replaced entirely by creating a mspack_system structure.

A compressor or decompressor for the required format must be instantiated before it can be used. Each construction function takes one parameter, which is either a pointer to a custom mspack_system structure, or NULL to use the default. The instantiation returned, if not NULL, contains function pointers (methods) to work with the given file format.

For compression:

For decompression:

Once finished working with a format, each kind of compressor/decompressor has its own specific destructor:

Destroying a compressor or decompressor does not destroy any objects, structures or handles that have been created using that compressor or decompressor. Ensure that everything created or opened is destroyed or closed before compressor/decompressor is itself destroyed.

Error codes

All compressors and decompressors use the same set of error codes. Most methods return an error code directly. For methods which do not return error codes directly, the error code can be obtained with the last_error() method.


libmspack methods are reentrant and multithreading-safe when each thread has its own compressor or decompressor.

You should not call multiple methods simultaneously on a single compressor or decompressor instance.

If this may happen, you can either use one compressor or decompressor per thread, or you can use your preferred lock, semaphore or mutex library to ensure no more than one method on a compressor/decompressor is called simultaneously. libmspack will not do this locking for you.

Example of incorrect behaviour:

Correct behaviour:

Also correct behaviour: