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


C# ZipOutputStream.Close方法代码示例

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


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

示例1: ZipFiles

        /// <summary>
        /// Zip all the specified files into the specified ZipFileName.
        /// </summary>
        public static string ZipFiles(IEnumerable<string> FilesToZip, string ZipFileName, string Password)
        {
            if (!File.Exists(ZipFileName))
                File.Delete(ZipFileName);

            ZipOutputStream Zip = new ZipOutputStream(File.Create(ZipFileName));
            if (Password != "")
                Zip.Password = Password;
            try
            {
                Zip.SetLevel(5); // 0 - store only to 9 - means best compression
                foreach (string FileName in FilesToZip)
                {
                    FileStream fs = File.OpenRead(FileName);

                    byte[] Buffer = new byte[fs.Length];
                    fs.Read(Buffer, 0, Buffer.Length);
                    fs.Close();

                    ZipEntry Entry = new ZipEntry(Path.GetFileName(FileName));
                    Zip.PutNextEntry(Entry);
                    Zip.Write(Buffer, 0, Buffer.Length);
                }
                Zip.Finish();
                Zip.Close();
                return ZipFileName;
            }
            catch (System.Exception)
            {
                Zip.Finish();
                Zip.Close();
                File.Delete(ZipFileName);
                throw;
            }
        }
开发者ID:rcichota,项目名称:APSIM.Shared,代码行数:38,代码来源:ZipUtilities.cs

示例2: GetZipFileName

        public static string GetZipFileName(string filename)
        {
            string zipfile = filename.Replace (".db", ".zip");
            try {

                using (ZipOutputStream s = new ZipOutputStream (File.Create (zipfile))) {
                    s.SetLevel (9); // 0 - store only to 9 - means best compression
                    byte[] buffer = new byte[4096];
                    ZipEntry entry = new ZipEntry (filename);
                    entry.DateTime = DateTime.Now;
                    s.PutNextEntry (entry);

                    using (FileStream fs = File.OpenRead (filename)) {
                        int sourceBytes;
                        do {
                            sourceBytes = fs.Read (buffer, 0, buffer.Length);
                            s.Write (buffer, 0, sourceBytes);
                        } while (sourceBytes > 0);
                    }
                    s.Finish ();
                    s.Close ();
                }
            } catch (Exception ex) {
                zipfile = filename;
            }
            return zipfile;
        }
开发者ID:mokth,项目名称:merpV3,代码行数:27,代码来源:ZipHelper.cs

示例3: CompressFolder

	static public void CompressFolder(string aFolderName, string aFullFileOuputName, string[] ExcludedFolderNames, string[] ExcludedFileNames){
		// Perform some simple parameter checking.  More could be done
		// like checking the target file name is ok, disk space, and lots
		// of other things, but for a demo this covers some obvious traps.
		if (!Directory.Exists(aFolderName)) {
			Debug.Log("Cannot find directory : " + aFolderName);
			return;
		}

		try
		{
			string[] exFileNames = new string[0];
			string[] exFolderNames = new string[0];
			if(ExcludedFileNames != null) exFileNames = ExcludedFileNames;
			if(ExcludedFolderNames != null) exFolderNames = ExcludedFolderNames;
			// Depending on the directory this could be very large and would require more attention
			// in a commercial package.
			List<string> filenames = GenerateFolderFileList(aFolderName, null);
			
			//foreach(string filename in filenames) Debug.Log(filename);
			// 'using' statements guarantee the stream is closed properly which is a big source
			// of problems otherwise.  Its exception safe as well which is great.
			using (ZipOutputStream zipOut = new ZipOutputStream(File.Create(aFullFileOuputName))){
			zipOut.Finish();
			zipOut.Close();
			}
			using(ZipFile s = new ZipFile(aFullFileOuputName)){
					s.BeginUpdate();
					int counter = 0;
					//add the file to the zip file
				   	foreach(string filename in filenames){
						bool include = true;
						string entryName = filename.Replace(aFolderName, "");
						//Debug.Log(entryName);
						foreach(string fn in exFolderNames){
							Regex regEx = new Regex(@"^" + fn.Replace(".",@"\."));
							if(regEx.IsMatch(entryName)) include = false;
						}
						foreach(string fn in exFileNames){
							Regex regEx = new Regex(@"^" + fn.Replace(".",@"\."));
							if(regEx.IsMatch(entryName)) include = false;
						}
						if(include){
							s.Add(filename, entryName);
						}
						counter++;
					}
				    //commit the update once we are done
				    s.CommitUpdate();
				    //close the file
				    s.Close();
				}
		}
		catch(Exception ex)
		{
			Debug.Log("Exception during processing" + ex.Message);
			
			// No need to rethrow the exception as for our purposes its handled.
		}
	}
