How to find uncompressed size of ionic zip file

2019-02-18 19:48发布

I have a zip file compressed using Ionic zip. Before extracting I need to verify the available disk space. But how do I find the uncompressed size before hand? Is there any header information in the zip file (by ionic) so that I can read it?

2条回答
Ridiculous、
2楼-- · 2019-02-18 20:37

This should do the trick:

static long totaluncompressedsize;
static string info;
.
.
.
.

// Option 1
foreach (ZipEntry e in zip)
{
    long uncompressedsize = e.UncompressedSize;
    totaluncompressedsize += uncompressedsize;
}

// Or

// Option 2 - will need to sift through the mass of info        
using (ZipFile zip = ZipFile.Read(zipFile))
{
    info = zip.Info;
}
查看更多
Fickle 薄情
3楼-- · 2019-02-18 20:41
public static long GetTotalUnzippedSize(string zipFileName)
{
    using (ZipArchive zipFile = ZipFile.OpenRead(zipFileName))
    {
        return zipFile.Entries.Sum(entry => entry.Length);
    }
}
查看更多
登录 后发表回答