zoukankan      html  css  js  c++  java
  • 压缩 工具类

    public class SharpZip
    {
    /// <summary>
    /// 压缩
    /// </summary>
    /// <param name="param"></param>
    /// <returns></returns>
    public string Compress(string param)
    {
    byte[] data = System.Text.Encoding.UTF8.GetBytes(param);

    MemoryStream ms = new MemoryStream();
    Stream stream = new ICSharpCode.SharpZipLib.GZip.GZipOutputStream(ms);
    try
    {
    stream.Write(data, 0, data.Length);
    }
    finally
    {
    stream.Close();
    ms.Close();
    }
    return Convert.ToBase64String(ms.ToArray());
    }

    /// <summary>
    /// 解压
    /// </summary>
    /// <param name="param"></param>
    /// <returns></returns>
    public string Decompress(string param)
    {
    string commonString = "";

    byte[] buffer = Convert.FromBase64String(param);
    MemoryStream ms = new MemoryStream(buffer);
    Stream sm = new ICSharpCode.SharpZipLib.GZip.GZipInputStream(ms);
    //这里要指明要读入的格式,要不就有乱码
    StreamReader reader = new StreamReader(sm, System.Text.Encoding.UTF8);
    try
    {
    commonString = reader.ReadToEnd();
    }
    finally
    {
    sm.Close();
    ms.Close();
    }
    return commonString;
    }
    }

  • 相关阅读:
    日本最大的汽车品牌:丰田【仅供自己参考】
    读书笔记1
    读书笔记1
    计算机网络笔记1
    ZY凉凉经
    HK凉凉经
    访问一个网站,发生了什么?
    正向代理VS反向代理
    mac下打开hosts文件
    国际手机区号
  • 原文地址:https://www.cnblogs.com/yangpeng-jingjing/p/8796977.html
Copyright © 2011-2022 走看看