Exemple #1
0
        static public DataTable DecompressionDataTable(byte[] bytes)
        {
            MemoryStream mStream = new MemoryStream(bytes);

            mStream.Seek(0, SeekOrigin.Begin);

            DeflateStream unZipStream = new DeflateStream(mStream, CompressionMode.Decompress, true);

            byte[] unZipBytes = StreamOperator.ReadWholeStream(unZipStream);
            unZipStream.Flush();
            unZipStream.Close();

            MemoryStream resultStream = new MemoryStream(unZipBytes);

            resultStream.Seek(0, SeekOrigin.Begin);

            DataTable dtResult = new DataTable();

            dtResult.RemotingFormat = SerializationFormat.Binary;
            BinaryFormatter bFormatter = new BinaryFormatter();

            dtResult = (DataTable)bFormatter.Deserialize(resultStream, null);

            return(dtResult);
        }
Exemple #2
0
        /// <summary>
        /// 解压缩二进制格式数据,得到数据集
        /// </summary>
        /// <param name="bytes"></param>
        /// <returns></returns>
        public static DataSet DecompressionDataSet1(byte[] bytes)
        {
            // 初始化流,设置读取位置
            MemoryStream mStream = new MemoryStream(bytes);

            mStream.Seek(0, SeekOrigin.Begin);
            // 解压缩流得到byte[]格式数据
            DeflateStream unZipStream = new DeflateStream(mStream, CompressionMode.Decompress, true);

            byte[] unzipBytes = StreamOperator.ReadWholeStream(unZipStream);
            unZipStream.Flush();
            unZipStream.Close();
            // 将数据装入内存
            MemoryStream resultStream = new MemoryStream(unzipBytes);

            resultStream.Seek(0, SeekOrigin.Begin);
            // 反序列化
            DataSet resultDataSet = new DataSet();

            resultDataSet.RemotingFormat = SerializationFormat.Binary;
            BinaryFormatter bFormatter = new BinaryFormatter();

            resultDataSet = (DataSet)bFormatter.Deserialize(resultStream, null);
            //
            return(resultDataSet);
        }