I’ve made a managed LZMA implementation in C#. It’s written from scratch (i.e. I didn’t just port the 7zip code to C#) to get a better understanding of how “good” compression algorithms work and what makes them so efficient. The implementation itself is mainly just a learning project. The performance of the decoder is fine I’d say, but the encoder is rather slow and does not quite reach the compression ratio of the real 7zip lzma encoder. This is mainly because my implementation doesn’t do optimal parsing, which is the last thing in the original code I need to understand. But the 7zip code is kind of hard to read and not very well documented in that regard, so I didn’t get around doing it yet.

Anyway, the code is well-structured and documented. It might be worth checking out for anyone trying to get a grasp of how LZ-based compression is done. However, I wouldn’t recommend using it for serious projects/production because of the sub-optimal compression speed.

The code can be found on GitLab with instructions on how to compile the library. It provides a .NET Stream implementation (LzmaStream) for easy integration which is compatible with the .lzma standalone file format. 7zip and xz can decode it, for example.