0

In SharpZipLib we use ZipEntry like this:

            var fi = new FileInfo(file);
            var ze = new Sharp.Zip.ZipEntry(fi.Name);
            ze.DateTime = fi.LastAccessTime;
            ze.Size = fi.Length;
            stream.PutNextEntry(ze);

            var buffer = new byte[4096];
            var byteCount = 0;

            using (FileStream inputStream = File.OpenRead(fi.FullName))
            {
                byteCount = inputStream.Read(buffer, 0, buffer.Length);
                while (byteCount > 0)
                {
                    stream.Write(buffer, 0, byteCount);
                    byteCount = inputStream.Read(buffer, 0, buffer.Length);
                }
                inputStream.Close();
            }
            stream.CloseEntry();

There is a ze.CompressedSize property but it is -1 and populated only after the CloseEntry() which creates the zip file.

Is there a way to find out the Compressed size of the zip file without putting the files and actually creating it.

Simple Fellow
  • 4,315
  • 2
  • 31
  • 44

1 Answers1

0

Easiest way would be to have a dummy zip file, using ZipOutputStream, backed with an underlying MemoryStream. Write the file to that - make sure you set the same compression factor - and close the ZipOutputStream, re-open it using ZipFile, and scan the entry to obtain the compressed size.

There is an example here.

Umut Seven
  • 398
  • 2
  • 11
  • 20