25 namespace Simplicit.Net.Lzo {
27 using System.Diagnostics;
28 using System.Runtime.InteropServices;
34 private static TraceSwitch _traceSwitch =
new TraceSwitch(
"Simplicit.Net.Lzo",
"Switch for tracing of the LZOCompressor-Class");
37 [DllImport(
"lzo.dll")]
38 private static extern int __lzo_init3();
39 [DllImport(
"lzo.dll")]
40 private static extern string lzo_version_string();
41 [DllImport(
"lzo.dll")]
42 private static extern string lzo_version_date();
43 [DllImport(
"lzo.dll")]
44 private static extern int lzo1x_1_compress(
51 [DllImport(
"lzo.dll")]
52 private static extern int lzo1x_decompress(
60 private byte[] _workMemory =
new byte[16384L * 4];
63 int init = __lzo_init3();
65 throw new Exception(
"Initialization of LZO-Compressor failed !");
80 return lzo_version_string();
87 public string VersionDate {
89 return lzo_version_date();
100 if(_traceSwitch.TraceVerbose) {
101 Trace.WriteLine(String.Format(
"LZOCompressor: trying to compress {0}", src.Length));
103 byte[] dst =
new byte[src.Length + src.Length / 64 + 16 + 3 + 4];
105 lzo1x_1_compress(src, src.Length, dst, ref outlen, _workMemory);
106 if(_traceSwitch.TraceVerbose) {
107 Trace.WriteLine(String.Format(
"LZOCompressor: compressed {0} to {1} bytes", src.Length, outlen));
109 byte[] ret =
new byte[outlen + 4];
110 Array.Copy(dst, 0, ret, 0, outlen);
111 byte[] outlenarr = BitConverter.GetBytes(src.Length);
112 Array.Copy(outlenarr, 0, ret, outlen, 4);
122 if(_traceSwitch.TraceVerbose) {
123 Trace.WriteLine(String.Format(
"LZOCompressor: trying to decompress {0}", src.Length));
125 int origlen = BitConverter.ToInt32(src, src.Length - 4);
126 byte[] dst =
new byte[origlen];
127 int outlen = origlen;
128 lzo1x_decompress(src, src.Length - 4, dst, ref outlen, _workMemory);
129 if(_traceSwitch.TraceVerbose) {
130 Trace.WriteLine(String.Format(
"LZOCompressor: decompressed {0} to {1} bytes", src.Length, origlen));