本文整理汇总了C#中ICSharpCode.SharpZipLib.Zip.ZipOutputStream类的典型用法代码示例。如果您正苦于以下问题:C# ZipOutputStream类的具体用法?C# ZipOutputStream怎么用?C# ZipOutputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ZipOutputStream类属于ICSharpCode.SharpZipLib.Zip命名空间,在下文中一共展示了ZipOutputStream类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: CompressFilesToOneZipFile
private void CompressFilesToOneZipFile(ICollection<string> inputPaths, string zipFilePath)
{
Log.LogMessage(MessageImportance.Normal, "Zipping " + inputPaths.Count + " files to zip file " + zipFilePath);
using (var fsOut = File.Create(zipFilePath)) // Overwrites previous file
{
using (var zipStream = new ZipOutputStream(fsOut))
{
foreach (var inputPath in inputPaths)
{
zipStream.SetLevel(9); // Highest level of compression
var inputFileInfo = new FileInfo(inputPath);
var newEntry = new ZipEntry(inputFileInfo.Name) { DateTime = inputFileInfo.CreationTime };
zipStream.PutNextEntry(newEntry);
var buffer = new byte[4096];
using (var streamReader = File.OpenRead(inputPath))
{
ICSharpCode.SharpZipLib.Core.StreamUtils.Copy(streamReader, zipStream, buffer);
}
zipStream.CloseEntry();
}
zipStream.IsStreamOwner = true;
zipStream.Close();
}
}
}
开发者ID:bbriggs,项目名称:FieldWorks,代码行数:30,代码来源:ZipTask.cs
示例2: CompressFiles
public static void CompressFiles(IEnumerable<ISong> files, string destinationPath)
{
if (log.IsDebugEnabled)
{
log.Debug("Starting creation of zip file : " + destinationPath);
}
using (ZipOutputStream zipOutputStream = new ZipOutputStream(new FileStream(destinationPath, FileMode.OpenOrCreate)))
{
zipOutputStream.SetLevel(0);
foreach (ISong song in files)
{
FileInfo fileInfo = new FileInfo(song.MediaFilePath);
ZipEntry entry = new ZipEntry(song.Artist.Name + "\\" + song.Album.Name + "\\" + song.Title + fileInfo.Extension);
zipOutputStream.PutNextEntry(entry);
FileStream fs = File.OpenRead(song.MediaFilePath);
byte[] buff = new byte[1024];
int n = 0;
while ((n = fs.Read(buff, 0, buff.Length)) > 0)
{
zipOutputStream.Write(buff, 0, n);
}
fs.Close();
}
zipOutputStream.Finish();
}
if (log.IsDebugEnabled)
{
log.Debug("Zip file created : " + destinationPath);
}
}
开发者ID:BackupTheBerlios,项目名称:molecule-svn,代码行数:34,代码来源:CompressionHelper.cs
示例3: Zip
public void Zip(string outPathname, IList<ZipItem> contents)
{
var outputStream = File.Create(outPathname);
var zipStream = new ZipOutputStream(outputStream);
zipStream.SetLevel(3);
foreach (var item in contents)
{
if (item.IsDirectory)
{
var files = Directory.EnumerateFiles(item.FilePath);
foreach (var file in files)
{
AppendFile(zipStream, item.FolderInZip, file);
}
}
else
{
AppendFile(zipStream, item.FolderInZip, item.FilePath);
}
}
zipStream.IsStreamOwner = true;
zipStream.Close();
}
开发者ID:limitzero,项目名称:db-advance,代码行数:27,代码来源:ZipArchiver.cs
示例4: DownloadAllFiles
public FileResult DownloadAllFiles()
{
var context = System.Web.HttpContext.Current;
var folderPath = context.Server.MapPath("~/UploadedFiles/");
var baseOutputStream = new MemoryStream();
ZipOutputStream zipOutput = new ZipOutputStream(baseOutputStream) {IsStreamOwner = false};
/*
* Higher compression level will cause higher usage of reources
* If not necessary do not use highest level 9
*/
zipOutput.SetLevel(4);
SharpZipLibHelper.ZipFolder(folderPath, zipOutput);
zipOutput.Finish();
zipOutput.Close();
/* Set position to 0 so that cient start reading of the stream from the begining */
baseOutputStream.Position = 0;
/* Set custom headers to force browser to download the file instad of trying to open it */
return new FileStreamResult(baseOutputStream, "application/x-zip-compressed")
{
FileDownloadName = "eResult.zip"
};
}
开发者ID:jeffjuarez,项目名称:OI---All-Charts,代码行数:27,代码来源:EmployeesController.cs
示例5: CreateZipFile
public static void CreateZipFile(string[] filenames, string outputFile)
{
// Zip up the files - From SharpZipLib Demo Code
using (ZipOutputStream s = new ZipOutputStream(File.Create(outputFile)))
{
s.SetLevel(9); // 0-9, 9 being the highest level of compression
byte[] buffer = new byte[4096];
foreach (string file in filenames)
{
ZipEntry entry = new ZipEntry(Path.GetFileName(file));
entry.DateTime = DateTime.Now;
s.PutNextEntry(entry);
using (FileStream fs = File.OpenRead(file))
{
int sourceBytes;
do
{
sourceBytes = fs.Read(buffer, 0, buffer.Length);
s.Write(buffer, 0, sourceBytes);
}
while (sourceBytes > 0);
}
}
s.Finish();
s.Close();
}
}
开发者ID:ronanb67,项目名称:timeflies,代码行数:29,代码来源:ZipOperation.cs
示例6: Page_Load
private void Page_Load(object sender, System.EventArgs e)
{
System.DateTime dateTime = System.DateTime.Now;
string s1 = "Message_Backup_\uFFFD" + dateTime.ToString("ddMMyy_HHmmss\uFFFD") + ".zip\uFFFD";
System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();
ICSharpCode.SharpZipLib.Zip.ZipOutputStream zipOutputStream = new ICSharpCode.SharpZipLib.Zip.ZipOutputStream(memoryStream);
ActiveUp.Net.Mail.Mailbox mailbox = ((ActiveUp.Net.Mail.Imap4Client)Session["imapobject\uFFFD"]).SelectMailbox(Request.QueryString["b\uFFFD"]);
char[] chArr = new char[] { ',' };
string[] sArr = Request.QueryString["m\uFFFD"].Split(chArr);
for (int i = 0; i < sArr.Length; i++)
{
string s2 = sArr[i];
byte[] bArr = mailbox.Fetch.Message(System.Convert.ToInt32(s2));
ActiveUp.Net.Mail.Header header = ActiveUp.Net.Mail.Parser.ParseHeader(bArr);
ICSharpCode.SharpZipLib.Zip.ZipEntry zipEntry = new ICSharpCode.SharpZipLib.Zip.ZipEntry(header.Subject + ".eml\uFFFD");
zipOutputStream.PutNextEntry(zipEntry);
zipOutputStream.SetLevel(9);
zipOutputStream.Write(bArr, 0, bArr.Length);
zipOutputStream.CloseEntry();
}
zipOutputStream.Finish();
Response.AddHeader("Content-Disposition\uFFFD", "attachment; filename=\uFFFD" + s1);
Response.ContentType = "application/zip\uFFFD";
Response.BinaryWrite(memoryStream.GetBuffer());
zipOutputStream.Close();
}
开发者ID:haoasqui,项目名称:MailSystem.NET,代码行数:26,代码来源:DownloadZip.aspx.cs
示例7: SaveImpl
public override bool SaveImpl(XmlDocument content, Stream out1) {
ZipOutputStream zos = null;
if (out1 is ZipOutputStream)
zos = (ZipOutputStream) out1;
else
zos = new ZipOutputStream(out1);
ZipEntry partEntry = new ZipEntry(CONTENT_TYPES_PART_NAME);
try {
// Referenced in ZIP
zos.PutNextEntry(partEntry);
// Saving data in the ZIP file
StreamHelper.SaveXmlInStream(content, out1);
Stream ins = new MemoryStream();
byte[] buff = new byte[ZipHelper.READ_WRITE_FILE_BUFFER_SIZE];
while (true) {
int resultRead = ins.Read(buff, 0, ZipHelper.READ_WRITE_FILE_BUFFER_SIZE);
if (resultRead == 0) {
// end of file reached
break;
} else {
zos.Write(buff, 0, resultRead);
}
}
zos.CloseEntry();
} catch (IOException ioe) {
logger.Log(POILogger.ERROR, "Cannot write: " + CONTENT_TYPES_PART_NAME
+ " in Zip !", ioe);
return false;
}
return true;
}
开发者ID:hanwangkun,项目名称:npoi,代码行数:34,代码来源:ZipContentTypeManager.cs
示例8: ZipFile
public void ZipFile(string FileToZip, string ZipedFile, int CompressionLevel, int BlockSize)
{
//如果文件没有找到,则报错
if (!System.IO.File.Exists(FileToZip))
{
throw new System.IO.FileNotFoundException("The specified file " + FileToZip + " could not be found. Zipping aborderd");
}
System.IO.FileStream StreamToZip = new System.IO.FileStream(FileToZip, System.IO.FileMode.Open, System.IO.FileAccess.Read);
System.IO.FileStream ZipFile = System.IO.File.Create(ZipedFile);
ZipOutputStream ZipStream = new ZipOutputStream(ZipFile);
ZipEntry ZipEntry = new ZipEntry("ZippedFile");
ZipStream.PutNextEntry(ZipEntry);
ZipStream.SetLevel(CompressionLevel);
byte[] buffer = new byte[BlockSize];
System.Int32 size = StreamToZip.Read(buffer, 0, buffer.Length);
ZipStream.Write(buffer, 0, size);
try
{
while (size < StreamToZip.Length)
{
int sizeRead = StreamToZip.Read(buffer, 0, buffer.Length);
ZipStream.Write(buffer, 0, sizeRead);
size += sizeRead;
}
}
catch (System.Exception ex)
{
throw ex;
}
ZipStream.Finish();
ZipStream.Close();
StreamToZip.Close();
}
开发者ID:BlueSky007,项目名称:Demo55,代码行数:34,代码来源:ZipFile.cs
示例9: ZipFileBuilder
public ZipFileBuilder(Stream outStream)
{
zipStream = new ZipOutputStream(outStream);
zipStream.SetLevel(9); //best compression
factory = new ZipEntryFactory(DateTime.Now);
}
开发者ID:chutinhha,项目名称:heradms,代码行数:7,代码来源:ZipFileBuilder.cs
示例10: CompressFile
// Recurses down the folder structure
//
private void CompressFile(string filename, ZipOutputStream zipStream, int fileOffset)
{
var fi = new FileInfo(filename);
var entryName = Path.GetFileName(filename); // Makes the name in zip based on the folder
entryName = ZipEntry.CleanName(entryName); // Removes drive from name and fixes slash direction
var newEntry = new ZipEntry(entryName);
newEntry.DateTime = fi.LastWriteTime; // Note the zip format stores 2 second granularity
// Specifying the AESKeySize triggers AES encryption. Allowable values are 0 (off), 128 or 256.
// newEntry.AESKeySize = 256;
// To permit the zip to be unpacked by built-in extractor in WinXP and Server2003, WinZip 8, Java, and other older code,
// you need to do one of the following: Specify UseZip64.Off, or set the Size.
// If the file may be bigger than 4GB, or you do not need WinXP built-in compatibility, you do not need either,
// but the zip will be in Zip64 format which not all utilities can understand.
// zipStream.UseZip64 = UseZip64.Off;
newEntry.Size = fi.Length;
zipStream.PutNextEntry(newEntry);
// Zip the file in buffered chunks
// the "using" will close the stream even if an exception occurs
var buffer = new byte[4096];
using (var streamReader = File.OpenRead(filename))
{
StreamUtils.Copy(streamReader, zipStream, buffer);
}
zipStream.CloseEntry();
}
开发者ID:OndeVai,项目名称:Shared---Common-code-for-.net-and-MVC-3,代码行数:32,代码来源:ZipFile.cs
示例11: ZipToFile
/// <summary>
/// Zips the files in the specifed directory and outputs the zip file to the specified location.
/// </summary>
/// <param name="zipFilePath">The full path to the output zip file.</param>
/// <returns>The total number of files added to the zip file.</returns>
public int ZipToFile(string zipFilePath)
{
int total = 0;
if (Directory.Exists(DirectoryPath))
{
if (!Directory.Exists(Path.GetDirectoryName(zipFilePath)))
{
Directory.CreateDirectory(Path.GetDirectoryName(zipFilePath));
}
// Create the zip file
//Crc32 crc = new Crc32();
ZipOutputStream zipFile = new ZipOutputStream(File.Create(zipFilePath));
zipFile.UseZip64 = UseZip64.Off;
zipFile.SetLevel(9);
total += ZipFromPath(zipFile, DirectoryPath);
// Close the writer
zipFile.Finish();
zipFile.Close();
}
return total;
}
开发者ID:jeremysimmons,项目名称:sitestarter,代码行数:31,代码来源:DirectoryZipper.cs
示例12: OpenZipStream
private static ZipOutputStream OpenZipStream(Purl path)
{
Stream stream = path.CreateFile();
ZipOutputStream zip = new ZipOutputStream(stream);
zip.SetLevel(5);
return zip;
}
开发者ID:machine,项目名称:machine.partstore,代码行数:7,代码来源:ZipPackager.cs
示例13: Write
// See this link for details on zipping using SharpZipLib: https://github.com/icsharpcode/SharpZipLib/wiki/Zip-Samples#wiki-anchorCreate
public void Write(Cookbookology.Domain.Cookbook cookbook, Stream outputStream)
{
if (cookbook == null) throw new ArgumentNullException("cookbook");
if (outputStream == null) throw new ArgumentNullException("outputStream");
var converter = new MyCookbookConverter();
var mcb = converter.ConvertFromCommon(cookbook);
var ms = new MemoryStream();
var s = new XmlSerializer(typeof(Cookbook));
s.Serialize(ms, mcb);
ms.Position = 0; // reset to the start so that we can write the stream
// Add the cookbook as a single compressed file in a Zip
using (var zipStream = new ZipOutputStream(outputStream))
{
zipStream.SetLevel(3); // compression
zipStream.UseZip64 = UseZip64.Off; // not compatible with all utilities and OS (WinXp, WinZip8, Java, etc.)
var entry = new ZipEntry(mcbFileName);
entry.DateTime = DateTime.Now;
zipStream.PutNextEntry(entry);
StreamUtils.Copy(ms, zipStream, new byte[4096]);
zipStream.CloseEntry();
zipStream.IsStreamOwner = false; // Don't close the outputStream (parameter)
zipStream.Close();
}
}
开发者ID:andrewanderson,项目名称:Cookbookology,代码行数:31,代码来源:MyCookbookParser.cs
示例14: diskLess
public byte[] diskLess()
{
MemoryStream ms = new MemoryStream();
StreamWriter sw = new StreamWriter(ms);
sw.WriteLine("HELLO!");
sw.WriteLine("I WANT TO SAVE THIS FILE AS A .TXT FILE WITHIN TWO FOLDERS");
sw.Flush(); //This is required or you get a blank text file :)
ms.Position = 0;
// create the ZipEntry archive from the txt file in memory stream ms
MemoryStream outputMS = new System.IO.MemoryStream();
ZipOutputStream zipOutput = new ZipOutputStream(outputMS);
ZipEntry ze = new ZipEntry(@"dir1/dir2/whatever.txt");
zipOutput.PutNextEntry(ze);
zipOutput.Write(ms.ToArray(), 0, Convert.ToInt32(ms.Length));
zipOutput.Finish();
zipOutput.Close();
byte[] byteArrayOut = outputMS.ToArray();
outputMS.Close();
ms.Close();
return byteArrayOut;
}
开发者ID:compliashield,项目名称:certificate-issuer,代码行数:27,代码来源:ZipHelper.cs
示例15: Zip
public static void Zip(string strFile, string strZipFile)
{
Crc32 crc1 = new Crc32();
ZipOutputStream stream1 = new ZipOutputStream(File.Create(strZipFile));
try
{
stream1.SetLevel(6);
FileStream stream2 = File.OpenRead(strFile);
byte[] buffer1 = new byte[stream2.Length];
stream2.Read(buffer1, 0, buffer1.Length);
ZipEntry entry1 = new ZipEntry(strFile.Split(new char[] { '\\' })[strFile.Split(new char[] { '\\' }).Length - 1]);
entry1.DateTime = DateTime.Now;
entry1.Size = stream2.Length;
stream2.Close();
crc1.Reset();
crc1.Update(buffer1);
entry1.Crc = crc1.Value;
stream1.PutNextEntry(entry1);
stream1.Write(buffer1, 0, buffer1.Length);
}
catch (Exception exception1)
{
throw exception1;
}
finally
{
stream1.Finish();
stream1.Close();
stream1 = null;
crc1 = null;
}
}
开发者ID:powerhai,项目名称:Jinchen,代码行数:32,代码来源:ZipHelper.cs
示例16: CompressFile
/// <summary>
/// ファイルを圧縮
/// </summary>
/// <param name="filename">ファイル名フルパス</param>
/// <param name="offsetFolderName">圧縮時のルートフォルダのフルパス</param>
/// <param name="zipStream">圧縮先のZipStream</param>
public static void CompressFile(string filename, string offsetFolderName, ZipOutputStream zipStream)
{
//フォルダのオフセット値を取得
var folderOffset = offsetFolderName.Length + (offsetFolderName.EndsWith("\\") ? 0 : 1);
//ファイル名の余計なパスを消す
string entryName = filename.Substring(folderOffset);
entryName = ZipEntry.CleanName(entryName);
//圧縮するファイルを表示←非常に良くない
Console.WriteLine(entryName);
//ファイル情報書き込み
var fi = new FileInfo(filename);
var newEntry = new ZipEntry(entryName)
{
DateTime = fi.LastWriteTime,
Size = fi.Length,
};
zipStream.PutNextEntry(newEntry);
//ファイル内容書き込み
var buffer = new byte[4096];
using (var streamReader = File.OpenRead(filename))
{
StreamUtils.Copy(streamReader, zipStream, buffer);
}
zipStream.CloseEntry();
}
开发者ID:kagerouttepaso,项目名称:PassZipper,代码行数:36,代码来源:ZipTool.cs
示例17: ZipFile
/// <summary>
/// 压缩单个文件
/// </summary>
/// <param name="fileToZip">要进行压缩的文件名</param>
/// <param name="zipedFile">压缩后生成的压缩文件名</param>
/// <param name="level">压缩等级</param>
/// <param name="password">密码</param>
/// <param name="onFinished">压缩完成后的代理</param>
public static void ZipFile(string fileToZip, string zipedFile, string password = "", int level = 5, OnFinished onFinished = null)
{
//如果文件没有找到,则报错
if (!File.Exists(fileToZip))
throw new FileNotFoundException("指定要压缩的文件: " + fileToZip + " 不存在!");
using (FileStream fs = File.OpenRead(fileToZip))
{
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
fs.Close();
using (FileStream ZipFile = File.Create(zipedFile))
{
using (ZipOutputStream ZipStream = new ZipOutputStream(ZipFile))
{
string fileName = fileToZip.Substring(fileToZip.LastIndexOf("/") + 1);
ZipEntry ZipEntry = new ZipEntry(fileName);
ZipStream.PutNextEntry(ZipEntry);
ZipStream.SetLevel(level);
ZipStream.Password = password;
ZipStream.Write(buffer, 0, buffer.Length);
ZipStream.Finish();
ZipStream.Close();
if (null != onFinished) onFinished();
}
}
}
}
开发者ID:ZeroToken,项目名称:MyTools,代码行数:35,代码来源:ZipHelper.cs
示例18: CreateZipFiles
/// <summary>
/// 递归压缩文件
/// </summary>
/// <param name="sourceFilePath">待压缩的文件或文件夹路径</param>
/// <param name="zipStream">打包结果的zip文件路径(类似 D:\WorkSpace\a.zip),全路径包括文件名和.zip扩展名</param>
/// <param name="staticFile"></param>
private static void CreateZipFiles(string sourceFilePath, ZipOutputStream zipStream, string staticFile)
{
Crc32 crc = new Crc32();
string[] filesArray = Directory.GetFileSystemEntries(sourceFilePath);
foreach (string file in filesArray)
{
if (Directory.Exists(file)) //如果当前是文件夹,递归
{
CreateZipFiles(file, zipStream, staticFile);
}
else //如果是文件,开始压缩
{
FileStream fileStream = File.OpenRead(file);
byte[] buffer = new byte[fileStream.Length];
fileStream.Read(buffer, 0, buffer.Length);
string tempFile = file.Substring(staticFile.LastIndexOf("\\") + 1);
ZipEntry entry = new ZipEntry(tempFile);
entry.DateTime = DateTime.Now;
entry.Size = fileStream.Length;
fileStream.Close();
crc.Reset();
crc.Update(buffer);
entry.Crc = crc.Value;
zipStream.PutNextEntry(entry);
zipStream.Write(buffer, 0, buffer.Length);
}
}
}
开发者ID:454240357,项目名称:SmartLaw,代码行数:38,代码来源:ZipHelper.cs
示例19: ZipFiles
public static void ZipFiles(string inputFolderPath, string outputPathAndFile, string password)
{
ArrayList ar = GenerateFileList(inputFolderPath); // generate file list
int TrimLength = (Directory.GetParent(inputFolderPath)).ToString().Length;
// find number of chars to remove // from orginal file path
TrimLength += 1; //remove '\'
FileStream ostream;
byte[] obuffer;
string outPath = outputPathAndFile;
ZipOutputStream oZipStream = new ZipOutputStream(File.Create(outPath)); // create zip stream
if (password != null && password != String.Empty)
oZipStream.Password = password;
oZipStream.SetLevel(9); // maximum compression
ZipEntry oZipEntry;
foreach (string Fil in ar) // for each file, generate a zipentry
{
oZipEntry = new ZipEntry(Fil.Remove(0, TrimLength));
oZipStream.PutNextEntry(oZipEntry);
if (!Fil.EndsWith(@"/")) // if a file ends with '/' its a directory
{
ostream = File.OpenRead(Fil);
obuffer = new byte[ostream.Length];
ostream.Read(obuffer, 0, obuffer.Length);
oZipStream.Write(obuffer, 0, obuffer.Length);
}
}
oZipStream.Finish();
oZipStream.Close();
oZipStream.Dispose();
}
开发者ID:RexSystemsbd,项目名称:SageFrameV2.1Source,代码行数:31,代码来源:ZipUtil.cs
示例20: AddEntryAfterFinish
public void AddEntryAfterFinish()
{
MemoryStream ms = new MemoryStream();
ZipOutputStream s = new ZipOutputStream(ms);
s.Finish();
s.PutNextEntry(new ZipEntry("dummyfile.tst"));
}
开发者ID:BackupTheBerlios,项目名称:storm-ircd-svn,代码行数:7,代码来源:ZipTests.cs
注:本文中的ICSharpCode.SharpZipLib.Zip.ZipOutputStream类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论