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;
            }
  • 相关阅读:
    HDU 3280 Equal Sum Partitions(二分查找)
    提高效率—编程中的技巧
    开发心得
    使用OpenCV读、操作、写图像并与bash合作对某个文件夹下全部图像进行相似处理
    观察者模式
    ORA-00932: inconsistent datatypes: expected
    Struts1应用、实现简单计算器、使用DispatchAction、显示友好的报错信息、使用动态Form简化开发
    Apple Swift编程语言新手教程
    I NEED A OFFER! (hdu 1203 01背包)
    端午遥想
  • 原文地址:https://www.cnblogs.com/pcbren/p/9368927.html
Copyright © 2011-2022 走看看