當前位置: 首頁>>代碼示例>>C#>>正文


C# SevenZipCompressor.CompressStreamDictionary方法代碼示例

本文整理匯總了C#中SevenZip.SevenZipCompressor.CompressStreamDictionary方法的典型用法代碼示例。如果您正苦於以下問題:C# SevenZipCompressor.CompressStreamDictionary方法的具體用法?C# SevenZipCompressor.CompressStreamDictionary怎麽用?C# SevenZipCompressor.CompressStreamDictionary使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在SevenZip.SevenZipCompressor的用法示例。


在下文中一共展示了SevenZipCompressor.CompressStreamDictionary方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CompressArchive

        public int CompressArchive(Dictionary<string, Stream> files, string outFileName)
        {
            // create output archive
            SevenZipCompressor compressor = new SevenZipCompressor();
            try
            {
                var dict = new Dictionary<string, Stream>();

                foreach (var fileName in files.Keys)
                    dict.Add(fileName, files[fileName]);
                compressor.CompressStreamDictionary(dict, outFileName);
                return 0;

            }
            catch (Exception ex)
            {
                Logger.Logwrite(ex.Message);
                Console.Error.WriteLine("Error: Could not create output archive: " + outFileName);

                Console.Error.WriteLine("\t" + ex.Message);
                return 1;
            }
        }
開發者ID:se5a,項目名稱:PBWAutoClient,代碼行數:23,代碼來源:ArchiveHandler.cs

示例2: BackupFiles


//.........這裏部分代碼省略.........
                        case 2:
                            sevenZip.CompressionLevel = CompressionLevel.Fast;
                            break;
                        case 3:
                            sevenZip.CompressionLevel = CompressionLevel.Low;
                            break;
                        case 4:
                            sevenZip.CompressionLevel = CompressionLevel.Low;
                            break;
                        case 5:
                            sevenZip.CompressionLevel = CompressionLevel.Low;
                            break;
                        case 6:
                            sevenZip.CompressionLevel = CompressionLevel.Normal;
                            break;
                        case 7:
                            sevenZip.CompressionLevel = CompressionLevel.High;
                            break;
                        case 8:
                            sevenZip.CompressionLevel = CompressionLevel.High;
                            break;
                        case 9:
                            sevenZip.CompressionLevel = CompressionLevel.Ultra;
                            break;
                    }

                    if (BackupProgress != null)
                    {
                        sevenZip.FileCompressionStarted += (sender, e) =>
                        {
                            var ebp = new BackupProgressEventArgs()
                            {
                                AcrhiveFileName = e.FileName,
                                Action = EventAction.StartingArchive
                            };

                            sevenZipCurrentFile = e.FileName;

                            Report7ZipProgress(component, volumeMap, ebp);

                            if (cancel)
                            {
                                e.Cancel = true;
                            }
                        };

                        sevenZip.FileCompressionFinished += (sender, e) =>
                        {
                            var ebp = new BackupProgressEventArgs()
                            {
                                AcrhiveFileName = sevenZipCurrentFile,
                                Action = EventAction.ArchiveDone
                            };

                            sevenZipCurrentFile = String.Empty;

                            Report7ZipProgress(component, volumeMap, ebp);
                        };

                        sevenZip.Compressing += (sender, e) =>
                        {
                            var ebp = new BackupProgressEventArgs()
                            {
                                AcrhiveFileName = sevenZipCurrentFile,
                                Action = EventAction.PercentProgress,
                                CurrentEntry = sevenZipCurrentFile,
                                PercentDone = e.PercentDone
                            };

                            Report7ZipProgress(component, volumeMap, ebp);

                            if (cancel)
                            {
                                e.Cancel = true;
                            }
                        };
                    }

                    if (string.IsNullOrEmpty(options.Password))
                        sevenZip.CompressStreamDictionary(files, vmBackupPath);
                    else
                        sevenZip.CompressStreamDictionary(files, vmBackupPath, options.Password);

                    if (cancel)
                    {
                        if (File.Exists(vmBackupPath))
                        {
                            File.Delete(vmBackupPath);
                        }
                        throw new BackupCancelledException();
                    }
                }
            }
            finally
            {
                // Make sure that all streams are closed
                foreach (var s in streams)
                    s.Close();
            }
        }
開發者ID:wegli,項目名稱:hypervbackup,代碼行數:101,代碼來源:BackupManager.cs

示例3: Write

        public void Write(CloudFile cloudFile, Stream stream, OnProgress onProgress)
        {
            logger.DebugFormat("7zip, start writing [{0}]", cloudFile.FullName());

            cloudFile.Format = CloudFileFormat.SevenZip;
            //cloudFile.Fingerprint = HashHelper.MD5(cloudFile.Fingerprint + password);
            stream.Position = 0;

            // set the name into the package
            Dictionary<String, Stream> dir = new Dictionary<string, Stream>();
            dir[cloudFile.Name] = stream;

            // drive low level provider to write data
            using (MemoryStream compressedStream = new MemoryStream())
            {
                SevenZipCompressor compressor = new SevenZipCompressor();

                compressor.Compressing += new EventHandler<ProgressEventArgs>(
                    (o, p) => {
                        onProgress(cloudFile, ProcessTypes.Compress, (p.PercentDone * stream.Length / 100), stream.Length);
                        logger.InfoFormat("Compressing [{0}], [{1}% of {2}MB]", cloudFile.Name, p.PercentDone, (int)(stream.Length / 1024 / 1024));
                    });

                compressor.CompressStreamDictionary(dir, compressedStream, password);

                compressedStream.Position = 0;

                cloudFile.MD5 = cloudFile.Fingerprint;
                cloudFile.Fingerprint = HashHelper.MD5(cloudFile.Fingerprint+password);
                provider.Write(cloudFile, compressedStream, onProgress);
            }

            logger.DebugFormat("7zip, finish writing [{0}]", cloudFile.FullName());
        }
開發者ID:xfm84,項目名稱:test,代碼行數:34,代碼來源:SevenZipProvider.cs


注:本文中的SevenZip.SevenZipCompressor.CompressStreamDictionary方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。