/// <summary> /// 使用 DEFLATE 解压字节的数组。 /// </summary> /// /// <seealso cref="GZipStream.CompressString(String)">GZipStream.CompressString(String)</seealso> /// <seealso cref="GZipStream.UncompressBuffer(byte[])">GZipStream.UncompressBuffer(byte[])</seealso> /// <seealso cref="GZipStream.UncompressString(byte[])">GZipStream.UncompressString(byte[])</seealso> /// /// <param name="compressed"> /// 压缩的数组。 /// </param> /// /// <returns>解压后的字符串。</returns> public static String UncompressString(byte[] compressed) { using (var input = new MemoryStream(compressed)) { Stream decompressor = new GZipStream(input, CompressionMode.Decompress); return(ZipBaseStream.UncompressString(compressed, decompressor)); } }
/// <summary> /// 使用 DEFLATE 解压字节的数组。 /// </summary> /// /// <seealso cref="GZipStream.CompressBuffer(byte[])">GZipStream.CompressBuffer(byte[])</seealso> /// <seealso cref="GZipStream.UncompressString(byte[])">GZipStream.UncompressString(byte[])</seealso> /// <seealso cref="GZipStream.UncompressBuffer(byte[])">GZipStream.UncompressBuffer(byte[])</seealso> /// /// <param name="compressed"> /// 压缩的数组。 /// </param> /// /// <returns>解压后的数组。</returns> public static byte[] UncompressBuffer(byte[] compressed) { using (var input = new System.IO.MemoryStream(compressed)) { System.IO.Stream decompressor = new GZipStream(input, CompressionMode.Decompress); return(ZipBaseStream.UncompressBuffer(compressed, decompressor)); } }
/// <summary> /// 使用 DEFLATE 解压字节的数组。 /// </summary> /// /// <seealso cref="DeflateStream.CompressString(String)">DeflateStream.CompressString(String)</seealso> /// <seealso cref="DeflateStream.UncompressBuffer(byte[])">DeflateStream.UncompressBuffer(byte[])</seealso> /// <seealso cref="GZipStream.UncompressString(byte[])">GZipStream.UncompressString(byte[])</seealso> /// /// <param name="compressed"> /// 压缩的数组。 /// </param> /// /// <returns>解压后的字符串。</returns> public static string UncompressString(byte[] compressed) { using (var input = new System.IO.MemoryStream(compressed)) { System.IO.Stream decompressor = new DeflateStream(input, CompressionMode.Decompress); return(ZipBaseStream.UncompressString(compressed, decompressor)); } }
/// <summary> /// 使用 GZip 压缩一个字符串到数组。 /// </summary> /// /// <remarks> /// 用 <see cref="GZipStream.UncompressString(byte[])"/> 解压。 /// </remarks> /// /// <seealso cref="GZipStream.UncompressString(byte[])">GZipStream.UncompressString(byte[])</seealso> /// <seealso cref="GZipStream.CompressBuffer(byte[])">GZipStream.CompressBuffer(byte[])</seealso> /// <seealso cref="GZipStream.CompressString(string)">GZipStream.CompressString(string)</seealso> /// <param name="s"> 要压缩的字符串。 </param> /// <returns>压缩的字节的数组。</returns> public static byte[] CompressString(string s) { using (var ms = new MemoryStream()) { System.IO.Stream compressor = new GZipStream(ms, CompressionMode.Compress, CompressionLevel.BestCompression); ZipBaseStream.CompressString(s, compressor); return(ms.ToArray()); } }
/// <summary> /// 使用 DEFLATE 压缩一个数组到数组。 /// </summary> /// /// <remarks> /// 使用 <see cref="DeflateStream.UncompressBuffer(byte[])"/> 解压。 /// </remarks> /// /// <seealso cref="DeflateStream.CompressString(string)">DeflateStream.CompressString(string)</seealso> /// <seealso cref="DeflateStream.UncompressBuffer(byte[])">DeflateStream.UncompressBuffer(byte[])</seealso> /// <seealso cref="GZipStream.CompressBuffer(byte[])">GZipStream.CompressBuffer(byte[])</seealso> /// /// <param name="b"> /// 压缩的缓存。 /// </param> /// /// <returns>压缩的结果。</returns> public static byte[] CompressBuffer(byte[] b) { using (var ms = new System.IO.MemoryStream()) { System.IO.Stream compressor = new DeflateStream(ms, CompressionMode.Compress, CompressionLevel.BestCompression); ZipBaseStream.CompressBuffer(b, compressor); return(ms.ToArray()); } }