Sharpzip lib folder size same after compresssion

76 views Asked by At

I 'm using sharpzip lib for compressing a folder. But After compression zip size is a bit higher than the folder size. My folder includes 3 xml files encrypted with aes/Rsa.

for eg: size = 1kb size on disk = 12 kb

after compression size = 1.32 kb and size on disk 4 kb

ArrayList array = new ArrayList();
int TrimLength = (Directory.GetParent(PathToFile)).ToString().Length;
string test=@"\";

if (Directory.Exists(PathToFile))
{          
    if (!PathToFile.EndsWith(test))
    {
        TrimLength = TrimLength - 1;
    }
    array = GenerateFileList(PathToFile); // generate file list 
}

else
{
    array.Add(PathToFile);
}

FileStream ostream=null;
byte[] obuffer;
string outPath = @"" + CompressToFolder;

ZipOutputStream oZipStream = new ZipOutputStream(File.Create(outPath)); // create zip stream
oZipStream.SetLevel(9); // maximum compression
ZipEntry oZipEntry;

foreach (string Fil in array) // for each file, generate a zipentry
{
    oZipEntry = new ZipEntry(Fil.Remove(0, TrimLength+1));
    oZipEntry.IsUnicodeText = true;
    oZipStream.PutNextEntry(oZipEntry);

    if (!Fil.EndsWith(@"/")) // if a file ends with '/' its a directory
    {
        ostream = File.OpenRead(Fil);
        obuffer = new byte[ostream.Length];

        ostream.Read(obuffer, 0, obuffer.Length);

        oZipStream.Write(obuffer, 0, obuffer.Length);
        ostream.Dispose();
    }
}

ostream.Close();
oZipStream.Finish();
oZipStream.Close();

return true;
0

There are 0 answers