[C#] C#解压GZip文件代码 →→→→→进入此内容的聊天室

来自 , 2019-10-05, 写在 C#, 查看 127 次.
URL http://www.code666.cn/view/c4819d06
  1.         public void ungzip(string path, string decomPath, bool overwrite)
  2.         {
  3.             //for overwriting purposes
  4.             if (File.Exists(decomPath))
  5.             {
  6.                 if (overwrite)
  7.                 {
  8.                     File.Delete(decomPath);
  9.                 }
  10.                 else
  11.                 {
  12.                     throw new IOException("The decompressed path you specified already exists and cannot be overwritten.");
  13.                 }
  14.             }
  15.             //create our file streams
  16.             GZipStream stream = new GZipStream(new FileStream(path, FileMode.Open, FileAccess.ReadWrite), CompressionMode.Decompress);
  17.             FileStream decompressedFile = new FileStream(decomPath, FileMode.OpenOrCreate, FileAccess.Write);
  18.             //data represents a byte from the compressed file
  19.             //it's set through each iteration of the while loop
  20.             int data;
  21.             while ((data = stream.ReadByte()) != -1) //iterates over the data of the compressed file and writes the decompressed data
  22.             {
  23.                 decompressedFile.WriteByte((byte)data);
  24.             }
  25.             //close our file streams
  26.             decompressedFile.Close();
  27.             stream.Close();
  28.         }
  29. //csharp/5588

回复 "C#解压GZip文件代码"

这儿你可以回复上面这条便签

captcha