标签:style blog color io os ar sp div on
private byte[] Compression(byte[] data, CompressionMode mode) { DeflateStream zip = null; try { if (mode == CompressionMode.Compress)//压缩函数 { MemoryStream ms = new MemoryStream(); zip = new DeflateStream(ms, mode, true); zip.Write(data, 0, data.Length); zip.Close(); return ms.ToArray(); } else//解压函数 { MemoryStream ms = new MemoryStream(); ms.Write(data, 0, data.Length); ms.Flush(); ms.Position = 0; zip = new DeflateStream(ms, mode, true); MemoryStream os = new MemoryStream(); int SIZE = 1024*100; byte[] buf = new byte[SIZE]; int l = 0; do { l = zip.Read(buf, 0, SIZE); if (l == 0) l = zip.Read(buf, 0, SIZE); os.Write(buf, 0, l); } while (l != 0); zip.Close(); return os.ToArray(); } } catch { if (zip != null) zip.Close(); return null; } finally { if (zip != null) zip.Close(); } }
标签:style blog color io os ar sp div on
原文地址:http://www.cnblogs.com/yuanzhongkui/p/4013064.html