C#中用SharpZipLib生成gzip/解压文件

Code tells all:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using  System;
using  System.IO;
using  ICSharpCode.SharpZipLib.GZip;
using  ICSharpCode.SharpZipLib.Core;
 
namespace  CNKIDataExport
{
     class  Program
     {
         public  static  void  gZipFile( string  filePath,  string  zipFilePath)
         {
             Stream s =  new  GZipOutputStream(File.Create(zipFilePath));
             FileStream fs = File.OpenRead(filePath);
             int  size;
             byte [] buf =  new  byte [4096];
             do
             {
                 size = fs.Read(buf, 0, buf.Length);
                 s.Write(buf, 0, size);
             while  (size > 0);
             s.Close();
             fs.Close();
         }
 
         public  static  void  gunZipFile( string  zipFilePath,  string  filePath)
         {
             using  (Stream inStream =  new  GZipInputStream(File.OpenRead(zipFilePath)))
             using  (FileStream outStream = File.Create(filePath))
             {
                 byte [] buf =  new  byte [4096];
                 StreamUtils.Copy(inStream, outStream, buf);
             }
         }
 
         static  void  Main( string [] args)
         {
             string  src =  @"D:\test\in.txt"
             string  dest =  @"D:\test\out.gz"
             string  ori =  @"D:\test\ori.txt"
 
             gZipFile(src, dest);
             Console.WriteLine( "gzip over!" );
             gunZipFile(dest, ori);
             Console.WriteLine( "gunzip over!" );
             Console.ReadKey();
         }
     }
}


相关链接:

1、SharpZipLib下载

2、Using SharpZipLib to gzip a file

3、ICSharpCode.SharpZipLib.GZip.GZipInputStream Class Reference

4、C#利用SharpZipLib解压或压缩文件夹实例操作(ZIP格式)


*** walker ***

本文转自walker snapshot博客51CTO博客,原文链接http://blog.51cto.com/walkerqt/1706239如需转载请自行联系原作者

RQSLT
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值