12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- using System.IO;
- using ICSharpCode.SharpZipLib.Zip.Compression;
- namespace ET
- {
- public static class ZipHelper
- {
- public static byte[] Compress(byte[] content)
- {
-
- Deflater compressor = new Deflater();
- compressor.SetLevel(Deflater.BEST_COMPRESSION);
- compressor.SetInput(content);
- compressor.Finish();
- using (MemoryStream bos = new MemoryStream(content.Length))
- {
- var buf = new byte[1024];
- while (!compressor.IsFinished)
- {
- int n = compressor.Deflate(buf);
- bos.Write(buf, 0, n);
- }
- return bos.ToArray();
- }
- }
- public static byte[] Decompress(byte[] content)
- {
- return Decompress(content, 0, content.Length);
- }
- public static byte[] Decompress(byte[] content, int offset, int count)
- {
-
- Inflater decompressor = new Inflater();
- decompressor.SetInput(content, offset, count);
- using (MemoryStream bos = new MemoryStream(content.Length))
- {
- var buf = new byte[1024];
- while (!decompressor.IsFinished)
- {
- int n = decompressor.Inflate(buf);
- bos.Write(buf, 0, n);
- }
- return bos.ToArray();
- }
- }
- }
- }
|