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


C# ZipArchive.GetEntry方法代码示例

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


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

示例1: ReduceXap_CreateNewFile_Test

        public void ReduceXap_CreateNewFile_Test()
        {
            var fileSystem = Substitute.For<IFileSystem>();
            var console = new StringWriter();

            CreateFakeInputXap(fileSystem, ZipArchiveMode.Read, "A", "B").
                AddResourceAssemblyPart("en", "A").
                AddResourceAssemblyPart("en-US", "A").
                AddResourceAssemblyPart("en", "B");

            CreateFakeSourceXap(fileSystem, "A", "C");

            MemoryStream outputStream = new MemoryStream();
            fileSystem.FileExists("Output.xap").Returns(true);
            fileSystem.OpenArchive("Output.xap", ZipArchiveMode.Create).Returns(new ZipArchive(outputStream, ZipArchiveMode.Create, true));

            var options = new Options()
            {
                Input = "Input.xap",
                Sources = new[] { "Source.xap" },
                Output = "Output.xap"
            };

            var builder = new XapBuilder();
            builder.AddAssemblyPart("A", 1000);

            var minifier = new XapMinifier(fileSystem, console);
            minifier.ReduceXap(options);

            var output = new ZipArchive(outputStream, ZipArchiveMode.Read, true);
            Assert.AreEqual(3, output.Entries.Count);
            Assert.IsNotNull(output.GetEntry("B.dll"));
            Assert.IsNotNull(output.GetEntry("en\\B.resources.dll"));
        }
开发者ID:Thorarin,项目名称:XapReduce,代码行数:34,代码来源:XapMinifierTests.cs

示例2: DoTask

        /// <summary>
        /// Downloads and interprets the ZIP file CTS uploads for Google.  This is primarily to get route colors and route schedules.
        /// </summary>
        private static async Task<Tuple<List<GoogleRoute>, List<GoogleRouteSchedule>>> DoTask()
        {
            List<GoogleRoute> routes = null;
            List<GoogleRouteSchedule> schedules = null;

            var stream = await GetZipFileAsync();

            using (var archive = new ZipArchive(stream))
            {
                var routesEntry = archive.GetEntry("routes.txt");
                if (routesEntry == null)
                {
                    throw new FileNotFoundException("The Google Transit archive did not contain routes.txt.");
                }

                var scheduleEntry = archive.GetEntry("stop_times.txt");
                if (scheduleEntry == null)
                {
                    throw new FileNotFoundException("The Google Transit archive did not contain stop_times.txt.");
                }

                routes = ParseRouteCSV(routesEntry);
                schedules = ParseScheduleCSV(scheduleEntry);
            }

            return Tuple.Create(routes, schedules);
        }
开发者ID:RikkiGibson,项目名称:Corvallis-Bus-Server,代码行数:30,代码来源:GoogleTransitClient.cs

示例3: DoTask

        /// <summary>
        /// Downloads and interprets the ZIP file CTS uploads for Google.  This is primarily to get route colors and route schedules.
        /// </summary>
        private static GoogleTransitData DoTask()
        {
            List<GoogleRoute> routes = null;
            List<GoogleRouteSchedule> schedules = null;

            using (var archive = new ZipArchive(GetZipFile()))
            {
                var routesEntry = archive.GetEntry("routes.txt");
                if (routesEntry == null)
                {
                    throw new FileNotFoundException("The Google Transit archive did not contain routes.txt.");
                }

                var scheduleEntry = archive.GetEntry("stop_times.txt");
                if (scheduleEntry == null)
                {
                    throw new FileNotFoundException("The Google Transit archive did not contain stop_times.txt.");
                }

                routes = ParseRouteCSV(routesEntry);
                schedules = ParseScheduleCSV(scheduleEntry);
            }

            return new GoogleTransitData
            {
                Routes = routes,
                Schedules = schedules
            };
        }
开发者ID:RikkiGibson,项目名称:Corvallis-Bus-Server,代码行数:32,代码来源:GoogleTransitClient.cs

