Decompress byte array to DataTable - CSharp System.IO.Compression

CSharp examples for System.IO.Compression:GZip

Description

Decompress byte array to DataTable

Demo Code


using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO.Compression;
using System.IO;/*w w  w .j ava2 s  .  c o  m*/
using System.Data;
using System;

public class Main{
        public static DataTable Decompress(byte[] data)
        {
            MemoryStream stream = new MemoryStream();
            stream.Write(data, 0, data.Length);
            stream.Position = 0L;
            GZipStream stream2 = new GZipStream(stream, CompressionMode.Decompress, true);
            byte[] buffer2 = new byte[0x400];
            MemoryStream stream3 = new MemoryStream();
            for (int i = stream2.Read(buffer2, 0, buffer2.Length); i > 0; i = stream2.Read(buffer2, 0, buffer2.Length))
            {
                stream3.Write(buffer2, 0, i);
            }
            stream2.Close();
            stream2.Dispose();
            stream.Close();
            stream.Dispose();
            byte[] b = stream3.ToArray();
            stream3.Close();
            stream3.Dispose();
            return (DataTable) ByteArrayToObject(b);
        }
}

Related Tutorials