首页 > 代码库 > 压缩解压函数实现
压缩解压函数实现
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(); } }
压缩解压函数实现
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。