我有一些下載gzip文件的代碼,並解壓縮它們。問題是,我無法解壓縮整個文件,只能讀取前4096個字節,然後再讀取約500個字節。GZipStream沒有讀取整個文件
Byte[] buffer = new Byte[4096];
int count = 0;
FileStream fileInput = new FileStream("input.gzip", FileMode.Open, FileAccess.Read, FileShare.Read);
FileStream fileOutput = new FileStream("output.dat", FileMode.Create, FileAccess.Write, FileShare.None);
GZipStream gzipStream = new GZipStream(fileInput, CompressionMode.Decompress, true);
// Read from gzip steam
while ((count = gzipStream.Read(buffer, 0, buffer.Length)) > 0)
{
// Write to output file
fileOutput.Write(buffer, 0, count);
}
// Close the streams
...
我檢查了下載的文件;壓縮時爲13MB,幷包含一個XML文件。我已經手動解壓縮了XML文件,並且內容都在那裏。但是,當我使用此代碼執行此操作時,它僅輸出XML文件的最開始部分。
任何人有任何想法,爲什麼這可能會發生?
當我在寫一個解壓縮程序我記得得到這個問題。不過,我已經看到了我最終使用的工作代碼,除了被'使用'塊封裝之外,它看起來像你的。 – 2010-06-18 09:20:18
你在調用Flush()方法嗎? – n535 2010-06-18 09:20:31
嘗試沖洗(),沒有幫助。 – Edgar 2010-06-18 09:26:35