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
相关文章
|
5月前
|
XML C# 数据格式
使用C#操作XML文件
使用C#操作XML文件
|
5月前
|
C#
C# 文件操作(全部) 追加、拷贝、删除、移动文件、创建目录
C# 文件操作(全部) 追加、拷贝、删除、移动文件、创建目录
72 0
|
5月前
|
C#
C#读取html文件
C#读取html文件
110 3
|
2月前
|
监控 安全 C#
使用C#如何监控选定文件夹中文件的变动情况?
使用C#如何监控选定文件夹中文件的变动情况?
102 19
|
2月前
|
编译器 C# Windows
C#基础:手动编译一个.cs源代码文件并生成.exe可执行文件
通过上述步骤,应该能够高效准确地编译C#源代码并生成相应的可执行文件。此外,这一过程强调了对命令行编译器的理解,这在调试和自动化编译流程中是非常重要的。
119 2
|
2月前
|
文字识别 C# Python
使用C#将几个Excel文件合并去重分类
使用C#将几个Excel文件合并去重分类
25 3
|
2月前
|
C# 图形学 数据安全/隐私保护
Unity数据加密☀️ 二、使用Rider将C#代码生成DLL文件
Unity数据加密☀️ 二、使用Rider将C#代码生成DLL文件
|
2月前
|
C#
C# 写日志文件
C# 写日志文件
40 0
|
4月前
|
C#
【C#】C#读写Excel文件
【C#】C#读写Excel文件
65 1
|
4月前
|
JavaScript 前端开发 C#
初识Unity——创建代码、场景以及五个常用面板(创建C#代码、打开代码文件、场景的创建、Project、Hierarchy、Inspector、Scene、Game )
初识Unity——创建代码、场景以及五个常用面板(创建C#代码、打开代码文件、场景的创建、Project、Hierarchy、Inspector、Scene、Game )
91 0