zoukankan      html  css  js  c++  java
  • C# 压缩数据传输

    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.IO;
    using ICSharpCode.SharpZipLib.BZip2;
    using System.Text;

    namespace Common
    {
        /// <summary>
        /// 压缩数据传输
        /// </summary>
        public class UnZip
        {
            public UnZip()
            {
            }

            #region 返回压缩后的字节数组
            /// <summary>
            /// 返回压缩后的字节数组
            /// </summary>
            /// <param name="data"></param>
            /// <returns></returns>
            public static byte[] Compress(byte[] data)
            {
                if (data == null || data.Length == 0)
                {
                    return null;
                }

                MemoryStream inStream = new MemoryStream(data, 0, data.Length);
                MemoryStream outStream = new MemoryStream();
                BZip2.Compress(inStream, outStream,false, data.Length);

                byte[] result = outStream.ToArray();
                inStream.Close();
                outStream.Close();

                return result;
            }
            #endregion

            #region 返回解压后的字节数组
            /// <summary>
            /// 返回解压后的字节数组
            /// </summary>
            /// <param name="data">原始字节数组</param>
            /// <returns></returns>
            public static byte[] Decompress(byte[] data)
            {
                if (data == null || data.Length == 0)
                {
                    return null;
                }
                MemoryStream inStream = new MemoryStream(data, 0, data.Length);
                MemoryStream outStream = new MemoryStream();
                BZip2.Decompress(inStream, outStream,false);
               
                byte[] result = outStream.ToArray();
                inStream.Close();
                outStream.Close();

                return result;
            }

            #endregion
        }
    }

  • 相关阅读:
    dockerfile 踩坑记录
    Windows安装配置xampp
    docker 容器中设置 mysql lampp php软链接
    linux 软件连接 创建/查看/删除
    mysql 远程连接权限
    linux设置静态获取ip
    android 自定义控件中获取属性的三种方式(转)
    android 自定义组件-带图片的textView
    CodeIgniter 3之Session类库(3)(转)
    CodeIgniter 3之Session类库(2)(转)
  • 原文地址:https://www.cnblogs.com/weixing/p/2512752.html
Copyright © 2011-2022 走看看