我想在C#中使用deflate/gzip流,但它看起來壓縮後的文件比以前更大。GZipStream和DeflateStream產生更大的文件
例如,我壓縮一個900ko的docx文件,但它產生了一個1.4Mo!
它爲我嘗試過的每個文件都做到了。
可能是我在做錯了嗎?這裏是我的代碼:
FileStream input = File.OpenRead(Environment.CurrentDirectory + "/file.docx");
FileStream output = File.OpenWrite(Environment.CurrentDirectory + "/compressedfile.dat");
GZipStream comp = new GZipStream(output, CompressionMode.Compress);
while (input.Position != input.Length)
comp.WriteByte((byte)input.ReadByte());
input.Close();
comp.Close(); // automatically call flush at closing
output.Close();
你一定要明白,這將通過至少一個字節壓縮*任意*輸入的壓縮方法不能存在?特別是如果你試圖壓縮已經接近隨機的數據,例如預壓縮數據,您可能會看到尺寸增加。 – Joey 2010-10-05 13:30:31
.docx已經使用ZIP壓縮壓縮(嘗試重命名爲.zip並進行探索)。如果第二級壓縮會產生任何好處,我會感到驚訝。 – spender 2010-10-05 13:33:54
它應該只對沖洗進行有效的壓縮,所以它不應該改變一個東西 – kite 2010-10-05 13:34:19