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


C# ZipFile.BeginUpdate方法代码示例

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


在下文中一共展示了ZipFile.BeginUpdate方法的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: 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

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

示例5: SharpZipReader

 internal SharpZipReader(string zipFile)
 {
     _zipFile = new ZipFile(zipFile)
     {
         UseZip64 = UseZip64.Dynamic
     };
     _zipFile.BeginUpdate();
 }
开发者ID:UIKit0,项目名称:ClearCanvas,代码行数:8,代码来源:SharpZipReader.cs

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

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

示例8: BeginProcessing

 public void BeginProcessing()
 {
     _command.WriteVerbose("Begin Update...");
     try
     {
         _zip = new ZipFile(_command.OutputPath.ProviderPath);
         _zip.BeginUpdate();
     }
     catch (PipelineStoppedException)
     {
         throw;
     }
     catch (Exception ex)
     {
         var error = new ErrorRecord(ex, "ZipOpenFail", ErrorCategory.OpenError, _command.OutputPath);
         _command.ThrowTerminatingError(error);
     }
 }
开发者ID:razaraz,项目名称:Pscx,代码行数:18,代码来源:SingleArchiveZipUpdater.cs

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

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

示例11: ProcessZip

        private static void ProcessZip(object data, ZipFile zipFile)
        {
            zipFile.BeginUpdate();

            var document = "";
            var entry = zipFile.GetEntry(DocumentXmlPath);
            if (entry == null)
            {
                throw new Exception(string.Format("Can't find {0} in template zip", DocumentXmlPath));
            }

            using (var s = zipFile.GetInputStream(entry))
            using (var reader = new StreamReader(s, Encoding.UTF8))
            {
                document = reader.ReadToEnd();
            }

            var newDocument = ParseTemplate(document, data);

            zipFile.Add(new StringStaticDataSource(newDocument), DocumentXmlPath, CompressionMethod.Deflated, true);

            zipFile.CommitUpdate();
        }
开发者ID:JackWangCUMT,项目名称:docx-template-engine,代码行数:23,代码来源:DocXTemplateEngine.cs

示例12: NameFactory

        public void NameFactory()
        {
            MemoryStream memStream = new MemoryStream();
            DateTime fixedTime = new DateTime(1981, 4, 3);
            using (ZipFile f = new ZipFile(memStream))
            {
                f.IsStreamOwner = false;
                ((ZipEntryFactory)f.EntryFactory).IsUnicodeText = true;
                ((ZipEntryFactory)f.EntryFactory).Setting = ZipEntryFactory.TimeSetting.Fixed;
                ((ZipEntryFactory)f.EntryFactory).FixedDateTime = fixedTime;
                ((ZipEntryFactory)f.EntryFactory).SetAttributes = 1;
                f.BeginUpdate(new MemoryArchiveStorage());

                string[] names = new string[]
                {
                    "\u030A\u03B0",     // Greek
                    "\u0680\u0685",     // Arabic
                };

                foreach (string name in names)
                {
                    f.Add(new StringMemoryDataSource("Hello world"), name,
                          CompressionMethod.Deflated, true);
                }
                f.CommitUpdate();
                Assert.IsTrue(f.TestArchive(true));

                foreach (string name in names)
                {
                    int index = f.FindEntry(name, true);

                    Assert.IsTrue(index >= 0);
                    ZipEntry found = f[index];
                    Assert.AreEqual(name, found.Name);
                    Assert.IsTrue(found.IsUnicodeText);
                    Assert.AreEqual(fixedTime, found.DateTime);
                    Assert.IsTrue(found.IsDOSEntry);
                }
            }
        }
开发者ID:firestrand,项目名称:SharpZipLib,代码行数:40,代码来源:ZipTests.cs

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

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

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


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