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


C# ZipOutputStream.SetLevel方法代码示例

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


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

示例1: ZipFiles

        public static void ZipFiles(string InputFolderPath, string outputPathAndFile, string password)
        {
            string outPath = outputPathAndFile;
            ZipOutputStream oZipStream = new ZipOutputStream(File.Create(outPath));


            int TrimLength = 0;
            if (Directory.GetParent(InputFolderPath) != null)
            {
                TrimLength = (Directory.GetParent(InputFolderPath)).ToString().Length;
                TrimLength += 1; //remove '\'
            }


            string DirPath = outPath.Remove(outPath.LastIndexOf(@"\"));
            if (!Directory.Exists(DirPath))
                Directory.CreateDirectory(DirPath);


            DirectoryInfo dinf = new DirectoryInfo(InputFolderPath);

            if (dinf.Exists)
            {

                if (!string.IsNullOrEmpty(password))
                    oZipStream.Password = password;
                oZipStream.SetLevel(9); // maximum compression


                ArrayList ar = GenerateFileList(InputFolderPath); // generate file list

                foreach (object t in ar)
                {
                    string Fil = t.ToString();
                    ZipFile(TrimLength, oZipStream, Fil);
                }
            }
            else
            {
                FileInfo finf = new FileInfo(InputFolderPath);
                if (!string.IsNullOrEmpty(password))
                    oZipStream.Password = password;
                oZipStream.SetLevel(9); // maximum compression
                ZipFile(TrimLength, oZipStream, finf.FullName);
            }

            oZipStream.Finish();
            oZipStream.Close();
        }
开发者ID:sinaaslani,项目名称:kids.bmi.ir,代码行数:49,代码来源:ZipUtili.cs

示例2: zip

        public void zip(string to, string[] files)
        {
            using (ZipOutputStream s = new ZipOutputStream(File.Create(to)))
              {
            s.SetLevel(9);

            byte[] buffer = new byte[4096];

            foreach (string file in files)
            {
              ZipEntry entry = new ZipEntry(Path.GetFileName(file)) { 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:plkumar,项目名称:jish,代码行数:27,代码来源:ZipCommand.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: 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

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

        /// <summary>
        /// Creates a zip file out of specified input files
        /// </summary>
        /// <param name="files">input files</param>
        /// <param name="zipFileName">output zip file</param>
        /// <exception cref="System.ArgumentException">No file must exist with specified zip file name.</exception>
        public void Zip(FileInfo[] files, string zipFileName)
        {
            if (File.Exists(zipFileName))
                throw new ArgumentException("Es existiert bereits eine Datei unter diesem Namen.", "zipFileName");

            using (FileStream fs = new FileStream(zipFileName, FileMode.CreateNew))
            {
                using (ZipOutputStream stream = new ZipOutputStream(fs))
                {
                    stream.SetLevel(9);

                    foreach (FileInfo file in files)
                    {
                        ZipEntry entry = new ZipEntry(file.Name)
                            {
                                DateTime = DateTime.Now
                            };

                        using (FileStream entryFs = file.OpenRead())
                        {
                            byte[] buffer = new byte[entryFs.Length];

                            entryFs.Read(buffer, 0, buffer.Length);
                            entry.Size = entryFs.Length;

                            stream.PutNextEntry(entry);
                            stream.Write(buffer, 0, buffer.Length);
                        }
                    }

                    stream.Finish();
                }
            }
        }
开发者ID:peschuster,项目名称:SimpleUpdater,代码行数:40,代码来源:ZipManager.cs

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

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

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

示例10: 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();
            }
        }
开发者ID:veraveramanolo,项目名称:power-show,代码行数:34,代码来源:ZipPackage.cs

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

示例12: Zip

        /// <summary>
        /// Zips the specified source (File or Directory).
        /// </summary>
        public void Zip()
        {
            Common.ValidateOverwrite(this.overwriteTarget, this.target);

            this.Log(String.Format("Zipping: [{0}] -> [{1}].", this.source, this.target), LogLevel.Minimal);
            using (ZipOutputStream zipStream = new ZipOutputStream(File.Create(this.target)))
            {
                zipStream.SetLevel((int)zipLevel);
                if (!String.IsNullOrEmpty(this.password))
                    zipStream.Password = this.password;

                DirectoryInfo dir = new DirectoryInfo(Path.GetDirectoryName(this.source));
                List<string> fileList = Common.GetFileList(this.source, this.fileFilter, this.recursive);
                if (fileList.Count == 0)
                    this.Log(String.Format("No files found matching the filter criteria."), LogLevel.Verbose);

                foreach (string filePath in fileList)
                {
                    this.zipFile(zipStream, dir, new FileInfo(filePath));
                }

                zipStream.IsStreamOwner = true;
                zipStream.Close();
            }

            this.Log(String.Format("Successfully Zipped: [{0}] -> [{1}].", this.source, this.target), LogLevel.Minimal);
            Common.RemoveFile(this.removeSource, this.source);
        }
开发者ID:svn2github,项目名称:SSIS-Extensions,代码行数:31,代码来源:ZipManager.cs

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

示例14: CompressBuffer

 /// <summary>
 /// Compresses an array of bytes and stores the result in a new array of bytes.
 /// </summary>
 /// <param name="uncompressed">The uncompressed buffer.</param>
 /// <param name="compressed">An array of bytes where the compressed input will be stored.</param>
 /// <remarks>
 /// The compressed input is passed back to the calling method as an <b>out</b>
 /// parameter. That means that the calling method doesn't need to initialize the
 /// compressed buffer.  
 /// </remarks>
 /// <exception cref="ArgumentNullException">
 /// Thrown if the uncompressed input buffer is empty or null.
 /// </exception>
 /// <exception cref="CWZipException">
 /// Thrown if a problem is encountered during the compression process.
 /// </exception>
 public static void CompressBuffer(byte[] uncompressed, out byte[] compressed)
 {
     if ((uncompressed == null) || (uncompressed.Length == 0))
     {
         throw new ArgumentNullException("uncompressed", "The uncompressed input buffer cannot be null or empty.");
     }
     MemoryStream ms = null;
     compressed = null;
     try
     {
         ms = new MemoryStream();
         ZipOutputStream zip = new ZipOutputStream(ms);
         zip.SetLevel(compressionLevel);
         ZipEntry entry = new ZipEntry("1");
         zip.PutNextEntry(entry);
         zip.Write(uncompressed, 0, uncompressed.Length);
         zip.Finish();
         ms.Position = 0;
         compressed = ms.ToArray();
         ms.Close();
     }
     catch (Exception e)
     {
         if (ms != null)
         {
             ms.Close();
         }
         throw new CWZipException(e.Message);
     }
     finally
     {
         ms = null;
         GC.Collect();
     }
 }
开发者ID:modernist,项目名称:CrawlWave,代码行数:51,代码来源:CompressionUtils.cs

示例15: GetOutputStream

        public override Stream GetOutputStream(UploadedFile file)
        {
            FileStream fileS = null;
            ZipOutputStream zipS = null;

            try
            {
                string outputPath = GetZipPath(file);

                Directory.CreateDirectory(Path.GetDirectoryName(outputPath));

                fileS = File.OpenWrite(outputPath);
                zipS = new ZipOutputStream(fileS);

                zipS.SetLevel(5);

                zipS.PutNextEntry(new ZipEntry(file.ClientName));

                file.LocationInfo[FileNameKey] = outputPath;

                return zipS;
            }
            catch
            {
                if (fileS != null)
                    fileS.Close();

                if (zipS != null)
                    zipS.Close();

                return null;
            }
        }
开发者ID:bmsolutions,项目名称:mvc2inaction,代码行数:33,代码来源:ZipUploadStreamProvider.cs


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