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


C# ZipFile.CommitUpdate方法代码示例

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


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

示例1: TryDeleting

        void TryDeleting(byte[] master, int totalEntries, int additions, params int[] toDelete)
        {
            MemoryStream ms = new MemoryStream();
            ms.Write(master, 0, master.Length);

            using (ZipFile f = new ZipFile(ms)) {
                f.IsStreamOwner = false;
                Assert.AreEqual(totalEntries, f.Count);
                Assert.IsTrue(f.TestArchive(true));
                f.BeginUpdate(new MemoryArchiveStorage());

                for (int i = 0; i < additions; ++i) {
                    f.Add(new StringMemoryDataSource("Another great file"),
                        string.Format("Add{0}.dat", i + 1));
                }

                foreach (int i in toDelete) {
                    f.Delete(f[i]);
                }
                f.CommitUpdate();

                /* write stream to file to assist debugging.
                                byte[] data = ms.ToArray();
                                using ( FileStream fs = File.Open(@"c:\aha.zip", FileMode.Create, FileAccess.ReadWrite, FileShare.Read) ) {
                                    fs.Write(data, 0, data.Length);
                                }
                */
                int newTotal = totalEntries + additions - toDelete.Length;
                Assert.AreEqual(newTotal, f.Count,
                    string.Format("Expected {0} entries after update found {1}", newTotal, f.Count));
                Assert.IsTrue(f.TestArchive(true), "Archive test should pass");
            }
        }
开发者ID:firestrand,项目名称:SharpZipLib,代码行数:33,代码来源:ZipTests.cs

示例2: CompressDataInToFile

        public void CompressDataInToFile(string directory, string password, string outputFile)
        {
            var fullFileListing = Directory.EnumerateFiles(directory, "*.*", SearchOption.AllDirectories);
            var directories = Directory.EnumerateDirectories(directory, "*", SearchOption.AllDirectories);

            _logger.Information("Creating ZIP File");
            using (var zip = new ZipFile(outputFile))
            {
                zip.UseZip64 = UseZip64.On;

                _logger.Information("Adding directories..");
                foreach (var childDirectory in directories)
                {
                    _logger.Information(string.Format("Adding {0}", childDirectory.Replace(directory, string.Empty)));
                    zip.BeginUpdate();
                    zip.AddDirectory(childDirectory.Replace(directory, string.Empty));
                    zip.CommitUpdate();
                }

                _logger.Information("Adding files..");
                foreach (var file in fullFileListing)
                {
                    _logger.Information(string.Format("Adding {0}", file.Replace(directory, string.Empty)));
                    zip.BeginUpdate();
                    zip.Add(file, file.Replace(directory, string.Empty));
                    zip.CommitUpdate();
                }

                _logger.Information("Setting password..");
                zip.BeginUpdate();
                zip.Password = password;
                zip.CommitUpdate();
            }
        }
开发者ID:tombuildsstuff,项目名称:SimpleBackup,代码行数:34,代码来源:ZipCompressData.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: AddToZip

        /// <summary>
        /// Add files to an existing Zip archive, 
        /// </summary>
        /// <param name="filename">Array of path / filenames to add to the archive</param>
        /// <param name="archive">Zip archive that we want to add the file to</param>
        public void AddToZip(string[] filename, string archive)
        {
            if (!File.Exists(archive))
            {
                return;
            }

            try
            {
                ZipFile zf = new ZipFile(archive);
                zf.BeginUpdate();
                // path relative to the archive
                zf.NameTransform = new ZipNameTransform(Path.GetDirectoryName(archive));
                foreach (var file in filename)
                {
                    // skip if this isn't a real file
                    if (!File.Exists(file))
                    {
                        continue;
                    }
                    zf.Add(file, CompressionMethod.Deflated);
                }
                zf.CommitUpdate();
                zf.Close();
            }
            catch (Exception e)
            {
                if (e.Message != null)
                {
                    var msg = new[] { e.Message };
                    LocDB.Message("defErrMsg", e.Message, msg, LocDB.MessageTypes.Error, LocDB.MessageDefault.First);
                }
            }
        }
开发者ID:neilmayhew,项目名称:pathway,代码行数:39,代码来源:ZipFolder.cs

