use*_*944 0 c# sharpziplib c#-4.0
我有一个非常奇怪的问题.我使用SharpZipLib库生成.zip.我发现.zip的大小比我的文本文件总大一点.我不知道出了什么问题.我也尝试谷歌,但我找不到与我的情况有关的任何内容.这是我的代码:
protected void CompressFolder(string[] files, string outputPath)
{
using (ZipOutputStream s = new ZipOutputStream(File.Create(outputPath)))
{
s.SetLevel(0);
foreach (string path in files)
{
ZipEntry entry = new ZipEntry(Path.GetFileName(path));
entry.DateTime = DateTime.Now;
entry.Size = new FileInfo(path).Length;
s.PutNextEntry(entry);
byte[] buffer = new byte[4096];
int byteCount = 0;
using (FileStream input = File.OpenRead(path))
{
byteCount = input.Read(buffer, 0, buffer.Length);
while (byteCount > 0)
{
s.Write(buffer, 0, byteCount);
byteCount = input.Read(buffer, 0, buffer.Length);
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
压缩级别为0表示SharpZipLib存储而不是压缩.
较大的尺寸是因为Zip metastructure(文件名等)
然后,您的解决方案是将级别更改为更高级别,即:
s.SetLevel(9);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
848 次 |
最近记录: |