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


C# ZipFile.GetEntry方法代码示例

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


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

示例1: DocxImporter

        public DocxImporter(string file)
        {
            zip = new ZipFile (file);

            var docEntry = zip.GetEntry (DocumentXmlEntry);
            if (docEntry == null)
                throw new DocxFormatException (string.Format ("Zip entry '{0}' not found", DocumentXmlEntry));

            docXml = XDocument.Load (zip.GetInputStream (docEntry.ZipFileIndex));

            var relsEntry = zip.GetEntry (DocumentRelsEntry);
            if (relsEntry != null)
                relsXml = XDocument.Load (zip.GetInputStream (relsEntry.ZipFileIndex));
        }
开发者ID:joelmartinez,项目名称:DocConverter,代码行数:14,代码来源:DocxImporter.cs

示例2: LoadPack

        public static void LoadPack(string packDir)
        {
            Dictionary<string, Dictionary<ushort, string>> allTextMap;
            using (var z = new ZipFile(Path.Combine(packDir, "text.zip")))
            {
                using (var texter = new StreamReader(z.GetInputStream(z.GetEntry("text.csv")), Encoding.UTF8))
                {
                    allTextMap = CSV.ParseCSVText(texter);
                }
            }

            var byterList = new List<BinaryReader>();
            var zipFiles = new List<ZipFile>();
            foreach (var f in Directory.GetFiles(packDir, "*.zip"))
            {
                var name = Path.GetFileNameWithoutExtension(f);
                if (name != null && !name.Equals("text"))
                {
                    var z = new ZipFile(f);
                    zipFiles.Add(z);
                    var byter = new BinaryReader(z.GetInputStream(z.GetEntry(name)));
                    byterList.Add(byter);
                }
            }

            Processor(new Stream(byterList, allTextMap));
            foreach (var z in zipFiles)
            {
                z.Close();
            }
        }
开发者ID:stallboy,项目名称:configgen,代码行数:31,代码来源:CSVLoader.cs

示例3: AreEqual

 /// <summary>
 /// Compares all idml's in outputPath to make sure the content.xml and styles.xml are the same
 /// </summary>
 public static void AreEqual(string expectFullName, string outputFullName, string msg)
 {
     using (var expFl = new ZipFile(expectFullName))
     {
         var outFl = new ZipFile(outputFullName);                
         foreach (ZipEntry zipEntry in expFl)
         {
             //TODO: designmap.xml should be tested but \\MetadataPacketPreference should be ignored as it contains the creation date.
             if (!CheckFile(zipEntry.Name,"Stories,Spreads,Resources,MasterSpreads"))
                 continue;
             if (Path.GetExtension(zipEntry.Name) != ".xml")
                 continue;
             string outputEntry = new StreamReader(outFl.GetInputStream(outFl.GetEntry(zipEntry.Name).ZipFileIndex)).ReadToEnd();
             string expectEntry = new StreamReader(expFl.GetInputStream(expFl.GetEntry(zipEntry.Name).ZipFileIndex)).ReadToEnd();
             XmlDocument outputDocument = new XmlDocument();
             outputDocument.XmlResolver = FileStreamXmlResolver.GetNullResolver();
             outputDocument.LoadXml(outputEntry);
             XmlDocument expectDocument = new XmlDocument();
             outputDocument.XmlResolver = FileStreamXmlResolver.GetNullResolver();
             expectDocument.LoadXml(expectEntry);
             XmlDsigC14NTransform outputCanon = new XmlDsigC14NTransform();
             outputCanon.Resolver = new XmlUrlResolver();
             outputCanon.LoadInput(outputDocument);
             XmlDsigC14NTransform expectCanon = new XmlDsigC14NTransform();
             expectCanon.Resolver = new XmlUrlResolver();
             expectCanon.LoadInput(expectDocument);
             Stream outputStream = (Stream)outputCanon.GetOutput(typeof(Stream));
             Stream expectStream = (Stream)expectCanon.GetOutput(typeof(Stream));
             string errMessage = string.Format("{0}: {1} doesn't match", msg, zipEntry.Name);
             Assert.AreEqual(expectStream.Length, outputStream.Length, errMessage);
             FileAssert.AreEqual(expectStream, outputStream, errMessage);
         }
     }
 }