示例5: AddFile

 /// <summary>
 /// 添加单个文件到压缩包中
 /// </summary>
 /// <param name="filePath">要压缩的文件</param>
 /// <param name="zipPath">目标压缩包路径</param>
 /// <param name="filePathInZip">在压缩包中文件的路径</param>
 public  void AddFile(string filePath, string zipPath,string filePathInZip)
 {
     using (ZipFile zip = new ZipFile(zipPath))
     {
         zip.BeginUpdate();
         zip.Add(filePath, filePathInZip);
         zip.CommitUpdate();
     }
 }
开发者ID:DebugOfTheRoad,项目名称:CL.IO.Zip,代码行数:15,代码来源:ZipHandler.cs

示例6: Process

            public static void Process( ZipFile zip, ChartRenderingJob chart)
            {
                TemporaryDataSource tds = new TemporaryDataSource(){ ms = new MemoryStream()};
                var currentEntry = zip.GetEntry(chart.TemplatePath);
                using( var input = zip.GetInputStream(currentEntry))
                {
                    ChartWriter.RenderChart(chart,input,tds.ms);
                }
                zip.BeginUpdate();
                zip.Add(tds, currentEntry.Name,currentEntry.CompressionMethod,currentEntry.IsUnicodeText);
                zip.CommitUpdate();

                
            }
开发者ID:swinstanley,项目名称:ChartStreamer,代码行数:14,代码来源:WorkbookWriter.cs

示例7: CompressFile

 private static long CompressFile(FileInfo fi)
 {
     long w = 0;
     if (!overwrite && File.Exists(fi.Name.Replace(fi.Extension, ".zip")))
     {
         if (!quiet)
             Print(String.Format("\r !!   Skipping extant file {0}", fi.Name), ConsoleColor.DarkCyan);
         return -1;
     }
     using (Stream z = File.Open(fi.Name.Replace(fi.Extension, ".zip"), FileMode.OpenOrCreate, FileAccess.ReadWrite))
     {
         using (ZipFile zip = new ZipFile(z))
         {
             zip.BeginUpdate();
             zip.Add(fi.Name);
             zip.CommitUpdate();
             w = z.Length;
             zip.Close();
         }
         return w;
     }
 }
开发者ID:dearing,项目名称:sandbox,代码行数:22,代码来源:Program.cs

示例8: LogAsFile

        /// <summary>
        /// Saves a (looong) string of data as a daily zip file entry.
        /// </summary>
        /// <param name="fileContents">The data as string. NOT filename, sorry</param>
        /// <param name="filenameInZip">What the file will be called in the zip file</param>
        public static void LogAsFile(string fileContents, string filenameInZip)
        {
            string filename = LOG_DIR + CurrFilename() + ".zip";
            if (!File.Exists(filename))
            {
                using (FileStream newzip = File.OpenWrite(filename))
                {
                    newzip.Write(EMPTY_ZIP, 0, EMPTY_ZIP.Length);
                }
            }

            using (ZipFile zipfile = new ZipFile(filename))
            {

                MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(fileContents));
                LogDataSource lds = new LogDataSource(ms);

                zipfile.BeginUpdate();
                zipfile.Add(lds, filenameInZip, CompressionMethod.Deflated, false);
                zipfile.CommitUpdate();
            }
        }
开发者ID:jack4M,项目名称:XTBCNB,代码行数:27,代码来源:Log.cs

示例9: BasicEncryption

        public void BasicEncryption()
        {
            const string TestValue = "0001000";
            MemoryStream memStream = new MemoryStream();
            using (ZipFile f = new ZipFile(memStream)) {
                f.IsStreamOwner = false;
                f.Password = "Hello";

                StringMemoryDataSource m = new StringMemoryDataSource(TestValue);
                f.BeginUpdate(new MemoryArchiveStorage());
                f.Add(m, "a.dat");
                f.CommitUpdate();
                Assert.IsTrue(f.TestArchive(true), "Archive test should pass");
            }

            using (ZipFile g = new ZipFile(memStream)) {
                g.Password = "Hello";
                ZipEntry ze = g[0];

                Assert.IsTrue(ze.IsCrypted, "Entry should be encrypted");
                using (StreamReader r = new StreamReader(g.GetInputStream(0))) {
                    string data = r.ReadToEnd();
                    Assert.AreEqual(TestValue, data);
                }
            }
        }
开发者ID:firestrand,项目名称:SharpZipLib,代码行数:26,代码来源:ZipTests.cs

