123456789101112131415161718192021222324252627282930313233 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO.Compression;
- using System.IO;
- namespace Test.TestPress
- {
- public class CompressUtil
- {
- public static byte[] GetBytes(string str)
- {
- byte[] data = Encoding.UTF8.GetBytes(str.ToString());
- return data;
- }
- public static byte[] GZipCompress(byte[] data)
- {
- byte[] result;
- using (MemoryStream ms = new MemoryStream())
- {
- using (GZipStream compressedzipStream = new GZipStream(ms, CompressionMode.Compress, true))
- {
- compressedzipStream.Write(data, 0, data.Length);
- compressedzipStream.Close();
- }
- result= ms.ToArray();
- }
- return result;
- }
- }
- }
|