本文整理汇总了C#中ICSharpCode.SharpZipLib.Zip.ZipOutputStream.PutNextEntry方法的典型用法代码示例。如果您正苦于以下问题:C# ZipOutputStream.PutNextEntry方法的具体用法?C# ZipOutputStream.PutNextEntry怎么用?C# ZipOutputStream.PutNextEntry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICSharpCode.SharpZipLib.Zip.ZipOutputStream
的用法示例。
在下文中一共展示了ZipOutputStream.PutNextEntry方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: saveFileDialog_FileOk
private void saveFileDialog_FileOk(object sender, CancelEventArgs e)
{
ReportText = ReportTextBox.Text;
ZipEntry ze;
ZipOutputStream zip_out = new ZipOutputStream(File.Create((sender as SaveFileDialog).FileName));
string SourceText;
byte[] data=null;
foreach (string FileName in FileNames)
{
SourceText = VEC.StandartCompiler.GetSourceFileText(FileName);
if (SourceText != null)
{
data = System.Text.Encoding.GetEncoding(1251).GetBytes(SourceText);
ze = new ZipEntry(System.IO.Path.GetFileName(FileName));
zip_out.PutNextEntry(ze);
zip_out.Write(data, 0, data.Length);
}
}
ze = new ZipEntry("Report.txt");
zip_out.PutNextEntry(ze);
data = System.Text.Encoding.GetEncoding(1251).GetBytes(ReportText);
zip_out.Write(data, 0, data.Length);
zip_out.Finish();
zip_out.Close();
}
示例2: CreateFileBundle
/// <summary>
/// Creates a bundle containing version list delta and all data of files.
/// </summary>
/// <returns>The binary bundle.</returns>
/// <param name="list">List needed to transferred.</param>
public static byte[] CreateFileBundle(List<FileEvent> list)
{
using (MemoryStream ms = new MemoryStream())
using (ZipOutputStream zip = new ZipOutputStream(ms))
{
ZipEntry block = new ZipEntry("vs");
zip.PutNextEntry(block);
zip.WriteAllBytes(list.SerializeAsBytes());
zip.CloseEntry();
foreach (var sha1 in list.Where(x => x.SHA1 != null).Select(x => x.SHA1).Distinct())
{
block = new ZipEntry(sha1);
zip.PutNextEntry(block);
zip.WriteAllBytes(File.ReadAllBytes(Config.MetaFolderData.File(sha1)));
zip.CloseEntry();
}
zip.Finish();
ms.Flush();
ms.Position = 0;
return ms.ToArray();
}
}
示例3: Save
public void Save(Project project, string filename)
{
using (var zipStream = new ZipOutputStream(new FileStream(filename, FileMode.Create)))
{
zipStream.PutNextEntry(new ZipEntry("book.xml"));
bookLoader.Save(project.Book, zipStream);
zipStream.CloseEntry();
foreach (var file in project.Files)
{
zipStream.PutNextEntry(new ZipEntry(file.Filename));
fileController.WriteSupportFile(file, zipStream);
zipStream.CloseEntry();
}
}
}
示例4: 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);
}
}
}
示例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();
}
}
示例6: 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();
}
示例7: 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();
}
}
}
}
示例8: 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);
}
}
}
示例9: 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);
}
}
示例10: 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;
}
}
示例11: 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);
}
示例12: 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 ();
}
示例13: PackageFiles
public void PackageFiles(IEnumerable<ZipFileEntry> filesToZip)
{
using (var zipStream = new ZipOutputStream(File.Create(ZipFilePath)))
{
if (!string.IsNullOrEmpty(Password))
{
zipStream.Password = Password;
}
zipStream.SetLevel(9); // 9 -> "highest compression"
foreach (var fileEntry in filesToZip)
{
var zipEntry = new ZipEntry(fileEntry.FilePathInsideZip);
var fileInfo = new FileInfo(fileEntry.AbsoluteFilePath);
zipEntry.DateTime = fileInfo.LastWriteTime;
zipEntry.Size = fileInfo.Length;
zipStream.PutNextEntry(zipEntry);
// Zip the file in buffered chunks
var buffer = new byte[4096];
using (var streamReader = File.OpenRead(fileEntry.AbsoluteFilePath))
{
ICSharpCode.SharpZipLib.Core.StreamUtils.Copy(streamReader, zipStream, buffer);
}
zipStream.CloseEntry();
}
zipStream.Finish();
zipStream.Close();
}
}
示例14: ZipFiles
/// <summary>
/// Método que faz o zip de arquivos encontrados no diretório <strPathDirectory>
/// </summary>
/// <param name="strPath"></param>
public static void ZipFiles(String strPathDirectory, String strZipName)
{
try
{
using (ZipOutputStream ZipOut = new ZipOutputStream(File.Create(strPathDirectory + "\\" + strZipName + ".zip")))
{
string[] OLfiles = Directory.GetFiles(strPathDirectory);
Console.WriteLine(OLfiles.Length);
ZipOut.SetLevel(9);
byte[] buffer = new byte[4096];
foreach (string filename in OLfiles)
{
ZipEntry entry = new ZipEntry(Path.GetFileName(filename));
ZipOut.PutNextEntry(entry);
using (FileStream fs = File.OpenRead(filename))
{
int sourceBytes;
do
{
sourceBytes = fs.Read(buffer, 0, buffer.Length);
ZipOut.Write(buffer, 0, sourceBytes);
} while (sourceBytes > 0);
}
}
ZipOut.Finish();
ZipOut.Close();
}
}
catch (System.Exception ex)
{
System.Console.Error.WriteLine("exception: " + ex);
//TODO colocar log
}
}
示例15: AddZip
public static string AddZip(string fileName, string zipName, ZipOutputStream s)
{
Crc32 crc = new Crc32();
try
{
FileStream fs = File.OpenRead(fileName);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
fileName = Path.GetFileName(fileName);
long fileLength = fs.Length;
fs.Close();
ZipEntry entry = new ZipEntry(zipName);
entry.DateTime = DateTime.Now;
entry.Size = fileLength;
crc.Reset();
crc.Update(buffer);
entry.Crc = crc.Value;
s.PutNextEntry(entry);
s.Write(buffer, 0, buffer.Length);
return string.Empty;
}
catch (Exception addEx)
{
return addEx.ToString();
}
}