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;
            }
  • 相关阅读:
    怎么做接口测试,概念及常用方法一
    Maven 常用命令
    终端/Shell 快捷键
    Linux/Unix split 大文件分割合并
    macOS 跳过非 AppStore 下载的软件打开时的验证步骤
    docker[-compose] 连接内网其他容器地址
    iOS现有工程 集成 Cordova/Ionic
    Retrofit2 上传图片等文件
    ButterKnife 绑定 RadioGroup
    使用 Sublime Text 3 开发 React
  • 原文地址:https://www.cnblogs.com/pcbren/p/9368927.html
Copyright © 2011-2022 走看看