示例10: AddEncryptedEntriesToExistingArchive

        public void AddEncryptedEntriesToExistingArchive()
        {
            const string TestValue = "0001000";
            MemoryStream memStream = new MemoryStream();
            using (ZipFile f = new ZipFile(memStream)) {
                f.IsStreamOwner = false;
                f.UseZip64 = UseZip64.Off;

                StringMemoryDataSource m = new StringMemoryDataSource(TestValue);
                f.BeginUpdate(new MemoryArchiveStorage());
                f.Add(m, "a.dat");
                f.CommitUpdate();
                Assert.IsTrue(f.TestArchive(true), "Archive test should pass");
            }

            using (ZipFile g = new ZipFile(memStream)) {
                ZipEntry ze = g[0];

                Assert.IsFalse(ze.IsCrypted, "Entry should NOT be encrypted");
                using (StreamReader r = new StreamReader(g.GetInputStream(0))) {
                    string data = r.ReadToEnd();
                    Assert.AreEqual(TestValue, data);
                }

                StringMemoryDataSource n = new StringMemoryDataSource(TestValue);

                g.Password = "Axolotyl";
                g.UseZip64 = UseZip64.Off;
                g.IsStreamOwner = false;
                g.BeginUpdate();
                g.Add(n, "a1.dat");
                g.CommitUpdate();
                Assert.IsTrue(g.TestArchive(true), "Archive test should pass");
                ze = g[1];
                Assert.IsTrue(ze.IsCrypted, "New entry should be encrypted");

                using (StreamReader r = new StreamReader(g.GetInputStream(0))) {
                    string data = r.ReadToEnd();
                    Assert.AreEqual(TestValue, data);
                }
            }
        }
开发者ID:firestrand,项目名称:SharpZipLib,代码行数:42,代码来源:ZipTests.cs

示例11: AddAndDeleteEntriesMemory

        public void AddAndDeleteEntriesMemory()
        {
            MemoryStream memStream = new MemoryStream();

            using (ZipFile f = new ZipFile(memStream)) {
                f.IsStreamOwner = false;

                f.BeginUpdate(new MemoryArchiveStorage());
                f.Add(new StringMemoryDataSource("Hello world"), @"z:\a\a.dat");
                f.Add(new StringMemoryDataSource("Another"), @"\b\b.dat");
                f.Add(new StringMemoryDataSource("Mr C"), @"c\c.dat");
                f.Add(new StringMemoryDataSource("Mrs D was a star"), @"d\d.dat");
                f.CommitUpdate();
                Assert.IsTrue(f.TestArchive(true));
            }

            byte[] master = memStream.ToArray();

            TryDeleting(master, 4, 1, @"z:\a\a.dat");
            TryDeleting(master, 4, 1, @"\a\a.dat");
            TryDeleting(master, 4, 1, @"a/a.dat");

            TryDeleting(master, 4, 0, 0);
            TryDeleting(master, 4, 0, 1);
            TryDeleting(master, 4, 0, 2);
            TryDeleting(master, 4, 0, 3);
            TryDeleting(master, 4, 0, 0, 1);
            TryDeleting(master, 4, 0, 0, 2);
            TryDeleting(master, 4, 0, 0, 3);
            TryDeleting(master, 4, 0, 1, 2);
            TryDeleting(master, 4, 0, 1, 3);
            TryDeleting(master, 4, 0, 2);

            TryDeleting(master, 4, 1, 0);
            TryDeleting(master, 4, 1, 1);
            TryDeleting(master, 4, 3, 2);
            TryDeleting(master, 4, 4, 3);
            TryDeleting(master, 4, 10, 0, 1);
            TryDeleting(master, 4, 10, 0, 2);
            TryDeleting(master, 4, 10, 0, 3);
            TryDeleting(master, 4, 20, 1, 2);
            TryDeleting(master, 4, 30, 1, 3);
            TryDeleting(master, 4, 40, 2);
        }
开发者ID:firestrand,项目名称:SharpZipLib,代码行数:44,代码来源:ZipTests.cs

