Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 压缩后Sharpzip lib文件夹大小相同_C#_Sharpziplib - Fatal编程技术网

C# 压缩后Sharpzip lib文件夹大小相同

C# 压缩后Sharpzip lib文件夹大小相同,c#,sharpziplib,C#,Sharpziplib,我正在使用sharpzip lib压缩文件夹。但压缩后压缩大小略高于文件夹大小。 我的文件夹包括使用aes/Rsa加密的3个xml文件。 例如:size=1kb磁盘大小=12KB ArrayList array = new ArrayList(); int TrimLength = (Directory.GetParent(PathToFile)).ToString().Length; string test=@"\"; if (Directory.Exists(PathToFile)) {

我正在使用sharpzip lib压缩文件夹。但压缩后压缩大小略高于文件夹大小。 我的文件夹包括使用aes/Rsa加密的
3个xml
文件。

例如:
size=1kb磁盘大小=12KB

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;
压缩后
size=1.32KB
和磁盘上的大小
4KB

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;

我不认为加密的东西能像纯文本那样压缩。这可能与此有关。@Sudev加密文本比纯文本具有更少的冗余,这就是为什么它比纯文本提供更少的压缩,因此您得到的是完全正常的。我不认为其他存档格式,如7z、arc、,rar etc将产生更令人满意的结果。因此,不要为此烦恼。但如果你真的关心安全性,我建议你压缩纯文本文件,然后加密存档。