zoukankan      html  css  js  c++  java
  • PCB 无需解压,直接读取Genesis TGZ指定文件 实现方法

    通过无需解压读取ZIP压缩包的方法,寻思者如何可以不解压直接读Genesis TGZ文件内容,

    通过查找资料,原来可以通过:SharpCompress.dll工具实现此需求,此工具如此NB

    一.SharpCompress  读取TGZ小结:

         1.读取TGZ内容,无法直接直接指定路径读取文件,只能通过MoveToNextEntry一个一个往下遍历查找文件

         2.MoveToNextEntry 遍历文件,采用的是深度递归

         3.区分文件名与文方件夹,无法通过Entry.IsDirectory 区分,识别方法:尾随 / 斜杆为文件夹,否则为文件

    二.通过写实际例子来对此工具的用法进行说明这样来得更实际一些。哈哈

            例1:读取TGZ  STEP中有多少个step

            private string readTGZ_Dir()
            {
                string line = "";
                string tarFilePath = @"F:2p00802ya0.tgz";
                string FileName = Path.GetFileNameWithoutExtension(tarFilePath);
                string FindDir = $@"{FileName}/steps/";  //以/斜杆结尾为文件夹
                using (Stream stream = File.OpenRead(tarFilePath))
                {
                    IReader reader = ReaderFactory.Open(stream);
                    while (reader.MoveToNextEntry())
                    {
                        Match matchresult = Regex.Match(reader.Entry.Key, $@"^{FindDir}([ws]+)/$");
                        if (matchresult.Success)
                        {
                            line += matchresult.Groups[1].Value + "  ";
                        }
                    }
                }
                return line;
            }

        例2:读取TGZ  指定standard字体内容

            private string readTGZ_File()
            {
                string line = "";
                string tarFilePath = @"F:2p00802ya0.tgz";
                string FileName = Path.GetFileNameWithoutExtension(tarFilePath);
                string FindFile = $@"{FileName}/fonts/standard";
                using (Stream stream = File.OpenRead(tarFilePath))
                {
                    IReader reader = ReaderFactory.Open(stream);
                    while (reader.MoveToNextEntry())
                    {
                        if (reader.Entry.Key == FindFile)
                        {
                            EntryStream st = reader.OpenEntryStream();
                            byte[] byData = new byte[reader.Entry.Size];
                            st.Read(byData, 0, byData.Length);
                            line = System.Text.Encoding.Default.GetString(byData);  //纯英文读取
                             //line = System.Text.Encoding.UTF8.GetString(byData);     //含中文读取
                            st.Close();
                            break;
                        }
                    }
                }
                return line;
            }
  • 相关阅读:
    有线电视网络(最小割)
    太空飞行计划问题(最小割,最大权闭合图,网络流24题)
    攻击装置(最小割,最大权独立集)
    王者之剑(最小割,最大独立集)
    善意的投票(最小割)
    有向图破坏(最小割,最小点权覆盖)
    线性代数(最小割,最大密度子图,TJOI2015)
    codewars--js--counting duplicates
    codewars--js--the highest and lowest number + JS 字符串和数组相关知识
    work
  • 原文地址:https://www.cnblogs.com/pcbren/p/9368927.html
Copyright © 2011-2022 走看看