开发者ID:shaunus84,项目名称:through-shadows,代码行数:60,代码来源:Zip.cs

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

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

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

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

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

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

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

示例11: ZipFile

        //public static void ZipFile(string path, string file2Zip, string zipFileName, string zip, string bldgType)
        public static void ZipFile(string path, string file2Zip, string zipFileName)
        {
            //MemoryStream ms = InitializeGbxml(path + file2Zip, zip, bldgType) as MemoryStream;
            MemoryStream ms = InitializeGbxml(Path.Combine(path , file2Zip)) as MemoryStream;
 
            string compressedFile =Path.Combine(path, zipFileName);
            if (File.Exists(compressedFile))
            {
                File.Delete(compressedFile);
            }
            Crc32 objCrc32 = new Crc32();
            ZipOutputStream strmZipOutputStream = new ZipOutputStream(File.Create(compressedFile));
            strmZipOutputStream.SetLevel(9);

            byte[] gbXmlBuffer = new byte[ms.Length];
            ms.Read(gbXmlBuffer, 0, gbXmlBuffer.Length);

            ZipEntry objZipEntry = new ZipEntry(file2Zip);

            objZipEntry.DateTime = DateTime.Now;
            objZipEntry.Size = ms.Length;
            ms.Close();
            objCrc32.Reset();
            objCrc32.Update(gbXmlBuffer);
            objZipEntry.Crc = objCrc32.Value;
            strmZipOutputStream.PutNextEntry(objZipEntry);
            strmZipOutputStream.Write(gbXmlBuffer, 0, gbXmlBuffer.Length);
            strmZipOutputStream.Finish();
            strmZipOutputStream.Close();
            strmZipOutputStream.Dispose();
        }
开发者ID:whztt07,项目名称:EnergyAnalysisForDynamo,代码行数:32,代码来源:ZipUtil.cs

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

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

示例14: Zip

 /// <summary>
 /// 将文件或目录压缩。
 /// </summary>
 /// <param name="paths">路径集合。</param>
 /// <returns>压缩后数据</returns>
 public static byte[] Zip(string[] paths)
 {
     byte[] data = null;
     if (paths != null && paths.Length > 0)
     {
         using (MemoryStream ms = new MemoryStream())
         {
             //压缩数据保存到临时文件。
             using (ZipOutputStream zipStream = new ZipOutputStream(ms))
             {
                 zipStream.SetLevel(9);
                 for (int i = 0; i < paths.Length; i++)
                 {
                     if (File.Exists(paths[i]))
                     {
                         ZipFileData(zipStream, paths[i], null, null);
                     }
                     else if (Directory.Exists(paths[i]))
                     {
                         ZipFolderData(zipStream, paths[i], string.Empty);
                     }
                 }
                 zipStream.IsStreamOwner = true;
                 zipStream.Close();
             }
             data = ms.ToArray();
         }
     }
     return data;
 }
开发者ID:jeasonyoung,项目名称:csharp_sfit,代码行数:35,代码来源:ZipUtils.cs

示例15: 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
            }
        }
开发者ID:mabech,项目名称:Projeto-Mestrado,代码行数:39,代码来源:Util.cs


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