Beispiel #1
0
void ZipInputStreamTest::testZipContents() {
  ZipInputStream zis("test.zip");
  int count(0);
  while (zis.getNextEntry()->isValid())
    count++;
  CPPUNIT_ASSERT_EQUAL(4, count);
}
Beispiel #2
0
void ZipInputStreamTest::testDirectory() {
  ZipInputStream zis("test.zip"); //only files in this
  ConstEntryPointer poi(zis.getNextEntry());
  while( poi->isValid() ) {
      CPPUNIT_ASSERT_EQUAL( false, poi->isDirectory() );
      poi = zis.getNextEntry();
  }
}
Beispiel #3
0
extern "C" int LLVMFuzzerTestOneInput(const wxUint8 *data, size_t size)
{
    wxLogNull noLog;

    wxMemoryInputStream mis(data, size);
    wxZipInputStream zis(mis);
    while ( wxZipEntry* const ze = zis.GetNextEntry() ) {
        zis.OpenEntry(*ze);
        delete ze;
    }

    return 0;
}
Beispiel #4
0
/** \brief Retrieve a pointer to a file in the Zip archive.
 *
 * This function returns a shared pointer to an istream defined from the
 * named entry, which gives you access to the corresponding file defined
 * in the Zip archive.
 *
 * The function returns nullptr if there is no entry with the
 * specified name in this ZipFile.
 *
 * Note that the function returns a smart pointer to an istream. The
 * ZipFile class does not hold that pointer meaning that
 * if you call getInputStream() multiple times with the same
 * \p entry_name parameter, you get different istream instance each
 * time.
 *
 * By default the \p entry_name parameter is expected to match the full
 * path and filename (MatchPath::MATCH). If you are looking for a file
 * and want to ignore the path, set the matchpath parameter
 * to MatchPath::IGNORE.
 *
 * \note
 * If the file is compressed inside the Zip archive, this input stream
 * returns the uncompressed data transparently to you (outside of the
 * time it takes to decompress the data, of course.)
 *
 * \param[in] entry_name  The name of the file to search in the collection.
 * \param[in] matchpath  Whether the full path or just the filename is matched.
 *
 * \return A shared pointer to an open istream for the specified entry.
 *
 * \sa CollectionCollection
 * \sa DirectoryCollection
 * \sa FileCollection
 */
ZipFile::stream_pointer_t ZipFile::getInputStream(std::string const& entry_name, MatchPath matchpath)
{
    mustBeValid();

    FileEntry::pointer_t entry(getEntry(entry_name, matchpath));
    if(entry)
    {
        stream_pointer_t zis(new ZipInputStream(m_filename, entry->getEntryOffset() + m_vs.startOffset()));
        return zis;
    }

    // no entry with that name (and match) available
    return nullptr;
}
Beispiel #5
0
void ZipInputStreamTest::testZipFileSizes() {
  vector<uint32> entries;
  entries.push_back(1327); // got these from unzip -l test.zip
  entries.push_back(17992);
  entries.push_back(8);
  entries.push_back(76468);
  ZipInputStream zis("test.zip");
  ConstEntryPointer poi(zis.getNextEntry());
  int count(0);
  while( poi->isValid() ) {
      CPPUNIT_ASSERT_EQUAL( entries[count], poi->getSize() );
      poi = zis.getNextEntry();
      count++;
  }
}
Beispiel #6
0
void ZipInputStreamTest::testZipContentNames() {
  vector<string> entries;
  entries.push_back("file1.txt"); // got these from unzip -l test.zip
  entries.push_back("file2.txt");
  entries.push_back("file3.txt");
  entries.push_back("testfile.bin");
  ZipInputStream zis("test.zip");
  ConstEntryPointer poi(zis.getNextEntry());
  int count(0);
  while( poi->isValid() ) {
      CPPUNIT_ASSERT_EQUAL( entries[count], poi->getName() );
      poi = zis.getNextEntry();
      count++;
  }
}
Beispiel #7
0
istream *ZipFile::getInputStream( const string &entry_name, 
				  MatchPath matchpath ) {
  if ( ! _valid )
    throw InvalidStateException( "Attempt to use an invalid ZipFile" ) ;

  ConstEntryPointer ent = getEntry( entry_name, matchpath ) ;
  
  if ( ent == 0 )
    return 0 ;
  else {
    ZipInputStream *zis( new ZipInputStream( _filename,
      static_cast< const ZipCDirEntry * >( ent.get() )->
      getLocalHeaderOffset() + _vs.startOffset() ) ) ;
    zis->getNextEntry();
    return zis;
  }
}
Beispiel #8
0
DWORD UncompressNSave(LPCTSTR szFileName, BYTE* compr, size_t comprLen)
{
	wxMemoryInputStream mis(compr, comprLen);

	wxZlibInputStream zis(mis, wxZLIB_ZLIB);

	wxFile file;
	if ( file.Create(szFileName, true) == false )
	{
		wxRemoveFile(szFileName);
		return wxSysErrorCode();
	}

	wxFileOutputStream fos(file);
	zis.Read(fos);

	return ERROR_SUCCESS;
}