查找压缩的总ZipFile大小(KB)(不是长度)

时间:2018-03-13 06:03:06

标签: c# asp.net compression

我的应用程序中有以下代码部分。我想将压缩文件大小存储在DB中,但是当我存储缓冲区值时,它与压缩的zip文件大小不同。

如何在C#中识别确切的Zip文件大小?

using (ZipFile zip = new ZipFile())
{
    zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;

    foreach (Docs Docs in FileByteCollection)
    {
        doctype = "Insured";
        country = "US";

        if (doctype == "Local")
            Docs.DocumentName = "LocalDoc.pdf";

        else if (doctype != "Local")
            Docs.DocumentName = "Interantional.pdf"

        zip.AddEntry(Docs.DocName, Docs.DocumentContent);
    }

    zip.Save(outputMemStream);
}

获取FileSize的当前逻辑:

byte[] byteArr = ((MemoryStream)outputMemStream).ToArray();

int totalSize = 0;

foreach (byte b in byteArr)
    totalSize = totalSize + b;

0 个答案:

没有答案