博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
The Zip, GZip, BZip2 and Tar Implementation For .NET
阅读量:6856 次
发布时间:2019-06-26

本文共 3668 字,大约阅读时间需要 12 分钟。

#ziplib (SharpZipLib, formerly NZipLib) is a Zip, GZip, Tar and BZip2 library written entirely in C# for the .NET platform. It is implemented

as an assembly (installable in the GAC), and thus can easily be incorporated into other projects (in any .NET language). The creator of #ziplib put it this
way: "I've ported the zip library over to C# because I needed gzip/zip compression and I didn't want to use libzip.dll or something like this. I want
all in pure C#."

Ref:

Ref:

Example:

Reference:ICSharpCode.SharpZipLib.dll----------------------------------------------using System.IO;using ICSharpCode.SharpZipLib.Core;using ICSharpCode.SharpZipLib.Zip;string sourceDir = "d:\\ziptest";string targetZipDir = "d:\\ziptest\\zip";string targetUnZipDir = "d:\\ziptest\\unzip";string targetZipFile = "d:\\ziptest\\zip\\temp";
Init
var astrFileNames = Directory.GetFiles(sourceDir);            if (!Directory.Exists(targetZipDir))            {                Directory.CreateDirectory(targetZipDir);            }            var strmZipOutputStream = new ZipOutputStream(File.Create(targetZipFile));            try            {                strmZipOutputStream.SetLevel(9);                byte[] abyBuffer = new byte[4096];                foreach (var strFile in astrFileNames)                {                    var strmFile = File.OpenRead(strFile);                    try                    {                        var objZipEntry = new ZipEntry(strFile);                        objZipEntry.DateTime = DateTime.Now;                        objZipEntry.Size = strmFile.Length;                        strmZipOutputStream.PutNextEntry(objZipEntry);                        StreamUtils.Copy(strmFile, strmZipOutputStream, abyBuffer);                    }                    finally                    {                        strmFile.Close();                    }                }                strmZipOutputStream.Finish();            }            finally            {                strmZipOutputStream.Close();            }
Zip Code
try            {                using (ZipInputStream s = new ZipInputStream(File.OpenRead(targetZipFile)))                {                    ZipEntry theEntry;                    while ((theEntry = s.GetNextEntry()) != null)                    {                        string fileName = Path.GetFileName(theEntry.Name);                        if (!Directory.Exists(targetUnZipDir))                        {                            Directory.CreateDirectory(targetUnZipDir);                        }                        if (fileName != String.Empty)                        {                            using (FileStream streamWriter = File.Create(targetUnZipDir + "\\" + Path.GetFileName(theEntry.Name)))                            {                                int size = 2048;                                byte[] data = new byte[2048];                                while (true)                                {                                    size = s.Read(data, 0, data.Length);                                    if (size > 0)                                    {                                        streamWriter.Write(data, 0, size);                                    }                                    else                                    {                                        break;                                    }                                }                            }                        }                    }                }            }            catch (Exception ex)            {                throw ex;            }
UnZip Code

 

转载于:https://www.cnblogs.com/ncore/p/3225590.html

你可能感兴趣的文章
理解Docker容器的进程管理
查看>>
微信小程序独家秘笈之左滑删除
查看>>
Using Oracle's Parallel Execution Features
查看>>
[轉]发布时出现PHP has encountered a Stack overflow 解决办法
查看>>
substitute Simple JavaScript Template :
查看>>
9、如何清空流及缓存
查看>>
gvim汉化及配置
查看>>
ubuntu下JMF RTP不支持单播接收
查看>>
fastboot烧写命令
查看>>
深度测试与alpha混合(1)
查看>>
15幅非常有创意的影子摄影作品欣赏
查看>>
lightbox源码解析
查看>>
SQL Server 2008 VALUES
查看>>
[算法] 已知在平面坐标系内有N个点,求离开给定坐标距离最近的10个点
查看>>
使用DMV和DMF分析数据库性能
查看>>
PHP验证IP地址输入的准确性:数组数值验证
查看>>
Linux c 中alarm,signal,pause的使用说明
查看>>
数据源控件的ASP.NET参数
查看>>
HTML5中custom data-*特性与asp.net mvc 3 表单验证
查看>>
NYoj 14会场安排问题
查看>>