示例4: AssertVocabulary

 /// <summary>
 /// Run a vocabulary test against two data files inside a zip file </summary>
 public static void AssertVocabulary(Analyzer a, Stream zipFile, string voc, string @out)
 {
     using (ZipArchive zip = new ZipArchive(zipFile, ZipArchiveMode.Read, false, Encoding.UTF8))
     {
         using (Stream v = zip.GetEntry(voc).Open())
         {
             using (Stream o = zip.GetEntry(@out).Open())
             {
                 AssertVocabulary(a, v, o);
             }
         }
     }
 }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:15,代码来源:VocabularyAssert.cs

示例5: ZipGetEntryReadMode

		public void ZipGetEntryReadMode()
		{
			File.Copy("archive.zip", "test.zip", overwrite: true);
			using (var archive = new ZipArchive(File.Open("test.zip", FileMode.Open),
				ZipArchiveMode.Read))
			{
				var entry = archive.GetEntry("foo.txt");
				Assert.IsNotNull(entry);

				var nullEntry = archive.GetEntry("nonexisting");
				Assert.IsNull(nullEntry);
			}
		}
开发者ID:pompomJuice,项目名称:mono,代码行数:13,代码来源:ZipTest.cs

示例6: BlankPage11_Loaded

        private async void BlankPage11_Loaded(object sender, RoutedEventArgs e)
        {
            var f = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/giftest.gif"));
            f = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/vedio.mp4"));
            f = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/live.jpg"));

            MemoryStream ms = null;
            using (var s = await f.OpenReadAsync())
            {
                using (var zip = new ZipArchive(s.AsStream(), ZipArchiveMode.Read))
                {
                    ZipArchiveEntry entry = zip.GetEntry("formats/living/living.mp4");
                    if (entry != null)
                    {
                        using (var st = entry.Open())
                        {
                            ms = new MemoryStream();
                            st.CopyTo(ms);
                            ms.Flush();
                        }
                    }
                }
            }
            var m = ms.AsRandomAccessStream();
            m.Seek(0);

            MediaElement1.SetSource(m, "video/mp4");
            MediaElement1.Play();
        }
开发者ID:HppZ,项目名称:UniversalTest,代码行数:29,代码来源:BlankPage11.xaml.cs

示例7: GetRootFilePathAsync

        public static async System.Threading.Tasks.Task<string> GetRootFilePathAsync(ZipArchive epubArchive)
        {
            //Checking if file exist
            const string EPUB_CONTAINER_FILE_PATH = "META-INF/container.xml";

            ZipArchiveEntry containerFileEntry = epubArchive.GetEntry(EPUB_CONTAINER_FILE_PATH);
            string full_path = string.Empty;

            if (containerFileEntry == null)
                throw new Exception(String.Format("EPUB parsing error: {0} file not found in archive.", EPUB_CONTAINER_FILE_PATH));

            //Loading container.xml to memmory...
            using (Stream containerStream = containerFileEntry.Open())
            {
                // ...and trying to parse it in order to get the full path to the .opf file, like full-path="SomeFolder/SomeFileWithContent.opf"
                full_path = await XmlUtils.GetFilePathAttributeAsync(containerStream);
            }
            //Checking if the problem exist...
            if (full_path == "full-path attribute not found" || full_path == "Yes, rootfile not found...")
            {
                Debug.WriteLine(string.Format("Content.opf path is FUBAR and the problem is: {0}", full_path));
                throw new Exception(string.Format("Content.opf path is FUBAR and the problem is: {0}", full_path));
            }
                
            return full_path;

            //Initial code sucks and is not compatible with Win 8.1 runtime framework
            /*
            xmlNamespaceManager.AddNamespace("cns", "urn:oasis:names:tc:opendocument:xmlns:container");
            XmlNode rootFileNode = containerDocument.DocumentElement.SelectSingleNode("/cns:container/cns:rootfiles/cns:rootfile", xmlNamespaceManager);
            return rootFileNode.Attributes["full-path"].Value;
            */
        }
