public static void AddDecompressionRequest(DecompressionRequest req) { lock(DecompressionRequests) { DecompressionRequests.Enqueue(req); } }
private static int Decompress(DecompressionRequest req) { string zipName = req.sourceFilename; string fileName = req.targetFilename; string dstFile = ""; FileStream fsIn = null; FileStream fsOut = null; GZipStream gzip = null; const int bufferSize = 4096; byte[] buffer = new byte[bufferSize]; int count = 0; int totalCount = 0; try { dstFile = fileName; fsIn = new FileStream(zipName, FileMode.Open, FileAccess.Read, FileShare.Read); fsOut = new FileStream(dstFile, FileMode.Create, FileAccess.Write, FileShare.None); gzip = new GZipStream(fsIn, CompressionMode.Decompress, true); while (true) { count = gzip.Read(buffer, 0, bufferSize); if (count != 0) { fsOut.Write(buffer, 0, count); totalCount += count; } if (count != bufferSize) { // have reached the end break; } } } catch (Exception ex) { // handle or display the error System.Diagnostics.Debug.Assert(false, ex.ToString()); } finally { if (gzip != null) { gzip.Close(); gzip = null; } if (fsOut != null) { fsOut.Close(); fsOut = null; } if (fsIn != null) { fsIn.Close(); fsIn = null; } } return totalCount; }