Click here to Skip to main content
13,295,178 members (74,871 online)
Click here to Skip to main content
Add your own
alternative version


53 bookmarked
Posted 3 Nov 2006

Pure C# MiniLZO port

, 22 Dec 2006
Rate this:
Please Sign up or sign in to vote.
Fast stream compression using a ported minilzo for .NET.


I was recently in a position where I needed to find a fast streamable compression solution.  The great source by Markus Oberhumer provided the answer. After using the C code for a while, I realized C#/.NET lacked a similar library, short of one I found which was commercial.

As a result, I decided to attempt a minimalistic port of MiniLZO compression and decompression into pure C#. At this point, the code uses unsafe/fixed blocks to best mimic the original minilzo implementation. A pure managed solution may be soon to follow (at the cost of speed).

The code has not been unit tested 100%, but all initial tests have been successful. If anyone finds any bugs, please report them so I may fix it. I also have not done any profiling of the speed yet, if anyone feels upto the task of comparing it against the C implementation.

Use of the code is relatively simple, here is a quick example.


byte[] original = File.ReadAllBytes("...");
byte[] destination;
MiniLZO.Compress(original, out destination);


byte[] destination = ...; /* Resulting buffer from above */
byte[] original = new byte[x];
MiniLZO.Decompress(destination, original);

Note that with compression, the destination buffer will be assigned and trimmed to the correct size. With decompression, the "original" buffer must be preallocated with the correct original size. Also note that my implementation removed all use of goto from the original source, and replaces certain uses with OverflowExceptions.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
Canada Canada
Short and simple, I'm a self contracted programmer, my strongest programming skills are in C/C++ and C#/.NET. I have a nack for porting C algorithms to C#.

You may also be interested in...

Comments and Discussions

GeneralRe: Another such library... Pin
WorldNomad23-Dec-06 4:32
memberWorldNomad23-Dec-06 4:32 
GeneralRe: Another such library... Pin
omaurice23-Dec-06 5:00
memberomaurice23-Dec-06 5:00 
Generalwhy not adding the original size to the header of the buffer Pin
Unruled Boy5-Nov-06 16:19
memberUnruled Boy5-Nov-06 16:19 
GeneralRe: why not adding the original size to the header of the buffer Pin
Astaelan6-Nov-06 18:01
memberAstaelan6-Nov-06 18:01 
GeneralRe: why not adding the original size to the header of the buffer Pin
SimmoTech6-Nov-06 21:44
memberSimmoTech6-Nov-06 21:44 
GeneralRe: why not adding the original size to the header of the buffer Pin
Astaelan6-Nov-06 22:12
memberAstaelan6-Nov-06 22:12 
GeneralImpressive, but... Pin
woudwijk4-Nov-06 2:11
memberwoudwijk4-Nov-06 2:11 
GeneralRe: Impressive, but... Pin
Astaelan4-Nov-06 11:29
memberAstaelan4-Nov-06 11:29 
Thanks for pointing this out, however, it was not the intention of this project to use a slow compression algorithm such as gzip. LZO is incredibly fast, and perhaps one of the best, if not the best option for streaming compression... Please don't confuse this with file based compression, which gzip is far more suited for. The methods you mention better relate to my other article which was about SharpZipLib, at which time I was using 1.1 framework and yes, they added something that was missing.

LZO gives you the option to trade off compression speed for size, without losing any of the decompression speed. This project wasn't meant to superceed anything around, it simply fills a void that nothing else has yet for .NET, and still managed around a 43% savings with the default.

I don't much care about the rating, I didn't do this for popularity, though I am a bit surprised someone felt this deserved such a low rating. Anyway, profile the codes, you'll find minilzo is significantly faster (unless I screwed up my code somewhere) and as such is useful for other purposes than the gzip streams.
GeneralAgreement Pin
Behind The Scene22-Dec-06 13:44
memberBehind The Scene22-Dec-06 13:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171207.1 | Last Updated 22 Dec 2006
Article Copyright 2006 by Astaelan
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid