惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

B
Blog RSS Feed
博客园 - 叶小钗
F
Fortinet All Blogs
GbyAI
GbyAI
Martin Fowler
Martin Fowler
博客园 - 聂微东
I
InfoQ
B
Blog
IT之家
IT之家
美团技术团队
L
LangChain Blog
小众软件
小众软件
C
Check Point Blog
MongoDB | Blog
MongoDB | Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
V
V2EX
Last Week in AI
Last Week in AI
A
About on SuperTechFans
博客园 - Franky
P
Proofpoint News Feed
罗磊的独立博客
月光博客
月光博客
V
Visual Studio Blog
MyScale Blog
MyScale Blog

博客园 - 痞子再

介绍50个 WordPress 动作挂钩 决定如何开发你的WordPress主题框架 WordPress 主题框架是如何工作的 WordPress主题制作教程[壹] - 了解WP&结构&索引 jQuery UI Datepicker -- jQuery日历控件中的精品(UI绚丽) godaddy.com免费10G空间申请步骤详解 godaddy免费空间完美安装部署dedecms UrlRewriter使用详解 - 痞子再 - 博客园 google的CDN内容分发网络来加载jQuery库 - 痞子再 - 博客园 利用google API实现全文翻译的Web Service JavaScript模拟进度条 字符串操作类 NET代码积累之一 让visual studio 2005 自动为类加版权 C#日期格式化 UrlRewriter 使用详解 (Friendly Url) web.config中配置字符串中特殊字符的处理 - 痞子再 - 博客园 漂浮层广告代码[层为隐藏,点击广告后层消失][24小时/次] 网页采集时,常用的几种正则表达式 C# Check is No number - 痞子再
压缩和解压缩的方法 from Byte[]
痞子再 · 2008-11-21 · via 博客园 - 痞子再

  public static byte[] Zip(byte[] data)
        {
            MemoryStream mstream = new MemoryStream();
            BZip2OutputStream zipOutStream = new BZip2OutputStream(mstream);
            zipOutStream.Write(data, 0, data.Length);
            zipOutStream.Finalize();
            zipOutStream.Close();

            byte[] result = mstream.ToArray();
            mstream.Close();

            return result;
        }

        public static byte[] Unzip(byte[] data)
        {
            MemoryStream mstream = new MemoryStream(data);
            BZip2InputStream zipInputStream = new BZip2InputStream(mstream);
            byte[] byteUncompressed = new byte[zipInputStream.Length];
            zipInputStream.Read(byteUncompressed, 0, (int)byteUncompressed.Length);

            zipInputStream.Close();
            mstream.Close();

            return byteUncompressed;
        }