示例12: Zip64Useage

        public void Zip64Useage()
        {
            MemoryStream memStream = new MemoryStream();
            using (ZipFile f = new ZipFile(memStream)) {
                f.IsStreamOwner = false;
                f.UseZip64 = UseZip64.On;

                StringMemoryDataSource m = new StringMemoryDataSource("0000000");
                f.BeginUpdate(new MemoryArchiveStorage());
                f.Add(m, "a.dat");
                f.Add(m, "b.dat");
                f.CommitUpdate();
                Assert.IsTrue(f.TestArchive(true));
            }

            byte[] rawArchive = memStream.ToArray();

            byte[] pseudoSfx = new byte[1049 + rawArchive.Length];
            Array.Copy(rawArchive, 0, pseudoSfx, 1049, rawArchive.Length);

            memStream = new MemoryStream(pseudoSfx);
            using (ZipFile f = new ZipFile(memStream)) {
                for (int index = 0; index < f.Count; ++index) {
                    Stream entryStream = f.GetInputStream(index);
                    MemoryStream data = new MemoryStream();
                    StreamUtils.Copy(entryStream, data, new byte[128]);
                    string contents = Encoding.ASCII.GetString(data.ToArray());
                    Assert.AreEqual("0000000", contents);
                }
            }
        }
开发者ID:firestrand,项目名称:SharpZipLib,代码行数:31,代码来源:ZipTests.cs

示例13: UpdateCommentOnlyInMemory

        public void UpdateCommentOnlyInMemory()
        {
            MemoryStream ms = new MemoryStream();

            using (ZipFile testFile = new ZipFile(ms))
            {
                testFile.IsStreamOwner = false;
                testFile.BeginUpdate();
                testFile.Add(new StringMemoryDataSource("Aha"), "No1", CompressionMethod.Stored);
                testFile.Add(new StringMemoryDataSource("And so it goes"), "No2", CompressionMethod.Stored);
                testFile.Add(new StringMemoryDataSource("No3"), "No3", CompressionMethod.Stored);
                testFile.CommitUpdate();

                Assert.IsTrue(testFile.TestArchive(true));
            }

            using (ZipFile testFile = new ZipFile(ms))
            {
                Assert.IsTrue(testFile.TestArchive(true));
                Assert.AreEqual("", testFile.ZipFileComment);
                testFile.IsStreamOwner = false;

                testFile.BeginUpdate();
                testFile.SetComment("Here is my comment");
                testFile.CommitUpdate();

                Assert.IsTrue(testFile.TestArchive(true));
            }

            using (ZipFile testFile = new ZipFile(ms))
            {
                Assert.IsTrue(testFile.TestArchive(true));
                Assert.AreEqual("Here is my comment", testFile.ZipFileComment);
            }
        }
开发者ID:firestrand,项目名称:SharpZipLib,代码行数:35,代码来源:ZipTests.cs

示例14: Delete

		/// <summary>
		/// Delete entries from an archive
		/// </summary>
		/// <param name="fileSpecs">The file specs to operate on.</param>
		void Delete(ArrayList fileSpecs)
		{
			string zipFileName = fileSpecs[0] as string;
			if (Path.GetExtension(zipFileName).Length == 0) 
			{
				zipFileName = Path.ChangeExtension(zipFileName, ".zip");
			}

			try
			{
				using (ZipFile zipFile = new ZipFile(zipFileName))
				{
					zipFile.BeginUpdate();
					for ( int i = 1; i < fileSpecs.Count; ++i )
					{
						zipFile.Delete((string)fileSpecs[i]);
					}
					zipFile.CommitUpdate();
				}
			}
			catch(Exception ex)
			{
				Console.WriteLine("Problem deleting files - '{0}'", ex.Message);
			}
		}
开发者ID:dengchangtao,项目名称:hydronumerics,代码行数:29,代码来源:zf.cs

