Get byte[] from dataset and compress

后端 未结 2 474
感动是毒
感动是毒 2021-01-19 04:25

I am returning a custom class from a WCF operation. The binding used is netTcp. This custom class contains several data members. One of them is a dataset. The dataset can be

2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-19 05:06

    You can just use the following:

            using(var memory = new MemoryStream())
            {
                using(var gzip = new GZipStream(memory, CompressionMode.Compress, true))
                {
                    var formatter = new BinaryFormatter();
                    formatter.Serialize(gzip, ds);
                }
    
                return memory.ToArray();
            }
    

提交回复
热议问题