[转][C#]压缩解压缩类 GZipStream
using System;
using System.IO;
using System.IO.Compression; namespace zip
{ public class Program
{ public static void Main()
{
// Path to directory of files to compress and decompress.
string dirpath = @"c:\users\public\reports"; DirectoryInfo di = new DirectoryInfo(dirpath); // Compress the directory's files.
foreach (FileInfo fi in di.GetFiles())
{
Compress(fi); } // Decompress all *.gz files in the directory.
foreach (FileInfo fi in di.GetFiles("*.gz"))
{
Decompress(fi); } } public static void Compress(FileInfo fi)
{
// Get the stream of the source file.
using (FileStream inFile = fi.OpenRead())
{
// Prevent compressing hidden and
// already compressed files.
if ((File.GetAttributes(fi.FullName)
& FileAttributes.Hidden)
!= FileAttributes.Hidden & fi.Extension != ".gz")
{
// Create the compressed file.
using (FileStream outFile =
File.Create(fi.FullName + ".gz"))
{
using (GZipStream Compress =
new GZipStream(outFile,
CompressionMode.Compress))
{
// Copy the source file into
// the compression stream.
inFile.CopyTo(Compress); Console.WriteLine("Compressed {0} from {1} to {2} bytes.",
fi.Name, fi.Length.ToString(), outFile.Length.ToString());
}
}
}
}
} public static void Decompress(FileInfo fi)
{
// Get the stream of the source file.
using (FileStream inFile = fi.OpenRead())
{
// Get original file extension, for example
// "doc" from report.doc.gz.
string curFile = fi.FullName;
string origName = curFile.Remove(curFile.Length -
fi.Extension.Length); //Create the decompressed file.
using (FileStream outFile = File.Create(origName))
{
using (GZipStream Decompress = new GZipStream(inFile,
CompressionMode.Decompress))
{
// Copy the decompression stream
// into the output file.
Decompress.CopyTo(outFile); Console.WriteLine("Decompressed: {0}", fi.Name); }
}
}
} }
}
[转][C#]压缩解压缩类 GZipStream的更多相关文章
- [压缩解压缩] SharpZip--压缩、解压缩帮助类
里面有三个类都是用于压缩和解压缩的.大家看下图片 看下面代码吧 /// <summary> /// 类说明:SharpZip /// 编 码 人:苏飞 /// 联系方式:361983679 ...
- Qt之QuaZIP(zip压缩/解压缩)
简述 QuaZIP是使用Qt/C++对ZLIB进行简单封装的用于压缩及解压缩ZIP的开源库.适用于多种平台,利用它可以很方便的将单个或多个文件打包为zip文件,且打包后的zip文件可以通过其它工具打开 ...
- hadoop的压缩解压缩,reduce端join,map端join
hadoop的压缩解压缩 hadoop对于常见的几种压缩算法对于我们的mapreduce都是内置支持,不需要我们关心.经过map之后,数据会产生输出经过shuffle,这个时候的shuffle过程特别 ...
- Hadoop案例(二)压缩解压缩
压缩/解压缩案例 一. 对数据流的压缩和解压缩 CompressionCodec有两个方法可以用于轻松地压缩或解压缩数据.要想对正在被写入一个输出流的数据进行压缩,我们可以使用createOutput ...
- Qt之zip压缩/解压缩(QuaZIP)
摘要: 简述 QuaZIP是使用Qt/C++对ZLIB进行简单封装的用于压缩及解压缩ZIP的开源库.适用于多种平台,利用它可以很方便的将单个或多个文件打包为zip文件,且打包后的zip文件可以通过其它 ...
- Linux下的压缩解压缩命令详解
linux zip命令zip -r myfile.zip ./*将当前目录下的所有文件和文件夹全部压缩成myfile.zip文件,-r表示递归压缩子目录下所有文件. 2.unzipunzip -o - ...
- Linux/centos/redhat下各种压缩解压缩方式详解
1.zip命令 zip -r myfile.zip ./* 将当前目录下的所有文件和文件夹全部压缩成myfile.zip文件,-r表示递归压缩子目录下所有文件. 2.unzip unzip -o -d ...
- ICSharpCode.SharpZipLib实现压缩解压缩
最近,在项目中经常需要处理压缩和解压缩文件的操作.经过查找,发现了ICSharpCode.SharpZipLib.dll ,这是一个完全由c#编写的Zip, GZip.Tar . BZip2 类库,可 ...
- 使用 apache ant 轻松实现文件压缩/解压缩(转)
原文地址:http://blog.csdn.net/irvine007/article/details/6779492 maven配置ant包: <dependency> <grou ...
随机推荐
- 【转载】hibernate缓存机制
一级缓存(session级别) 我们来看看hibernate提供的一级缓存 //此时会发出一条sql,将所有学生全部查询出来,并放到session的一级缓存当中.当再次查询学生信息时,会首先去缓存中看 ...
- Python学习札记(二十八) 模块1
参考:模块 NOTE 1.模块:一个.py文件称为一个模块. 2.代码模块化的意义:a.提升程序的可维护性 b.不用重复造轮子 3.避免模块冲突,解决方法:引入了按目录来组织模块的方法,称为包(Pac ...
- SPOJ—VLATTICE Visible Lattice Points(莫比乌斯反演)
http://www.spoj.com/problems/VLATTICE/en/ 题意: 给一个长度为N的正方形,从(0,0,0)能看到多少个点. 思路:这道题其实和能量采集是差不多的,只不过从二维 ...
- Validate Binary Search Tree,判断是否是二叉排序树
算法分析:两种方法,一种是中序遍历,然后得到一个序列,看序列是否是有序的.第二种,是用递归. 中序遍历: public class Solution { List<Integer> lis ...
- PHP如何生成文章预览图
PHP如何生成文章预览图 一.总结 一句话总结:php的wkhtmltox扩展,php官方文档有怎么使用,或者github,或者百度,等等等等 wkhtmltox 1.PHP如何自动生成文章预览图? ...
- VAE--就是AutoEncoder的编码输出服从正态分布
花式解释AutoEncoder与VAE 什么是自动编码器 自动编码器(AutoEncoder)最开始作为一种数据的压缩方法,其特点有: 1)跟数据相关程度很高,这意味着自动编码器只能压缩与训练数据相似 ...
- oracle非空约束
ALTER TABLE TB_ZJGL_DWSB_GRMX_LOG MODIFY HJQX NULL;
- 一次SQLServer索引损坏问题的排查与修复
线上库执行一项数据变更操作时,一直提示"出现错误 8646.请记录该错误和时间,并与您的系统管理员联系." 通过代码排查,最终确定是在执行某存储过程时触发了如下错误,并指明了位置是 ...
- Beta发布
作业要求[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2408] 视频展示 链接[https://www.cnblogs.com/erc ...
- Sqlserver 按照时间段统计数据
WITH t1 ( [hour], title ) , ' 0:00:00--- 1:00:00' UNION ALL , ' 1:00:00--- 2:00:00' UNION ALL , ' 2: ...