zoukankan      html  css  js  c++  java
  • GZip压缩与解压缩

    GZIP的压缩与解压缩代码:

    public static class CompressionHelper
            {
                /// <summary> 
                /// Compress the byte[] 
                /// </summary> 
                /// <param name="input"></param> 
                /// <returns></returns> 
                public static byte[] Compress(byte[] input)
                {
                    byte[] output;
                    using (MemoryStream ms = new MemoryStream())
                    {
                        using (GZipStream gs = new GZipStream(ms, CompressionMode.Compress))
                        {
                            gs.Write(input, 0, input.Length);
                            gs.Close();
                            output = ms.ToArray();
                        }
                        ms.Close();
                    }
                    return output;
                }
    
                /// <summary> 
                /// Decompress the byte[] 
                /// </summary> 
                /// <param name="input"></param> 
                /// <returns></returns> 
                public static byte[] Decompress(byte[] input)
                {
                    List<byte> output = new List<byte>();
                    using (MemoryStream ms = new MemoryStream(input))
                    {
                        using (GZipStream gs = new GZipStream(ms, CompressionMode.Decompress))
                        {
                            int readByte = gs.ReadByte();
                            while (readByte != -1)
                            {
                                output.Add((byte)readByte);
                                readByte = gs.ReadByte();
                            }
                            gs.Close();
                        }
                        ms.Close();
                    }
                    return output.ToArray();
                }
            }

    出处:http://blog.csdn.net/joyhen/article/details/45366969

  • 相关阅读:
    观光公交
    审查(银)
    小木棍 && 愤怒的小鸟
    SDOI2008 仪仗队 && SDOI2012 Longge的问题 && q
    斗地主 && Mayan游戏 && 作业调度方案
    过河
    跳跳棋
    count
    Cow Tennis Tournament
    luogu P1534不高兴的津津(升级版)
  • 原文地址:https://www.cnblogs.com/mq0036/p/7016385.html
Copyright © 2011-2022 走看看