0

I am using the System.IO.Compression in .net 4.5 and ZipArchive and ZipFile are used to add txt files to the archive. There are around 75 files . The files when put in a folder and measured the size, it was around 15 KB

But when used to put in archive using the ZipArchive the zip file size generated was of 21KB. Am I doing something wrong or this ZipArhive is just to put the files into an archive single file rather than compressing ?

Is that Deflate alogrithm used for the .zip creation ? This is what I have done. Is there any high level compression that can be used ?for .7zip the file size is even smaller, around 1KB only

 using (ZipArchive zippedFile = ZipFile.Open(zipFileName, ZipArchiveMode.Create))
                {
                    foreach (string file in filesTobeZipped)
                    {
                        zippedFile.CreateEntryFromFile(file, Path.GetFileName(file), CompressionLevel.Optimal);
                    }
                }
rahulmr
  • 681
  • 1
  • 7
  • 19

1 Answers1

1

Each entry in a zip file has an overhead for the local and central headers of 76 bytes plus the length of the file name with path, twice, plus a single end record of 22 bytes. For 75 files each with, say, a three-character name, the total overhead would be about 6K. Each file averages about 200 bytes in length uncompressed, which is too short to compress effectively. If each file remained a 200 byte entry in the zip file, then you would end up with a 21K zip file. Which is in fact what you got.

Mark Adler
  • 101,978
  • 13
  • 118
  • 158
  • So you mean to say that for a minimal file size of 1KB and for a batch of 100-1000 files,we dont need to expect too much compression and it would be almost the same size or more than the actual size of all these files ? – rahulmr Jan 20 '17 at 06:00
  • Note that on your drive each file also takes up more space than it says. The amount of space taken by a one-byte file is likely 512 or 1024 bytes, depending on your operating system. And that doesn't even count the space taken by the corresponding directory entry. – Mark Adler Jan 20 '17 at 06:33