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?
Asked
Active
Viewed 4,571 times
2 Answers
10
This should do the trick:
Option 1
static long totaluncompressedsize;
static string info;
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;
}

Software Engineer
- 15,457
- 7
- 74
- 102

Taniq
- 178
- 1
- 11
-
thanks, it worked.. its quite fast too.. but im thinking if there could be a faster approach than iterating thru each entry. – nawfal Jun 08 '12 at 08:16
-
1you could check the zip.Info property but this takes just as long, and returns a whole bunch of useful(?) information. – Taniq Jun 08 '12 at 08:31
-
yes you are right, accessing info property is a complete mess – nawfal Jun 08 '12 at 08:53
-
Yup. I think option 1 is the best choice for what you require. It's not a massive overhead, even if the zip is quite large. – Taniq Jun 08 '12 at 09:10
-
4Two things: #1 - iterating each entry as in this answer is the right way to go. It does not involve a full scan of the zip file. Zip includes metadata on each entry in the "central directory" and when iterating, you are simply walking the list of objects created from that metadata. It's fast. #2. The ZipFile.Info property does the same thing (iterates the entries) and formats the output as a string. – Cheeso Jun 13 '12 at 10:44
3
public static long GetTotalUnzippedSize(string zipFileName)
{
using (ZipArchive zipFile = ZipFile.OpenRead(zipFileName))
{
return zipFile.Entries.Sum(entry => entry.Length);
}
}
-
Can u tell us what's the advantage of this or how is it different from previous answer? – nawfal Sep 18 '15 at 15:59
-
1