有谁知道在C#中快速压缩或解压缩文件和文件夹的好方法吗?处理大文件可能是必要的。
发布于 2008-08-05 12:04:41
这里有两个方法可以压缩和解压一个字节流,你可以从你的文件对象中获得。
public static byte[] Compress(byte[] data)
{
MemoryStream output = new MemoryStream();
GZipStream gzip = new GZipStream(output, CompressionMode.Compress, true);
gzip.Write(data, 0, data.Length);
gzip.Close();
return output.ToArray();
}
public static byte[] Decompress(byte[] data)
{
MemoryStream input = new MemoryStream();
input.Write(data, 0, data.Length);
input.Position = 0;
GZipStream gzip = new GZipStream(input, CompressionMode.Decompress, true);
MemoryStream output = new MemoryStream();
byte[] buff = new byte[64];
int read = -1;
read = gzip.Read(buff, 0, buff.Length);
while (read > 0)
{
output.Write(buff, 0, read);
read = gzip.Read(buff, 0, buff.Length);
}
gzip.Close();
return output.ToArray();
}发布于 2008-08-01 17:30:56
我一直在使用SharpZip库。
Here's a link
发布于 2008-08-01 17:28:24
在Java1.1中,唯一可用的方法是进入.Net库。
Using the Zip Classes in the J# Class Libraries to Compress Files and Data with C#
不确定这在最近的版本中是否发生了变化。
https://stackoverflow.com/questions/145
复制相似问题