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

推荐订阅源

A
Arctic Wolf
F
Fortinet All Blogs
酷 壳 – CoolShell
酷 壳 – CoolShell
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
C
Check Point Blog
P
Proofpoint News Feed
aimingoo的专栏
aimingoo的专栏
Blog — PlanetScale
Blog — PlanetScale
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Recent Announcements
Recent Announcements
L
LangChain Blog
B
Blog RSS Feed
Application and Cybersecurity Blog
Application and Cybersecurity Blog
O
OpenAI News
V
Vulnerabilities – Threatpost
G
Google Developers Blog
博客园 - 三生石上(FineUI控件)
T
Troy Hunt's Blog
P
Proofpoint News Feed
D
Darknet – Hacking Tools, Hacker News & Cyber Security
V
V2EX
H
Help Net Security
MongoDB | Blog
MongoDB | Blog
N
Netflix TechBlog - Medium
Know Your Adversary
Know Your Adversary
P
Privacy & Cybersecurity Law Blog
博客园 - Franky
Microsoft Azure Blog
Microsoft Azure Blog
TaoSecurity Blog
TaoSecurity Blog
I
Intezer
W
WeLiveSecurity
Cisco Talos Blog
Cisco Talos Blog
WordPress大学
WordPress大学
L
Lohrmann on Cybersecurity
Spread Privacy
Spread Privacy
Google Online Security Blog
Google Online Security Blog
Schneier on Security
Schneier on Security
Cloudbric
Cloudbric
U
Unit 42
S
Security Affairs
大猫的无限游戏
大猫的无限游戏
F
Full Disclosure
T
Threatpost
Hacker News - Newest:
Hacker News - Newest: "LLM"
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Engineering at Meta
Engineering at Meta
Hacker News: Ask HN
Hacker News: Ask HN
Stack Overflow Blog
Stack Overflow Blog
T
Tor Project blog
Microsoft Security Blog
Microsoft Security Blog

博客园 - 阿齐

2013年1月18日 星期五 如何修改Panorama控件的Title 分享好用的截屏软件:SnagIt [转]如何在Windows Server 2012中安装.Net Framework 3.5? 屌丝笔记本玩Windows Phone 8开发(在Windows Server 2012中安装WP8 SDK) 在Ubuntu下的Firefox地址栏点击全选网页地址 Ubuntu下的Firefox差点让我崩溃 如何判断文本文件的编码方式? 使用Base64编码数据量变大33.4% 旧文一篇:7年项目总结 在.Net中将MailMessage保存为本地eml文件 创业之三要素 让MSN Messager(Windows Live Messager)重回托盘 创业的Idea是怎样产生的? 我的恩师白玉玺先生-----转自北京崇文汇通武术网站,作者:柳宗林 记录一把,两个截取HTTP请求的工具 标记一下:两个免费的SVN服务 需要使用计算器才能做的投资,通常都不是好投资 解决“A problem has been encountered while loading the setup components. Canceling setup.”的问题 己丑年正月十九北京随想
使用ICSharpCode.SharpZLib压缩/解压给定的数据
阿齐 · 2010-11-08 · via 博客园 - 阿齐

先介绍一下ICSharpCode.SharpZLib的几个代码入口

  1. ZipOutputStream,提供数据压缩功能代码入口;
  2. ZipInputStream,提供数据解压功能代码入口;
  3. ZipEntry,压缩和解药的数据单元描述。

下面是简单的代码:

/*压缩数据*/

public static byte[] Compress(byte[] content)
{
    using (var memory = new MemoryStream())
    {
        var entry = new ZipEntry("email") { DateTime = DateTime.Now };
        var output = new ZipOutputStream(memory);
        output.SetLevel(9);
        output.PutNextEntry(entry);
        output.Write(content, 0, content.Length);
        output.Flush();
        output.Close();

        return memory.ToArray();
    }
}

/*解压数据*/

public static Dictionary<string, byte[]> Decompress(byte[] content)
{
    var dictionary = new Dictionary<string, byte[]>();
    var input = new MemoryStream(content);
    var zip = new ZipInputStream(input);
    try
    {
        ZipEntry entry;
        while ((entry = zip.GetNextEntry()) != null)
        {
            using (var output = new MemoryStream())
            {
                var buffer = new byte[2048];
                while (true)
                {
                    var size = zip.Read(buffer, 0, buffer.Length);
                    if (size == 0)
                    {
                        output.Flush();
                        dictionary[entry.Name] = output.ToArray();
                    }

                    output.Write(buffer, 0, size);
                }
            }
        }

        return dictionary;
    }
    finally
    {
        zip.Dispose();
        input.Dispose();
    }
}