예제 #1
0
        //public static byte[] CompressStream(object obj)
        //{
        //    byte[] b;
        //    BinaryFormatter bf = new BinaryFormatter();

        //    using (MemoryTributary objStream = new MemoryTributary())
        //    {
        //      //  using (MemoryTributary ms = new MemoryTributary())
        //        using (System.IO.Compression.DeflateStream objZS = new System.IO.Compression.DeflateStream(objStream, System.IO.Compression.CompressionMode.Compress))
        //        {
        //            bf.Serialize(objZS, obj);
        //         //   ms.Position = 0;
        //          //  ms.CopyTo(objZS);
        //        };
        //        b = objStream.ToArray();
        //    };
        //    return b;
        //}

        public static byte[] CompressStream(DataSet ds, bool includeSchema)
        {
            XmlWriteMode xwm;

            if (includeSchema)
            {
                xwm = XmlWriteMode.WriteSchema;
            }
            else
            {
                xwm = XmlWriteMode.IgnoreSchema;
            }



            byte[] b;


            using (MemoryTributary objStream = new MemoryTributary())
            {
                using (System.IO.Compression.DeflateStream deflateStream = new System.IO.Compression.DeflateStream(objStream, System.IO.Compression.CompressionMode.Compress))
                {
                    ds.WriteXml(deflateStream, xwm);
                };
                b = objStream.ToArray();
            };
            return(b);
        }
예제 #2
0
        public static DataSet DecompressDataSet(byte[] bytDs)
        {
            //Debug.Write(bytDs.Length.ToString());

            DataSet outDs = new DataSet();

            using (MemoryTributary inMs = new MemoryTributary(bytDs))
            {
                inMs.Seek(0, 0);

                using (DeflateStream zipStream = new DeflateStream(inMs, CompressionMode.Decompress, true))
                {
                    //    outDs.ReadXml(zipStream, XmlReadMode.DiffGram);
                    BinaryFormatter bf = new BinaryFormatter();
                    outDs = (DataSet)bf.Deserialize(zipStream, null);
                }
            }

            return(outDs);
        }