开发者ID:fedorinoGore,项目名称:bookScriptorW10,代码行数:33,代码来源:RootFilePathReader.cs

示例8: Restore

        public void Restore(string slnFile)
        {
            using (var resourceStream = _fileSystem.OpenResource("slnRun.Resources.nuget.zip"))
            using (var zipFile = new ZipArchive(resourceStream))
            using (var nugetInputFile = zipFile.GetEntry("nuget.exe").Open())
            {
                var tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
                _fileSystem.CreateDirectory(tempPath);
                try
                {
                    var targetPath = Path.Combine(tempPath, "nuget.exe");
                    using (var nugetOutputFile = _fileSystem.CreateFile(targetPath))
                        nugetInputFile.CopyTo(nugetOutputFile);

                    var sb = new StringBuilder();
                    var exitCode = _processRunner.Run(targetPath, $"restore \"{slnFile}\"", x => { sb.Append(x); });
                    if (exitCode != 0)
                    {
                        _logger.Error(sb.ToString());
                        throw new SlnRunException("nuget package restore failed.");
                    }
                }
                finally
                {
                    _fileSystem.DeleteDirectory(tempPath);
                }
            }
        }
开发者ID:vetterd,项目名称:slnRun,代码行数:28,代码来源:NuGet.cs

示例9: LoadData

    public override IRegressionProblemData LoadData(IDataDescriptor id) {
      var descriptor = (ResourceRegressionDataDescriptor)id;

      var instanceArchiveName = GetResourceName(FileName + @"\.zip");
      using (var instancesZipFile = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) {
        var entry = instancesZipFile.GetEntry(descriptor.ResourceName);
        NumberFormatInfo numberFormat;
        DateTimeFormatInfo dateFormat;
        char separator;
        using (Stream stream = entry.Open()) {
          TableFileParser.DetermineFileFormat(stream, out numberFormat, out dateFormat, out separator);
        }

        TableFileParser csvFileParser = new TableFileParser();
        using (Stream stream = entry.Open()) {
          csvFileParser.Parse(stream, numberFormat, dateFormat, separator, true);
        }

        Dataset dataset = new Dataset(csvFileParser.VariableNames, csvFileParser.Values);
        if (!descriptor.CheckVariableNames(csvFileParser.VariableNames)) {
          throw new ArgumentException("Parsed file contains variables which are not in the descriptor.");
        }

        return descriptor.GenerateRegressionData(dataset);
      }
    }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:26,代码来源:ResourceRegressionInstanceProvider.cs

示例10: Load

        public void Load(ZipArchive iArchive)
        {
            JObject pJOtImages = null;
            ZipArchiveEntry pZAEImages = iArchive.GetEntry("images.json");
            if (pZAEImages != null)
            {
                using (Stream pStmImages = pZAEImages.Open())
                {
                    using (StreamReader pSRrReader = new StreamReader(pStmImages, Encoding.UTF8, false, 1024, true))
                    {
                        using (JsonTextReader pJTRReader = new JsonTextReader(pSRrReader))
                        {
                            pJOtImages = JObject.Load(pJTRReader);
                        }
                    }
                }
            }

            JArray pJAyImages = pJOtImages["images"].Value<JArray>(); ;
            foreach(JObject curImage in pJAyImages)
            {
                ProjectImage pPIeImage = ProjectImage.FromJSON(curImage);
                ZipArchiveEntry pZAEImage = iArchive.GetEntry(pPIeImage.ID);
                if (pZAEImage != null)
                {
                    using (Stream pStmImage = pZAEImage.Open())
                    {
                        pPIeImage.Image = Image.FromStream(pStmImage);
                        cDicImages.Add(pPIeImage.ID, pPIeImage);
                    }
                }
            }
        }
开发者ID:devoctomy,项目名称:knitup,代码行数:33,代码来源:ProjectImages.cs