示例15: Single

 /// <summary>
 /// Run in single processing mode for the location.
 /// </summary>
 /// <param name="location">The location.</param>
 /// <param name="options">The collection of options.</param>
 public static void Single(string location, Options options) {
     var provider = Providers.FirstOrDefault(x => x.Open(location) != null);
     if (provider == null) return;
     using (var series = provider.Open(location)) {
         using (series.Populate()) {
             var seriesTitle = series.Title.InvalidatePath();
             var persistencePath = Path.Combine(seriesTitle, ".mangarack-persist");
             var persistence = new List<List<string>>();
             if (File.Exists(persistencePath)) {
                 const int persistenceVersion = 2;
                 foreach (var pieces in File.ReadAllLines(persistencePath).Select(line => new List<string>(line.Split('\0')))) {
                     while (pieces.Count < persistenceVersion) pieces.Add(string.Empty);
                     persistence.Add(pieces);
                 }
             }
             foreach (var chapter in series.Children) {
                 var line = persistence.FirstOrDefault(x => string.Equals(x[1], chapter.UniqueIdentifier));
                 if (line == null) continue;
                 var currentFilePath = Path.Combine(seriesTitle, line[0]);
                 var nextFileName = chapter.ToFileName(seriesTitle, options);
                 if (!string.Equals(line[0], nextFileName) && File.Exists(currentFilePath)) {
                     File.Move(currentFilePath, Path.Combine(seriesTitle, nextFileName));
                     line[0] = nextFileName;
                     Persist(persistencePath, persistence);
                     Console.WriteLine("Switched {0}", nextFileName);
                 }
             }
             foreach (var chapter in series.Children.Filter(options)) {
                 var hasFailed = false;
                 var fileName = chapter.ToFileName(seriesTitle, options);
                 var filePath = Path.Combine(seriesTitle, fileName);
                 var persistenceFile = persistence.FirstOrDefault(x => string.Equals(x[0], fileName));
                 if (options.EnablePersistentSynchronization && persistenceFile != null) {
                     continue;
                 }
                 if (persistenceFile != null) {
                     persistenceFile[1] = chapter.UniqueIdentifier ?? string.Empty;
                 } else {
                     persistence.Add(new List<string> {fileName, chapter.UniqueIdentifier ?? string.Empty});
                 }
                 do {
                     if (options.DisableDuplicationPrevention || !File.Exists(filePath)) {
                         using (chapter.Populate()) {
                             using (var publisher = new Publisher(filePath, options, provider)) {
                                 using (var synchronizer = new Synchronize(publisher, series, chapter)) {
                                     synchronizer.Populate();
                                     hasFailed = false;
                                 }
                             }
                         }
                     } else {
                         if (options.EnableOverwriteMetaInformation) {
                             var comicInfo = new ComicInfo();
                             using (var zipFile = new ZipFile(filePath)) {
                                 var zipEntry = zipFile.GetEntry("ComicInfo.xml");
                                 if (zipEntry != null) {
                                     var previousComicInfo = ComicInfo.Load(zipFile.GetInputStream(zipEntry));
                                     comicInfo.Transcribe(series, chapter, previousComicInfo.Pages);
                                     if (comicInfo.Genre.Any(x => !previousComicInfo.Genre.Contains(x)) ||
                                         previousComicInfo.Genre.Any(x => !comicInfo.Genre.Contains(x)) ||
                                         comicInfo.Manga != previousComicInfo.Manga ||
                                         comicInfo.Number != previousComicInfo.Number ||
                                         comicInfo.PageCount != previousComicInfo.PageCount ||
                                         comicInfo.Penciller.Any(x => !previousComicInfo.Penciller.Contains(x)) ||
                                         previousComicInfo.Penciller.Any(x => !comicInfo.Penciller.Contains(x)) ||
                                         comicInfo.Series != previousComicInfo.Series ||
                                         comicInfo.Summary != previousComicInfo.Summary ||
                                         comicInfo.Title != previousComicInfo.Title ||
                                         comicInfo.Volume != previousComicInfo.Volume ||
                                         comicInfo.Writer.Any(x => !previousComicInfo.Writer.Contains(x)) ||
                                         previousComicInfo.Writer.Any(x => !comicInfo.Writer.Contains(x))) {
                                         using (var memoryStream = new MemoryStream()) {
                                             comicInfo.Save(memoryStream);
                                             memoryStream.Position = 0;
                                             zipFile.BeginUpdate();
                                             zipFile.Add(new DataSource(memoryStream), "ComicInfo.xml");
                                             zipFile.CommitUpdate();
                                             Console.WriteLine("Modified {0}", fileName);
                                         }
                                     }
                                 }
                             }
                         }
                         if (!options.DisableRepairAndErrorTracking && File.Exists(string.Format("{0}.txt", filePath))) {
                             using (chapter.Populate()) {
                                 ComicInfo comicInfo;
                                 var hasBrokenPages = false;
                                 using (var zipFile = new ZipFile(filePath)) {
                                     var zipEntry = zipFile.GetEntry("ComicInfo.xml");
                                     if (zipEntry == null) {
                                         return;
                                     }
                                     comicInfo = ComicInfo.Load(zipFile.GetInputStream(zipEntry));
                                 }
                                 using (var publisher = new Publisher(filePath, options, provider, true)) {
//.........这里部分代码省略.........
开发者ID:Kokoro87,项目名称:mangarack.cs,代码行数:101,代码来源:Application.cs


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