/// <summary> /// 文件夹解压缩 /// </summary> /// <param name="input">字节数组</param> /// <param name="folderPath">解压缩目标文件夹</param> public static void DeCompressFolder(byte[] input, string folderPath) { try { using (MemoryStream source = new MemoryStream(input)) { using (Stream destination = new MemoryStream()) { using (GZipStream gzipStream = new GZipStream(source, CompressionMode.Decompress, true)) { byte[] bytes = new byte[4096]; int n; while ((n = gzipStream.Read(bytes, 0, bytes.Length)) != 0) { destination.Write(bytes, 0, n); } } destination.Flush(); destination.Position = 0; DeSerializeFiles(destination, folderPath); } } } catch { SharpZipLibUtils.DecompressFolder(input, folderPath); } }
/// <summary> /// 字节数组解压缩 /// </summary> /// <param name="input">字节数组</param> /// <returns>解压缩后的字节数组</returns> public static byte[] DecompressBytes(byte[] input) { try { long totalLength = 0; int size = 0; byte[] db; using (var ms = new MemoryStream()) { using (var msD = new MemoryStream()) { ms.Write(input, 0, input.Length); ms.Seek(0, SeekOrigin.Begin); using (var zip = new GZipStream(ms, CompressionMode.Decompress)) { bool readed = true; while (true) { size = zip.ReadByte(); if (size != -1) { if (!readed) { readed = true; } totalLength++; msD.WriteByte((byte)size); } else { if (readed) { break; } } } zip.Close(); } db = msD.ToArray(); msD.Close(); } } return(db); } catch { return(SharpZipLibUtils.DecompressBytes(input)); } }