今天在“Devexpress学习”QQ群(82306553)中学习网友死海里的鱼的方法。
public static byte[] CompressDataSet(DataSet input)
{
AdjustDataSetTimeColumn(input);
// 序列化为二进制
input.RemotingFormat = SerializationFormat.Binary;
BinaryFormatter bFormatter = new BinaryFormatter();
using (MemoryStream mStream = new MemoryStream())
{
bFormatter.Serialize(mStream, input);
byte[] bytes = mStream.ToArray();
// 压缩
using (MemoryStream oStream = new MemoryStream())
{
GZipStream zipStream = new GZipStream(oStream, CompressionMode.Compress);
zipStream.Write(bytes, 0, bytes.Length);
zipStream.Flush();
zipStream.Close();
return oStream.ToArray();
}
}
}