sharpziplib

C# ICSharpCode.SharpZipLib 压缩、解压文件 附源码

守給你的承諾、 提交于 2019-12-04 07:54:24
http://www.icsharpcode.net/opensource/sharpziplib/ 有SharpZiplib的最新版本,本文使用的版本为0.86.0.518,支持Zip, GZip, BZip2 和Tar格式。我们需要dll 在官网上也有。 好了,深入的大家还要多多研究,今天我们简单介绍一下 简单的 单文件、文件夹的压缩和解压 先给大家看一下效果: 一、引入ICSharpCode.SharpZipLib 我们新建个帮助类 ZipHelper.cs 然后 添加 dll 引用 二、添加完dll引用之后 我们 需要添加 这几个Using引用 1 using ICSharpCode.SharpZipLib.Checksums; 2 using ICSharpCode.SharpZipLib.Zip; 3 using System;4 using System.IO; 三、压缩单个文件 这里我添加了几个参数 大家可以根据自己的需要 修改一下 1 /// <summary> 2 /// ZIP:压缩单个文件 3 /// add yuangang by 2016-06-13 4 /// </summary> 5 /// <param name="FileToZip">需要压缩的文件(绝对路径)</param> 6 /// <param name="ZipedPath"

C# 利用SharpZipLib生成压缩包

可紊 提交于 2019-12-04 07:51:12
本文通过一个简单的小例子简述SharpZipLib压缩文件的常规用法,仅供学习分享使用,如有不足之处,还请指正。 什么是SharpZipLib ? SharpZipLib是一个C#的类库,主要用来解压缩Zip,GZip,BZip2,Tar等格式,是以托管程序集的方式实现,可以方便的应用于其他的项目之中。 在工程中引用SharpZipLib 在项目中,点击项目名称右键-->管理NuGet程序包,打开NuGet包管理器窗口,进行搜索下载即可,如下图所示: SharpZipLib的关键类结构图 如下所示: 涉及知识点: ZipOutputStream 压缩输出流,将文件一个接一个的写入压缩文档,此类不是线程安全的。 PutNextEntry 开始一个新的ZIP条目,ZipOutputStream中的方法。 ZipEntry 一个ZIP文件中的条目,可以理解为压缩包里面的一个文件夹/文件。 ZipInputStream 解压缩输出流,从压缩包中一个接一个的读出文档。 GetNextEntry 读出ZIP条目,ZipInputStream中的方法。 示例效果图: 关于解压缩小例子的示例效果图,如下: 核心代码 1 using ICSharpCode.SharpZipLib.Checksum; 2 using ICSharpCode.SharpZipLib.Zip; 3 using

C# with SharpZipLib - Compatibility of SharpZipLib with Winzip and XP?

大憨熊 提交于 2019-12-03 20:04:48
问题 I am using the CSharpZipLib library to automatically zip some files. The problem is that the resulting zip file doesn't work with Winzip (version 8.1) or XP's compressed folders. It does work with 7zip. Winzip gives an error that this file is not in the standard Zip 2.0 format . Is there a parameter that I can change that would get the library to compress in a Winzip/XP compatible format? 回答1: Set this in your ZipOutputStream: UseZip64 = ICSharpCode.SharpZipLib.Zip.UseZip64.Off Zip64 is not

sharpziplib - can you add a file without it copying the entire zip first?

回眸只為那壹抹淺笑 提交于 2019-12-02 05:34:37
问题 Im trying to add a file to an existing .zip file using sharpziplib - problem is, the zip file is 1GB in size. When i try to add 1 small file (400k) sharpziplib creates a copy/temp of the orig zip file before adding the new file - this poses a problem when the amount of free disk space is less than 2x the zip file you are trying to update. for example: 1GB zip myfile.zip 1GB zip myfile.zip.tmp.293 ZipFile zf = new ZipFile(path); zf.BeginUpdate(); zf.Add(file); // Adding a 400k file here causes

sharpziplib - can you add a file without it copying the entire zip first?

