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


C# Zip.ZipOutputStream类代码示例

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


ZipOutputStream类属于ICSharpCode.SharpZipLib.Zip命名空间,在下文中一共展示了ZipOutputStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


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