代码之家  ›  专栏  ›  技术社区  ›  sangz

我可以使用wxwidgets读取zip存档吗?

  •  -1
  • sangz  · 技术社区  · 9 年前

    我想读取zip存档中的xml文件或文本文件,而不从存档中提取。我可以不从zip存档中提取而直接执行吗?

    3 回复  |  直到 9 年前
        1
  •  1
  •   Lauri Nurmi    9 年前

    是的,你可以, wxZipInputStream 应该是你要找的。

        2
  •  0
  •   sangz    9 年前
    wxZipInputStream zip(in);
    
                while (entry.reset(zip.GetNextEntry()), entry.get() != NULL) {
                    wxString name = entry->GetName();
                    name = strPageName.BeforeLast('\\') + wxFileName::GetPathSeparator() + name;
    
                        zip.OpenEntry(*entry.get());
    
                        wxFileOutputStream file(name);
    
                        if (!file) {
                        wxLogError(_T("Can not create file '") + name + _T("'."));
                        break;
                        }   
    
                        zip.Read(file); 
    

    我尝试使用wxZipInputStream。是的,我可以在从存档中提取后读取文件。我想知道我是否可以读取这些文件而无需从zip存档中提取。

        3
  •  0
  •   sangz    9 年前
    wxFileSystem::AddHandler(new wxZipFSHandler);
    
    wxFileSystem fs;
    wxFSFile *zip = fs.OpenFile( "d:\\test.zip#zip:test.txt");
    if(zip!=NULL)
    {
      wxInputStream *in = zip->GetStream();
      if ( in != NULL )
      {
        wxFileOutputStream out( "d:\\testout.txt" );
        out.Write(*in);
        out.Close();
      }
      delete zip;
    }
    

    是的,我们可以直接从存档中读取zip文件。以上是示例代码。