本文整理汇总了C#中ICSharpCode.SharpZipLib.Zip.ZipEntry类的典型用法代码示例。如果您正苦于以下问题:C# ZipEntry类的具体用法?C# ZipEntry怎么用?C# ZipEntry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ZipEntry类属于ICSharpCode.SharpZipLib.Zip命名空间,在下文中一共展示了ZipEntry类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Save
public void Save(string extPath)
{
// https://forums.xamarin.com/discussion/7499/android-content-getexternalfilesdir-is-it-available
Java.IO.File sd = Android.OS.Environment.ExternalStorageDirectory;
//FileStream fsOut = File.Create(sd.AbsolutePath + "/Android/data/com.FSoft.are_u_ok_/files/MoodData.zip");
FileStream fsOut = File.Create(extPath + "/MoodData.zip");
//https://github.com/icsharpcode/SharpZipLib/wiki/Zip-Samples
ZipOutputStream zipStream = new ZipOutputStream(fsOut);
zipStream.SetLevel (3); //0-9, 9 being the highest level of compression
zipStream.Password = "Br1g1tte"; // optional. Null is the same as not setting. Required if using AES.
ZipEntry newEntry = new ZipEntry ("Mood.csv");
newEntry.IsCrypted = true;
zipStream.PutNextEntry (newEntry);
// Zip the file in buffered chunks
// the "using" will close the stream even if an exception occurs
byte[ ] buffer = new byte[4096];
string filename = extPath + "/MoodData.csv";
using (FileStream streamReader = File.OpenRead(filename)) {
StreamUtils.Copy(streamReader, zipStream, buffer);
}
zipStream.CloseEntry ();
zipStream.IsStreamOwner = true; // Makes the Close also Close the underlying stream
zipStream.Close ();
}
开发者ID:fsoyka,项目名称:RUOK,代码行数:27,代码来源:ZIPHelper.cs
示例2: 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
示例3: ZipDir
/// <summary>
/// 压缩文件夹
/// </summary>
/// <param name="dirToZip"></param>
/// <param name="zipedFileName"></param>
/// <param name="compressionLevel">压缩率0(无压缩)9(压缩率最高)</param>
public void ZipDir(string dirToZip, string zipedFileName, int compressionLevel = 9)
{
if (Path.GetExtension(zipedFileName) != ".zip")
{
zipedFileName = zipedFileName + ".zip";
}
using (var zipoutputstream = new ZipOutputStream(File.Create(zipedFileName)))
{
zipoutputstream.SetLevel(compressionLevel);
var crc = new Crc32();
var fileList = GetAllFies(dirToZip);
foreach (DictionaryEntry item in fileList)
{
var fs = new FileStream(item.Key.ToString(), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
var buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
// ZipEntry entry = new ZipEntry(item.Key.ToString().Substring(dirToZip.Length + 1));
var entry = new ZipEntry(Path.GetFileName(item.Key.ToString()))
{
DateTime = (DateTime) item.Value,
Size = fs.Length
};
fs.Close();
crc.Reset();
crc.Update(buffer);
entry.Crc = crc.Value;
zipoutputstream.PutNextEntry(entry);
zipoutputstream.Write(buffer, 0, buffer.Length);
}
}
}
开发者ID:lizhi5753186,项目名称:QDF,代码行数:37,代码来源:ZipHelper.cs
示例4: 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
示例5: CreateToMemoryStream
private static void CreateToMemoryStream(IEnumerable<Tuple<string, Stream>> entries, string zipName)
{
MemoryStream outputMemStream = new MemoryStream();
ZipOutputStream zipStream = new ZipOutputStream(outputMemStream);
zipStream.SetLevel(3); //0-9, 9 being the highest level of compression
foreach (var entry in entries)
{
ZipEntry newEntry = new ZipEntry(entry.Item1);
newEntry.DateTime = DateTime.Now;
zipStream.PutNextEntry(newEntry);
StreamUtils.Copy(entry.Item2, zipStream, new byte[4096]);
zipStream.CloseEntry();
}
zipStream.IsStreamOwner = false; // False stops the Close also Closing the underlying stream.
zipStream.Close(); // Must finish the ZipOutputStream before using outputMemStream.
outputMemStream.Position = 0;
File.WriteAllBytes(zipName, outputMemStream.ToArray());
//// Alternative outputs:
//// ToArray is the cleaner and easiest to use correctly with the penalty of duplicating allocated memory.
//byte[] byteArrayOut = outputMemStream.ToArray();
//// GetBuffer returns a raw buffer raw and so you need to account for the true length yourself.
//byte[] byteArrayOut = outputMemStream.GetBuffer();
//long len = outputMemStream.Length;
}
开发者ID:BredStik,项目名称:ImageResizer,代码行数:32,代码来源:CoordinatorActor.cs
示例6: zip
private void zip(string strFile, ZipOutputStream s, string staticFile)
{
if (strFile[strFile.Length - 1] != Path.DirectorySeparatorChar) strFile += Path.DirectorySeparatorChar;
Crc32 crc = new Crc32();
string[] filenames = Directory.GetFileSystemEntries(strFile);
foreach (string file in filenames)
{
if (Directory.Exists(file))
{
zip(file, s, staticFile);
}
else // 否则直接压缩文件
{
//打开压缩文件
FileStream fs = File.OpenRead(file);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
string tempfile = file.Substring(staticFile.LastIndexOf("\\") + 1);
ZipEntry entry = new ZipEntry(tempfile);
entry.DateTime = DateTime.Now;
entry.Size = fs.Length;
fs.Close();
crc.Reset();
crc.Update(buffer);
entry.Crc = crc.Value;
s.PutNextEntry(entry);
s.Write(buffer, 0, buffer.Length);
}
}
}
开发者ID:MasterKongKong,项目名称:eReim,代码行数:30,代码来源:ZipFloClass.cs
示例7: 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
示例8: Decompress
public void Decompress(ZipEntry file, Stream str) {
int size;
while (true) {
size = zipIn.Read(buf, 0, buf.Length); if (size <= 0) break;
str.Write(buf, 0, (int)size);
}
}
开发者ID:PavelPZ,项目名称:NetNew,代码行数:7,代码来源:ZipUtils.cs
示例9: 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
示例10: 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
示例11: ClsZipFileItem
public ClsZipFileItem(string zipPath, ZipEntry entry)
: base(entry.Name, entry.DateTime)
{
_path = entry.Name;
_entry = entry;
_zipPath = zipPath;
}
开发者ID:amirsalah,项目名称:moonview,代码行数:7,代码来源:ClsZipFileItem.cs
示例12: 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
示例13: CompressContent
/// <summary>
/// Compress an string using ZIP
/// </summary>
/// <param name="xml"></param>
/// <returns></returns>
public static byte[] CompressContent(string contentToZip)
{
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
byte[] buff = encoding.GetBytes(contentToZip);
try
{
using (MemoryStream stream = new MemoryStream())
{
using (ZipOutputStream zipout = new ZipOutputStream(stream))
{
zipout.SetLevel(9);
ZipEntry entry = new ZipEntry("zipfile.zip");
entry.DateTime = DateTime.Now;
zipout.PutNextEntry(entry);
zipout.Write(buff, 0, buff.Length);
zipout.Finish();
byte[] outputbyte = new byte[(int)stream.Length];
stream.Position = 0;
stream.Read(outputbyte, 0, (int)stream.Length);
return outputbyte;
}
}
}
catch (Exception ex)
{
ex.Message.ToString();
return null;
}
}
开发者ID:Chanicua,项目名称:GoogleHC,代码行数:37,代码来源:CompressionHelper.cs
示例14: ExecuteResult
public override void ExecuteResult(ControllerContext context)
{
string fileName = Path.GetTempFileName();
var response = context.HttpContext.Response;
using (var zipOutputStream = new ZipOutputStream(new FileStream(fileName, FileMode.OpenOrCreate)))
{
zipOutputStream.SetLevel(0);
foreach (var photo in Photos)
{
//FileInfo fileInfo = new FileInfo(photo.MediaFilePath);
ZipEntry entry = new ZipEntry(Tag.Name + @"\" + photo.Id + ".jpg");
zipOutputStream.PutNextEntry(entry);
using (FileStream fs = System.IO.File.OpenRead(photo.MediaFilePath))
{
byte[] buff = new byte[1024];
int n = 0;
while ((n = fs.Read(buff, 0, buff.Length)) > 0)
zipOutputStream.Write(buff, 0, n);
}
}
zipOutputStream.Finish();
}
System.IO.FileInfo file = new System.IO.FileInfo(fileName);
response.Clear();
response.AddHeader("Content-Disposition", "attachment; filename=" + "Photos.zip");
response.AddHeader("Content-Length", file.Length.ToString());
response.ContentType = "application/octet-stream";
response.WriteFile(file.FullName);
response.End();
System.IO.File.Delete(fileName);
}
开发者ID:BackupTheBerlios,项目名称:molecule-svn,代码行数:35,代码来源:ZipPhotoFilesResult.cs
示例15: CompressFolder
private static void CompressFolder(string path, ZipOutputStream zipStream)
{
string[] files = Directory.GetFiles(path);
foreach (string filename in files)
{
FileInfo fi = new FileInfo(filename);
int offset = _root.Length + 3;
string entryName = filename.Substring(offset);
entryName = ZipEntry.CleanName(entryName);
ZipEntry newEntry = new ZipEntry(entryName);
newEntry.DateTime = fi.LastWriteTime;
newEntry.Size = fi.Length;
zipStream.PutNextEntry(newEntry);
byte[] buffer = new byte[4096];
using (FileStream streamReader = File.OpenRead(filename))
{
StreamUtils.Copy(streamReader, zipStream, buffer);
}
zipStream.CloseEntry();
}
string[] folders = Directory.GetDirectories(path);
foreach (string folder in folders)
{
CompressFolder(folder, zipStream);
}
}
开发者ID:rxtur,项目名称:BeDeploy,代码行数:29,代码来源:Program.cs
示例16: 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
示例17: CreateZipFile
public void CreateZipFile(string[] straFilenames, string strOutputFilename)
{
Crc32 crc = new Crc32();
ZipOutputStream zos = new ZipOutputStream(File.Create(strOutputFilename));
zos.SetLevel(m_nCompressionLevel);
foreach (string strFileName in straFilenames)
{
FileStream fs = File.OpenRead(strFileName);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
ZipEntry entry = new ZipEntry(GetFileNameWithoutDrive(strFileName));
entry.DateTime = DateTime.Now;
entry.Size = fs.Length;
fs.Close();
crc.Reset();
crc.Update(buffer);
entry.Crc = crc.Value;
zos.PutNextEntry(entry);
zos.Write(buffer, 0, buffer.Length);
}
zos.Finish();
zos.Close();
}
开发者ID:tgiphil,项目名称:wintools,代码行数:33,代码来源:ZipCompressor.cs
示例18: 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
示例19: GetInputStream
public Stream GetInputStream(ZipEntry entry)
{
if (zipArchive == null)
throw new InvalidDataException("Zip File is closed");
Stream s = zipArchive.GetInputStream(entry);
return s;
}
开发者ID:jdineshk,项目名称:npoi,代码行数:7,代码来源:ZipFileZipEntrySource.cs
示例20: 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
注:本文中的ICSharpCode.SharpZipLib.Zip.ZipEntry类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论