天涯浪子 提交于 2019-12-02 02:06:14
Im trying to add a file to an existing .zip file using sharpziplib - problem is, the zip file is 1GB in size. When i try to add 1 small file (400k) sharpziplib creates a copy/temp of the orig zip file before adding the new file - this poses a problem when the amount of free disk space is less than 2x the zip file you are trying to update. for example: 1GB zip myfile.zip 1GB zip myfile.zip.tmp.293 ZipFile zf = new ZipFile(path); zf.BeginUpdate(); zf.Add(file); // Adding a 400k file here causes a 1GB temp file to be created zf.EndUpdate(); zf.Close(); Is there a more efficient way to do this?

C# with SharpZipLib - Compatibility of SharpZipLib with Winzip and XP?

懵懂的女人 提交于 2019-11-30 14:23:16
I am using the CSharpZipLib library to automatically zip some files. The problem is that the resulting zip file doesn't work with Winzip (version 8.1) or XP's compressed folders. It does work with 7zip. Winzip gives an error that this file is not in the standard Zip 2.0 format . Is there a parameter that I can change that would get the library to compress in a Winzip/XP compatible format? Set this in your ZipOutputStream: UseZip64 = ICSharpCode.SharpZipLib.Zip.UseZip64.Off Zip64 is not compatible with the Windows XP compressed folders utility or with WinZip. Edit: apparently the API has

c# sharpziplib adding file to existing archive

扶醉桌前 提交于 2019-11-29 13:50:45
am trying to add a file to an existing archive using the following code. When run no errors or exceptions are shown but no files are added to the archive either. Any ideas why? using (FileStream fileStream = File.Open(archivePath, FileMode.Open, FileAccess.ReadWrite)) using (ZipOutputStream zipToWrite = new ZipOutputStream(fileStream)) { zipToWrite.SetLevel(9); using (FileStream newFileStream = File.OpenRead(sourceFiles[0])) { byte[] byteBuffer = new byte[newFileStream.Length - 1]; newFileStream.Read(byteBuffer, 0, byteBuffer.Length); ZipEntry entry = new ZipEntry(sourceFiles[0]); zipToWrite

C#.net identify zip file

≡放荡痞女 提交于 2019-11-27 22:54:24
I am currently using the SharpZip api to handle my zip file entries. It works splendid for zipping and unzipping. Though, I am having trouble identifying if a file is a zip or not. I need to know if there is a way to detect if a file stream can be decompressed. Originally I used FileStream lFileStreamIn = File.OpenRead(mSourceFile); lZipFile = new ZipFile(lFileStreamIn); ZipInputStream lZipStreamTester = new ZipInputStream(lFileStreamIn, mBufferSize);// not working lZipStreamTester.Read(lBuffer, 0, 0); if (lZipStreamTester.CanDecompressEntry) { The LZipStreamTester becomes null every time and

Using SharpZipLib to unzip specific files?

淺唱寂寞╮ 提交于 2019-11-27 18:31:13
I'm trying to use SharpZipLib to pull specified files from a zip archive. All of the examples I've seen always expect that you want to unzip the entire zip, and do something along the lines of: FileStream fileStreamIn = new FileStream (sourcePath, FileMode.Open, FileAccess.Read); ZipInputStream zipInStream = new ZipInputStream(fileStreamIn); ZipEntry entry; while (entry = zipInStream.GetNextEntry() != null) { // Unzip file } What I want to do is something like: ZipEntry entry = zipInStream.SeekToFile("FileName"); As my needs involve using a zip as a package and only grabbing files into memory

How do I correctly prepare an 'HTTP Redirect Binding' SAML Request using C#

孤街醉人 提交于 2019-11-27 05:41:28
问题 I need to create an SP initiated SAML 2.0 Authentication transaction using HTTP Redirect Binding method. It turns out this is quite easy. Just get the IdP URI and concatenate a single query-string param SAMLRequest . The param is an encoded block of xml that describes the SAML request. So far so good. The problem comes when converting the SAML into the query string param. I believe this process of preparation should be: Build a SAML string Compress this string Base64 encode the string