Click here to Skip to main content
15,889,795 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I found this code to call the zLib1.dll but how
can I specify a file to compress and specify the file name compressed.
And the same case to uncompress?
C# 4.0

[DllImport("zlib1.dll", CallingConvention=CallingConvention.Cdecl) ] 
        static extern int compress(byte[] destBuffer, ref uint destLen, byte[] sourceBuffer, uint sourceLen);
        [DllImport("zlib1.dll", CallingConvention = CallingConvention.Cdecl)]
        static extern int uncompress(byte[] destBuffer, ref uint destLen, byte[] sourceBuffer, uint sourceLen);


public static byte[] Compress(byte[] data)
        {
            uint _dLen = (uint)((data.Length * 1.1) + 12);
            byte[] _d = new byte[_dLen];
            compress(_d, ref _dLen, data, (uint)data.Length);
            byte[] result = new byte[_dLen];
            Array.Copy(_d, 0, result, 0, result.Length);
            return result;
        }
        public static byte[] Decompress(byte[] data)
        {
            uint _dLen = 8192;
            byte[] _d = new byte[_dLen];
            if (uncompress(_d, ref _dLen, data, (uint)data.Length) != 0)
                return null;
            byte[] result = new byte[_dLen];
            Array.Copy(_d, 0, result, 0, result.Length);
            return result;
        }


[Edited]Code is blocked in "pre" tags[/Edited]
Posted
Updated 4-May-11 5:56am
v2

1 solution

If you want a zip library running for .NET, I suggest this one:
http://dotnetzip.codeplex.com/[^]

Very easy to use.
 
Share this answer
 
Comments
TheCodeVB 4-May-11 11:44am    
I really need to uncompress a file that was compressed with zlib1.dll
Olivier Levrey 4-May-11 11:53am    
Zip is a standard. You can use different libraries on a same file. Even if you compressed a zip file with another library, DotNetZip will be able to uncompress it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900