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

推荐订阅源

博客园_首页
T
The Blog of Author Tim Ferriss
GbyAI
GbyAI
雷峰网
雷峰网
Last Week in AI
Last Week in AI
人人都是产品经理
人人都是产品经理
F
Fortinet All Blogs
酷 壳 – CoolShell
酷 壳 – CoolShell
T
Tailwind CSS Blog
Y
Y Combinator Blog
J
Java Code Geeks
S
SegmentFault 最新的问题
罗磊的独立博客
爱范儿
爱范儿
F
Full Disclosure
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
V
V2EX
G
Google Developers Blog
腾讯CDC
美团技术团队
Martin Fowler
Martin Fowler
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
D
DataBreaches.Net
大猫的无限游戏
大猫的无限游戏
博客园 - 【当耐特】
B
Blog
Recorded Future
Recorded Future
月光博客
月光博客
Blog — PlanetScale
Blog — PlanetScale
IT之家
IT之家
N
Netflix TechBlog - Medium
P
Proofpoint News Feed
云风的 BLOG
云风的 BLOG
博客园 - 聂微东
阮一峰的网络日志
阮一峰的网络日志
B
Blog RSS Feed
aimingoo的专栏
aimingoo的专栏
W
WeLiveSecurity
Recent Announcements
Recent Announcements
P
Palo Alto Networks Blog
Apple Machine Learning Research
Apple Machine Learning Research
MongoDB | Blog
MongoDB | Blog
G
GRAHAM CLULEY
A
Arctic Wolf
AWS News Blog
AWS News Blog
Project Zero
Project Zero
博客园 - Franky
V
Vulnerabilities – Threatpost

博客园 - jerreychen

常用的JavaScript验证正则表达式 用CSS设置打印换页 使用Form认证实现用户登录 (LoginView的使用) 向容器(PlaceHolder)中动态添加多个用户控件(UserControl) C#.Net中WinForm采用Active Directory进行身份认证 Windows XP 如何设置系统自动关机任务 - jerreychen DataList嵌套GridView实现文章分类列表显示(2) visual studio 2008 sp1中如何让WebBrowser控件可编辑 - jerreychen SQLite 数据库初学 学习笔记 - jerreychen - 博客园 如何将.xsd文件自动生成对象 ASP.NET页面事件:顺序与回传详解 读取自定义的config文件 - jerreychen - 博客园 Umbraco 设置Document Types 的默认值 格式化数据 .net 序列化数据对象 .net 下,日期的格式化 太久太久没来了,久违了-博客园 showModelDialog 关闭后改变GridView某个单元格的值
Net支持gzip 压缩格式 压缩与解压
jerreychen · 2008-03-14 · via 博客园 - jerreychen

在网上看到这篇感觉有用,转过来,存下

.Net支持两种压缩格式:GZip和Deflate。其中,GZip可以被WinRAR打开。

使用起来很简单,下面的程序将字符串压缩入文件:

                using (DeflateStream gzip = new DeflateStream(fs, CompressionMode.Compress))
                {
                    
byte[] buf = Encoding.UTF8.GetBytes(this.txbSource.Text);
                    gzip.Write(buf, 
0, buf.Length);
                    gzip.Flush();
                }

解压只需要这样:

            gzip = new GZipStream(new MemoryStream(buf), CompressionMode.Decompress);
            
using (StreamReader reader = new StreamReader(gzip))
            {
                
this.txbTarget.Text = reader.ReadToEnd();
            }

如果从文件解压,只需要把MemoryStream换成一个FileStream就行了。
当然,需要加:using System.IO.Compression;