Skip to main content
The LZMA SDK is a public domain compression library that provides the LZMA algorithm used in 7-Zip.

Overview

LZMA SDK features:
  • License: Public domain (no restrictions)
  • Languages: C, C++, C#, Java
  • Algorithms: LZMA, LZMA2
  • Size: ~50 KB compiled
  • Speed: Very fast decompression
  • Ratio: Excellent compression
LZMA SDK is written and placed in the public domain by Igor Pavlov. You can use it freely without any restrictions.

Download

The LZMA SDK is available at:

Core Files

LZMA Encoder

LZMA Decoder

Common Files

LZMA Encoder API

Encoder Properties

From LzmaEnc.h (lines 20-34):

Initialization

Compression Example

LZMA Decoder API

Decoder State

From LzmaDec.h (lines 70-85):

Decompression Example

Simplified API

LzmaLib - Single Function Interface

From LzmaLib.h:

Simple Compression Example

Simple Decompression Example

LZMA2 API

LZMA2 Encoder

LZMA2 Decoder

Memory Allocation

Custom Allocator

Default Allocators

From Alloc.c:

Compression Parameters

Dictionary Size

Literal Context Bits (lc)

  • Default: 3
  • Range: 0-8
  • Higher = better compression for text, more memory

Literal Position Bits (lp)

  • Default: 0
  • Range: 0-4
  • For aligned data (executables): 2

Position Bits (pb)

  • Default: 2
  • Range: 0-4
  • For aligned data: 2

Fast Bytes (fb)

  • Default: 32
  • Range: 5-273
  • Higher = better compression, slower encoding
  • Recommended: 64 or 273 for maximum compression

Error Codes

From 7zTypes.h:

Building LZMA SDK

Makefile Targets

CMake Example

Performance Tips

Optimize compression speed:
  1. Reduce dictionary size - Use 16 MB instead of 64 MB
  2. Lower level - Use level 5 instead of 9
  3. Reduce fb - Use 32 instead of 273
  4. Enable threading - Set numThreads = 2
Optimize compression ratio:
  1. Maximum dictionary - 64 MB (32-bit) or 1.5 GB (64-bit)
  2. Maximum level - level = 9
  3. Maximum fb - fb = 273
  4. Binary tree mode - btMode = 1

Integration Examples

Compress File

See Also