以GZip解压缩,这个在某次解析某站数据的时候用到了,保存留念
public static string GZipDecompressString(this string zippedString) { if (string.IsNullOrEmpty(zippedString) || zippedString.Length == 0) { return ""; } else { byte[] zippedData = Convert.FromBase64String(zippedString.ToString()); return (string)(System.Text.Encoding.UTF8.GetString(Decompress(zippedData))); } } public static byte[] Decompress(byte[] zippedData) { MemoryStream ms = new MemoryStream(zippedData); GZipStream compressedzipStream = new GZipStream(ms, CompressionMode.Decompress); MemoryStream outBuffer = new MemoryStream(); byte[] block = new byte[1024]; while (true) { int bytesRead = compressedzipStream.Read(block, 0, block.Length); if (bytesRead <= 0) break; else outBuffer.Write(block, 0, bytesRead); } compressedzipStream.Close(); return outBuffer.ToArray(); }