当前位置: 首页>>代码示例>>C#>>正文


C# ZipOutputStream.CloseEntry方法代码示例

本文整理汇总了C#中ICSharpCode.SharpZipLib.Zip.ZipOutputStream.CloseEntry方法的典型用法代码示例。如果您正苦于以下问题:C# ZipOutputStream.CloseEntry方法的具体用法?C# ZipOutputStream.CloseEntry怎么用?C# ZipOutputStream.CloseEntry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICSharpCode.SharpZipLib.Zip.ZipOutputStream的用法示例。


在下文中一共展示了ZipOutputStream.CloseEntry方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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();
            }
        }
开发者ID:hoangvv1409,项目名称:codebase,代码行数:30,代码来源:VersionControl.cs

示例2: 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();
         }
     }
 }
开发者ID:phanson,项目名称:Medius,代码行数:15,代码来源:ProjectPersistenceController.cs

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: CreateToMemoryStream

        // Compresses the supplied memory stream, naming it as zipEntryName, into a zip,
        // which is returned as a memory stream or a byte array.
        //
        public static MemoryStream CreateToMemoryStream(MemoryStream memStreamIn, string zipEntryName)
        {
            MemoryStream outputMemStream = new MemoryStream();
            ZipOutputStream zipStream = new ZipOutputStream(outputMemStream);

            zipStream.SetLevel(3); //0-9, 9 being the highest level of compression

            ZipEntry newEntry = new ZipEntry(zipEntryName);
            newEntry.DateTime = DateTime.Now;

            zipStream.PutNextEntry(newEntry);

            StreamUtils.Copy(memStreamIn, 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;
            return outputMemStream;

            // 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:WeDoCrm,项目名称:PreDeployer,代码行数:32,代码来源:ZipUtil.cs

示例8: CompressFilesToOneZipFile

		private void CompressFilesToOneZipFile()
		{
			Log.LogMessage(MessageImportance.Normal, "Zipping " + Source.Length + " files to zip file " + Destination);

			using (var fsOut = File.Create(Destination)) // Overwrites previous file
			{
				using (var zipStream = new ZipOutputStream(fsOut))
				{
					foreach (ITaskItem item in Source)
					{
						string inputPath = item.ItemSpec;
						zipStream.SetLevel(9); // Highest level of compression

						var inputFileInfo = new FileInfo(inputPath);

						// clean up name
						string pathInArchive = !string.IsNullOrEmpty(WorkingDirectory) ? GetPath(inputFileInfo.FullName, WorkingDirectory)
							: Path.GetFileName(inputFileInfo.FullName);

						var newEntry = new ZipEntry(pathInArchive) { DateTime = inputFileInfo.CreationTime };
						zipStream.PutNextEntry(newEntry);

						var buffer = new byte[4096];
						using (FileStream streamReader = File.OpenRead(inputPath))
							ICSharpCode.SharpZipLib.Core.StreamUtils.Copy(streamReader, zipStream, buffer);

						zipStream.CloseEntry();
					}
					zipStream.IsStreamOwner = true;
					zipStream.Close();
				}
			}
		}
开发者ID:sillsdev,项目名称:FieldWorks,代码行数:33,代码来源:ZipTask.cs

示例9: SafeExecute

        protected override ITaskResult<Nothing> SafeExecute(TaskContext context)
        {
            if (Destination == null)
            {
                throw new Exception("Destination file is not set");
            }

            using (var zipStream = new ZipOutputStream(Destination.WriteStream))
            {
                foreach (var fileToCompress in _sourceFiles)
                {
                    var entry = new ZipEntry(fileToCompress.EntityPath)
                    {
                        Size = fileToCompress.File.Length
                    };

                    zipStream.PutNextEntry(entry);

                    using (var fileReadStream = fileToCompress.File.ReadStream)
                    {
                        fileReadStream.CopyTo(zipStream);
                    }

                    zipStream.CloseEntry();
                }

                zipStream.IsStreamOwner = true;
            }

            return Success;
        }
开发者ID:rosaliafx,项目名称:Rosalia,代码行数:31,代码来源:CompressTask.cs

示例10: 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

示例11: 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

示例12: 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

示例13: CompressFiles

        private void CompressFiles(IEnumerable<string> filePaths, ZipOutputStream zipStream)
        {
            foreach (var fullFileName in filePaths)
            {
                var fi = new FileInfo(fullFileName);

                var fileName = Path.GetFileName(fullFileName);
                var newEntry = new ZipEntry(fileName) {DateTime = fi.LastWriteTime, Size = fi.Length};
                // Note the zip format stores 2 second granularity

                // Specifying the AESKeySize triggers AES encryption. Allowable values are 0 (off), 128 or 256.
                // A password on the ZipOutputStream is required if using AES.
                //   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;
                zipStream.UseZip64 = UseZip64.Off;
                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(fullFileName))
                {
                    StreamUtils.Copy(streamReader, zipStream, buffer);
                }
                zipStream.CloseEntry();
            }
            zipStream.Finish();
        }
开发者ID:ukionik,项目名称:EasyMessenger,代码行数:33,代码来源:ZipCompressor.cs

示例14: 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

示例15: CompressFolder

        /// <summary>
        /// Compresses the folder.
        /// </summary>
        /// <param name="path">Path.</param>
        /// <param name="zipStream">Zip stream.</param>
        /// <param name="folderOffset">Folder offset.</param>
        private static void CompressFolder(string path, ZipOutputStream zipStream, int folderOffset)
        {
            string[] files = Directory.GetFiles(path);

            foreach (string filename in files) {

                FileInfo fi = new FileInfo(filename);

                string entryName = filename.Substring(folderOffset); // Makes the name in zip based on the folder
                entryName = ZipEntry.CleanName(entryName); // Removes drive from name and fixes slash direction
                ZipEntry newEntry = new ZipEntry(entryName);
                newEntry.DateTime = fi.LastWriteTime; // Note the zip format stores 2 second granularity
                newEntry.Size = fi.Length;

                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];
                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, folderOffset);
            }
        }
开发者ID:jatpannu,项目名称:legacy-projects,代码行数:35,代码来源:Program.cs


注:本文中的ICSharpCode.SharpZipLib.Zip.ZipOutputStream.CloseEntry方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。