鉴于这两个文件:c:\ folder1 \ test.txt和c:\ folder2 \ test.txt
在VB.NET上使用.Net 4.5 System.IO.Compression创建zip文件(c:\ test.zip)并添加2个文件并包含目录结构的最佳方法是什么?
感谢。
答案 0 :(得分:0)
答案位于网站
.NET GZipStream compress and decompress
public static bool Test()
{
string sample = "This is a compression test of microsoft .net gzip compression method and decompression methods";
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
byte[] data = encoding.GetBytes(sample);
// Compress.
GZipStream hgs;
byte[] cmpData;
using(MemoryStream cmpStream = new MemoryStream())
using(hgs = new GZipStream(cmpStream, CompressionMode.Compress))
{
hgs.Write(data, 0, data.Length);
cmpData = cmpStream.ToArray();
}
using(MemoryStream decomStream = new MemoryStream(cmpData))
using(hgs = new GZipStream(decomStream, CompressionMode.Decompress))
{
hgs.Read(data, 0, data.Length);
}
string sampleOut = encoding.GetString(data);
bool result = String.Equals(sample, sampleOut);
return result;
}