Click here to Skip to main content
15,881,898 members
Articles / Programming Languages / C#
Article

Pure C# MiniLZO port

Rate me:
Please Sign up or sign in to vote.
4.88/5 (21 votes)
22 Dec 20061 min read 140.6K   1.6K   53   44
Fast stream compression using a ported minilzo for .NET.

Introduction

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.

Compression

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

Decompression

C#
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.

License

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


Written By
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#.

Comments and Discussions

 
QuestionAccessViolation on 64-bit Pin
zzattack26-Aug-13 16:25
zzattack26-Aug-13 16:25 
AnswerRe: AccessViolation on 64-bit Pin
Mystery12325-May-23 0:11
professionalMystery12325-May-23 0:11 
QuestionCan u port lzo1z to .net Pin
yuvraj_oak1-Jul-11 23:01
yuvraj_oak1-Jul-11 23:01 
SuggestionRe: Can u port lzo1z to .net Pin
Coumar Pandourangane27-Aug-18 1:25
Coumar Pandourangane27-Aug-18 1:25 
GeneralDynamic sizes Pin
HenryChilvers20-Sep-10 13:26
HenryChilvers20-Sep-10 13:26 
GeneralBuffer overflow help :( Pin
zeeh315-Jul-10 9:49
zeeh315-Jul-10 9:49 
GeneralRe: Buffer overflow help :( Pin
zeeh316-Jul-10 7:07
zeeh316-Jul-10 7:07 
GeneralRe: Buffer overflow help :( Pin
Member 1020339811-Aug-13 20:15
Member 1020339811-Aug-13 20:15 
QuestionUsage in closed source customer project Pin
Kay Herzam12-Jul-07 22:01
Kay Herzam12-Jul-07 22:01 
AnswerRe: Usage in closed source customer project Pin
Astaelan13-Jul-07 6:11
Astaelan13-Jul-07 6:11 
Generalexample with memory stream, chunk-by-chunk Pin
dncpax211-Jul-07 1:19
dncpax211-Jul-07 1:19 
GeneralRe: example with memory stream, chunk-by-chunk Pin
Astaelan13-Jul-07 6:07
Astaelan13-Jul-07 6:07 
GeneralSource Code Pin
Tit Copernicus5-May-07 3:10
Tit Copernicus5-May-07 3:10 
GeneralRe: Source Code Pin
Astaelan5-May-07 8:24
Astaelan5-May-07 8:24 
GeneralHere is how to make it work on Pocket PC Windows Mobile Pin
rkm10-Jan-07 1:56
rkm10-Jan-07 1:56 
GeneralDoesn't work on 64 bit Pin
bimal20064-Jan-07 17:38
bimal20064-Jan-07 17:38 
GeneralRe: Doesn't work on 64 bit Pin
Astaelan4-Jan-07 18:15
Astaelan4-Jan-07 18:15 
GeneralRe: Doesn't work on 64 bit Pin
tedsmorris24-Oct-07 8:39
tedsmorris24-Oct-07 8:39 
GeneralRe: Doesn't work on 64 bit Pin
AVEbrahimi17-Jun-09 21:21
AVEbrahimi17-Jun-09 21:21 
GeneralRe: Doesn't work on 64 bit Pin
chenavnery1-Jul-15 5:02
chenavnery1-Jul-15 5:02 
GeneralThanks Pin
Ri Qen-Sin22-Dec-06 12:46
Ri Qen-Sin22-Dec-06 12:46 
GeneralRe: Thanks Pin
Astaelan23-Dec-06 3:47
Astaelan23-Dec-06 3:47 
GeneralTiny bug Pin
SimmoTech22-Nov-06 19:14
SimmoTech22-Nov-06 19:14 
GeneralRe: Tiny bug Pin
Astaelan22-Dec-06 9:19
Astaelan22-Dec-06 9:19 
GeneralSuggestion Pin
Oskar Austegard9-Nov-06 3:04
Oskar Austegard9-Nov-06 3:04 

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.