开发者ID:neilmayhew,项目名称:pathway,代码行数:37,代码来源:IdmlTest.cs

示例4: GetFileFromZip

        private Action<Stream> GetFileFromZip(string zipPath, string docPath)
        {
            var fileStream = new FileStream(zipPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            var zipFile = new ZipFile(fileStream);
            var zipEntry = zipFile.GetEntry(docPath);

            if (zipEntry == null || zipEntry.IsFile == false)
                return null;

            var data = zipFile.GetInputStream(zipEntry);
            if (data == null) return null;

            return stream =>
                   {
                       try
                       {
                           if (_disableRequestCompression == false)
                               stream = new GZipStream(stream, CompressionMode.Compress, leaveOpen: true);

                           data.CopyTo(stream);
                           stream.Flush();
                       }
                       finally
                       {
                           if (_disableRequestCompression == false)
                               stream.Dispose();
                       }
                   };
        }
开发者ID:synhershko,项目名称:RavenDB.ElasticsearchReplication,代码行数:29,代码来源:SpecialEmbeddedFileResponse.cs

示例5: ExtractResourceZip

 /// <summary>
 /// extract file from zipped resource, and place to temp folder
 /// </summary>
 /// <param name="resource">resource name</param>
 /// <param name="fileName">output name</param>
 /// <param name="OverWriteIfExists">if true,will overwrite the file even if the file exists</param>
 private void ExtractResourceZip(byte[] resource, string fileName, bool OverWriteIfExists = false, int BufferSize = BUFFERSIZE)
 {
     string target = WorkingPath + fileName;
     
     if (OverWriteIfExists || !File.Exists(target))
     {
         ZipFile zip = null;
         FileStream fs = null;
         Stream inStream = null;
         try
         {
             zip = new ZipFile(new MemoryStream(resource));
             inStream = zip.GetInputStream(zip.GetEntry(fileName));
             fs = new FileStream(target, FileMode.Create);
             byte[] buff = new byte[BufferSize];
             int read_count;
             while ((read_count = inStream.Read(buff, 0, BufferSize)) > 0)
             {
                 fs.Write(buff, 0, read_count);
             }
         }
         catch { }
         finally
         {
             if (zip != null) zip.Close();
             if (fs != null) fs.Close();
             if (inStream != null) inStream.Close();
         }
     }
 }
开发者ID:27m10a,项目名称:apkshellext,代码行数:36,代码来源:AndroidToolAgent.cs

示例6: AreEqual

 /// <summary>
 /// Compares all odt's in outputPath to make sure the content.xml and styles.xml are the same
 /// </summary>
 /// <param name="expectPath">expected output path</param>
 /// <param name="outputPath">output path</param>
 /// <param name="msg">message to display if mismatch</param>
 public static void AreEqual(string expectPath, string outputPath, string msg)
 {
     var outDi = new DirectoryInfo(outputPath);
     var expDi = new DirectoryInfo(expectPath);
     FileInfo[] outFi = outDi.GetFiles("*.od*");
     FileInfo[] expFi = expDi.GetFiles("*.od*");
     Assert.AreEqual(outFi.Length, expFi.Length, string.Format("{0} {1} odt found {2} expected", msg, outFi.Length, expFi.Length));
     foreach (FileInfo fi in outFi)
     {
         var outFl = new ZipFile(fi.FullName);
         var expFl = new ZipFile(Common.PathCombine(expectPath, fi.Name));
         foreach (string name in "content.xml,styles.xml".Split(','))
         {
             string outputEntry = new StreamReader(outFl.GetInputStream(outFl.GetEntry(name).ZipFileIndex)).ReadToEnd();
             string expectEntry = new StreamReader(expFl.GetInputStream(expFl.GetEntry(name).ZipFileIndex)).ReadToEnd();
             XmlDocument outputDocument = new XmlDocument();
             outputDocument.XmlResolver = FileStreamXmlResolver.GetNullResolver();
             outputDocument.LoadXml(outputEntry);
             XmlDocument expectDocument = new XmlDocument();
             expectDocument.XmlResolver = FileStreamXmlResolver.GetNullResolver();
             expectDocument.LoadXml(expectEntry);
             XmlDsigC14NTransform outputCanon = new XmlDsigC14NTransform();
             outputCanon.Resolver = new XmlUrlResolver();
             outputCanon.LoadInput(outputDocument);
             XmlDsigC14NTransform expectCanon = new XmlDsigC14NTransform();
             expectCanon.Resolver = new XmlUrlResolver();
             expectCanon.LoadInput(expectDocument);
             Stream outputStream = (Stream)outputCanon.GetOutput(typeof(Stream));
             Stream expectStream = (Stream)expectCanon.GetOutput(typeof(Stream));
             string errMessage = string.Format("{0}: {1} {2} doesn't match", msg, fi.Name, name);
             Assert.AreEqual(expectStream.Length, outputStream.Length, errMessage);
             FileAssert.AreEqual(expectStream, outputStream, errMessage);
         }
     }
 }
开发者ID:neilmayhew,项目名称:pathway,代码行数:41,代码来源:OdtTest.cs

示例7: FromFile

        public static bool FromFile(string fileName, out ThemePack result)
        {
            var fiSource = new FileInfo(fileName);

            using (var fs = new FileStream(fiSource.FullName, FileMode.Open, FileAccess.Read))
            using (var zf = new ZipFile(fs))
            {
                var ze = zf.GetEntry("info.json");
                if (ze == null)
                {
                    result = null;
                    return false;
                }

                using (var s = zf.GetInputStream(ze))
                using (var reader = new StreamReader(s))
                {
                    var themePack = JsonConvert.DeserializeObject<ThemePack>(reader.ReadToEnd());
                    themePack.FileName = fiSource.Name;

                    result = themePack;
                    return true;
                }
            }
        }
开发者ID:WELL-E,项目名称:Hurricane,代码行数:25,代码来源:ThemePack.cs

示例8: MakeBloomPack_AddslockFormattingMetaTagToReader

        public void MakeBloomPack_AddslockFormattingMetaTagToReader()
        {
            var srcBookPath = MakeBook();

            // the html file needs to have the same name as its directory
            var testFileName = Path.GetFileName(srcBookPath) + ".htm";
            var readerName = Path.Combine(srcBookPath, testFileName);

            var bloomPackName = Path.Combine(_folder.Path, "testReaderPack.BloomPack");

            var sb = new StringBuilder();
            sb.AppendLine("<!DOCTYPE html>");
            sb.AppendLine("<html>");
            sb.AppendLine("<head>");
            sb.AppendLine("    <meta charset=\"UTF-8\"></meta>");
            sb.AppendLine("    <meta name=\"Generator\" content=\"Bloom Version 3.3.0 (apparent build date: 28-Jul-2015)\"></meta>");
            sb.AppendLine("    <meta name=\"BloomFormatVersion\" content=\"2.0\"></meta>");
            sb.AppendLine("    <meta name=\"pageTemplateSource\" content=\"Leveled Reader\"></meta>");
            sb.AppendLine("    <title>Leveled Reader</title>");
            sb.AppendLine("    <link rel=\"stylesheet\" href=\"basePage.css\" type=\"text/css\"></link>");
            sb.AppendLine("</head>");
            sb.AppendLine("<body>");
            sb.AppendLine("</body>");
            sb.AppendLine("</html>");

            File.WriteAllText(readerName, sb.ToString());

            // make the BloomPack
            MakeTestBloomPack(bloomPackName, true);

            // get the reader file from the BloomPack
            var actualFiles = GetActualFilenamesFromZipfile(bloomPackName);
            var zipEntryName = actualFiles.FirstOrDefault(file => file.EndsWith(testFileName));
            Assert.That(zipEntryName, Is.Not.Null.And.Not.Empty);

            string outputText;
            using (var zip = new ZipFile(bloomPackName))
            {
                var ze = zip.GetEntry(zipEntryName);
                var buffer = new byte[4096];

                using (var instream = zip.GetInputStream(ze))
                using (var writer = new MemoryStream())
                {
                    ICSharpCode.SharpZipLib.Core.StreamUtils.Copy(instream, writer, buffer);
                    writer.Position = 0;
                    using (var reader = new StreamReader(writer))
                    {
                        outputText = reader.ReadToEnd();
                    }
                }
            }

            // check for the lockFormatting meta tag
            Assert.That(outputText, Is.Not.Null.And.Not.Empty);
            Assert.IsTrue(outputText.Contains("<meta name=\"lockFormatting\" content=\"true\">"));
        }
开发者ID:BloomBooks,项目名称:BloomDesktop,代码行数:57,代码来源:LibraryModelTests.cs

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

示例10: Load

        public async Task Load(string filePath)
        {
            var fiSource = new FileInfo(filePath);

            using (var fs = new FileStream(fiSource.FullName, FileMode.Open, FileAccess.Read))
            using (var zf = new ZipFile(fs))
            {
                if (ContainsAudioVisualisation)
                {
                    using (var stream = zf.GetInputStream(zf.GetEntry(ThemePackConsts.AudioVisualisationName)))
                    {
                        _audioVisualisationPlugin = await Task.Run(() => AudioVisualisationPluginHelper.FromStream(stream));
                    }
                }

                if (ContainsBackground)
                {
                    var path = "HurricaneBackground" + BackgroundName;
                    var backgroundZipEntry = zf.GetEntry(BackgroundName);
                    using (var zipStream = zf.GetInputStream(backgroundZipEntry))
                    {
                        var buffer = new byte[4096];
                        var file = new FileInfo(path);
                        if (file.Exists) file.Delete();
                        using (var streamWriter = File.Create(file.FullName))
                        {
                            StreamUtils.Copy(zipStream, streamWriter, buffer);
                        }
                        _backgroundPath = file.FullName;
                    }
                }

                if (ContainsAppTheme)
                {
                    using (var stream = zf.GetInputStream(zf.GetEntry(ThemePackConsts.AppThemeName)))
                    {
                        _appThemeResourceDictionary = (ResourceDictionary)XamlReader.Load(stream);
                    }
                } 
                
                if (ContainsAccentColor)
                {
                    using (var stream = zf.GetInputStream(zf.GetEntry(ThemePackConsts.AccentColorName)))
                    {
                        _accentColorResourceDictionary = (ResourceDictionary)XamlReader.Load(stream);
                    }
                }
            }
        }
开发者ID:WELL-E,项目名称:Hurricane,代码行数:49,代码来源:ThemePack.cs

示例11: Load

 /// <summary>
 /// Load the data for the given filename.
 /// </summary>
 public byte[] Load(string fileName)
 {
     using (var file = new ZipFile(path))
     {
         var entry = file.GetEntry(fileName);
         if (entry == null)
             return null;
         using (var stream = file.GetInputStream(entry))
         {
             var data = new byte[entry.Size];
             stream.Read(data, 0, data.Length);
             return data;
         }
     }
 }
开发者ID:Xtremrules,项目名称:dot42,代码行数:18,代码来源:ApkFileOpenOnAccessOnly.cs

示例12: GH221

        public void GH221()
        {
            // This is a perfectly fine file, written by 'file-roller', but
            // SharpZipLib can choke on it because it's not properly handling
            // the headers properly. See GH #221.
            string file = Path.Combine(TestData.DataDir(), "gh221.zip");

            var zipfile = new ZipFile(file);

            var entry = zipfile.GetEntry("221.txt");

            string version = string.Format("{0}", entry.Version);

            Assert.DoesNotThrow(delegate
            {
                zipfile.GetInputStream(entry);
            }, "zip-entry format {0} (788 is our bug)", version);
        }
开发者ID:CliftonMarien,项目名称:CKAN,代码行数:18,代码来源:ZipLib.cs

示例13: CommitUpdates

        /// <summary>
        /// Commits the updates.
        /// </summary>
        /// <remarks>Documented by Dev03, 2009-07-20</remarks>
        public void CommitUpdates()
        {
            ZipFile zipFile = null;
            try
            {
                zipFile = new ZipFile(file.FullName);
                zipFile.UseZip64 = UseZip64.Off;  // AAB-20090720: Zip64 caused some problem when modifing the archive (ErrorReportHandler.cs) - Zip64 is required to bypass the 4.2G limitation of the original Zip format (http://en.wikipedia.org/wiki/ZIP_(file_format))

                ZipEntry errorReport = zipFile.GetEntry(Resources.ERRORFILE_NAME);

                MemoryStream stream = new MemoryStream();
                using (Stream s = GetZipStream(errorReport, zipFile))
                {
                    XmlDocument doc = new XmlDocument();
                    using (StreamReader reader = new StreamReader(s, Encoding.Unicode))
                    {
                        doc.LoadXml(reader.ReadToEnd());
                    }
                    foreach (Dictionary<string, string> value in values)
                    {
                        XmlElement xE = doc.CreateElement(value["nodeName"]);
                        xE.InnerText = value["value"].Trim();
                        XmlNode parentNode = doc.SelectSingleNode(value["parentPath"]);
                        if (parentNode == null)
                            return;
                        parentNode.AppendChild(xE);
                    }
                    doc.Save(stream);
                }
                ZipData data = new ZipData(stream);
                zipFile.BeginUpdate();
                zipFile.Delete(errorReport);    //delete first!
                zipFile.CommitUpdate();
                zipFile.BeginUpdate();
                zipFile.Add(data, errorReport.Name);
                zipFile.CommitUpdate();
            }
            finally
            {
                if (zipFile != null)
                    zipFile.Close();
            }
        }
开发者ID:Stoner19,项目名称:Memory-Lifter,代码行数:47,代码来源:ErrorReportHandler.cs

示例14: GetWarriorNames

        // ProjectS 中,一个Spine内可以有多个共享部件的角色,它们以动画名称前缀区分
        // json 解析是从 Spine-Runtime 里拿过来的
        public static List<String> GetWarriorNames(String spineName)
        {
            String resDir = UserConfigManager.Instance.Config.ResDir;
            string zipPath = System.IO.Path.Combine(resDir, "spine/" + spineName + ".zip");
            
            FileInfo zipFInfo = new FileInfo(zipPath);
            if (!zipFInfo.Exists)
                return new List<String>();

            ZipFile zf = new ZipFile(zipPath);
            ZipEntry jsonEntry = zf.GetEntry(spineName + ".json");

            Stream jsonStream = zf.GetInputStream(jsonEntry);

            var root = new Dictionary<String, Object>();
            using (TextReader reader = new StreamReader(jsonStream))
            {
                root = Json.Deserialize(reader) as Dictionary<String, Object>;
            }

            if (root == null)
                throw new Exception(String.Format("Spine json 文件错误: {0} {1}", spineName, zipPath));

            List<String> result = new List<string>();

            if (root.ContainsKey("animations"))
            {
                foreach (KeyValuePair<String, Object> entry in (Dictionary<String, Object>)root["animations"])
                {
                    int dashPos = entry.Key.IndexOf('_');
                    if (dashPos != -1)
                    {
                        string actorName = entry.Key.Substring(0, dashPos);
                        if (!result.Contains(actorName))
                        {
                            result.Add(actorName);
                        }
                    }
                }
            }

            return result;
        }
开发者ID:Henry-T,项目名称:UnityPG,代码行数:45,代码来源:SpineUtil.cs

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


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