rahulmr
rahulmr

Reputation: 681

ZipArchive ZipFile not compressing

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);
                    }
                }

Upvotes: 0

Views: 576

Answers (1)

Mark Adler
Mark Adler

Reputation: 112502

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.

Upvotes: 1

Related Questions