示例11: DownloadAndExtract

        public async static Task DownloadAndExtract(
            string uri,
            params Tuple<string, string>[] files)
        {
            var tmpFile = Path.GetTempPath() + "pomelo_" + Guid.NewGuid().ToString() + ".zip";
            Console.WriteLine("Downloading from " + uri);
            using (var webClient = new HttpClient() { Timeout = new TimeSpan(1, 0, 0), MaxResponseContentBufferSize = 1024 * 1024 * 50 })
            {
                var bytes = await webClient.GetByteArrayAsync(uri);
                File.WriteAllBytes(tmpFile, bytes);
                Console.WriteLine("Downloaded");
            }
            using (var fileStream = new FileStream(tmpFile, FileMode.Open))
            using (var archive = new ZipArchive(fileStream))
            {
                foreach (var file in files)
                {
                    var entry = archive.GetEntry(file.Item1);
                    if (entry == null)
                        throw new Exception("Could not find file '" + file.Item1 + "'.");

                    Directory.CreateDirectory(Path.GetDirectoryName(file.Item2));

                    using (var entryStream = entry.Open())
                    using (var dllStream = File.OpenWrite(file.Item2))
                    {
                        entryStream.CopyTo(dllStream);
                    }
                }
            }
            File.Delete(tmpFile);
        }
开发者ID:yonglehou,项目名称:dotNETCore-Extensions,代码行数:32,代码来源:Download.cs

示例12: CryptRWArchive

		public CryptRWArchive(string filePath, string encryptionKey)
		{
			EncryptionKey = encryptionKey;
			_arc = ZipFile.Open(filePath, ZipArchiveMode.Update); //open R/W
			if (_arc.GetEntry("crypt.index")!=null)
			{
				LoadIndex();
			}
		}
开发者ID:exaphaser,项目名称:CryptRW,代码行数:9,代码来源:CryptRW.cs

示例13: ZipCreateFromDirectory

		public void ZipCreateFromDirectory()
		{
			if (File.Exists ("foo.zip"))
				File.Delete ("foo.zip");

			ZipFile.CreateFromDirectory ("foo", "foo.zip");
			Assert.IsTrue(File.Exists("foo.zip"));

			using (var archive = new ZipArchive (File.Open ("foo.zip", FileMode.Open),
				ZipArchiveMode.Read))
			{
				Assert.IsNotNull (archive.GetEntry ("foo.txt"));
				Assert.IsNotNull (archive.GetEntry ("bar.txt"));

				Assert.IsNotNull (archive.GetEntry ("foobar/foo.txt"));
				Assert.IsNotNull (archive.GetEntry ("foobar/bar.txt"));				
			}
		}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:18,代码来源:ZipTest.cs

示例14: AssertZipEntry

 private static void AssertZipEntry(ZipArchive archive, string fileName, string content)
 {
     ZipArchiveEntry entry = archive.GetEntry(fileName);
     Assert.NotNull(entry);
     using (var streamReader = new StreamReader(entry.Open()))
     {
         Assert.Equal(content, streamReader.ReadLine());
     }
 }
开发者ID:GregPerez83,项目名称:kudu,代码行数:9,代码来源:ZipArchiveExtensionFacts.cs

示例15: ZipCreateFromDirectoryIncludeBase

		public void ZipCreateFromDirectoryIncludeBase()
		{
			if (File.Exists ("foo.zip"))
				File.Delete ("foo.zip");

			ZipFile.CreateFromDirectory ("foo", "foo.zip", CompressionLevel.Fastest,
				includeBaseDirectory: true);
			Assert.IsTrue (File.Exists ("foo.zip"));

			using (var archive = new ZipArchive (File.Open ("foo.zip", FileMode.Open),
				ZipArchiveMode.Read))
			{
				Assert.IsNotNull (archive.GetEntry ("foo/foo.txt"));
				Assert.IsNotNull (archive.GetEntry ("foo/bar.txt"));

				Assert.IsNotNull (archive.GetEntry ("foo/foobar/foo.txt"));
				Assert.IsNotNull (archive.GetEntry ("foo/foobar/bar.txt"));				
			}
		}		
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:19,代码来源:ZipTest.cs


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