本文介绍了使用zLib1.ll指定要压缩和解压缩的文件.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发现此代码调用zLib1.dll,但如何
我可以指定要压缩的文件并指定要压缩的文件名吗?
和要解压缩的情况相同吗?
C#4.0
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;
}
[已编辑]代码在前置"标记中被阻止[/已编辑]
Code is blocked in "pre" tags[/Edited]
推荐答案
这篇关于使用zLib1.ll指定要压缩和解压缩的文件.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!