testdeb.cc 826 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include <apt-pkg/dirstream.h>
  2. #include <apt-pkg/debfile.h>
  3. #include <apt-pkg/error.h>
  4. #include <apt-pkg/extracttar.h>
  5. class NullStream : public pkgDirStream
  6. {
  7. public:
  8. virtual bool DoItem(Item &Itm,int &Fd) {return true;};
  9. };
  10. bool Test(const char *File)
  11. {
  12. FileFd Fd(File,FileFd::ReadOnly);
  13. debDebFile Deb(Fd);
  14. if (_error->PendingError() == true)
  15. return false;
  16. // Get the archive member and positition the file
  17. const ARArchive::Member *Member = Deb.GotoMember("data.tar.gz");
  18. if (Member == 0)
  19. return false;
  20. // Extract it.
  21. ExtractTar Tar(Deb.GetFile(),Member->Size, "gzip");
  22. NullStream Dir;
  23. if (Tar.Go(Dir) == false)
  24. return false;
  25. return true;
  26. }
  27. int main(int argc, const char *argv[])
  28. {
  29. Test(argv[1]);
  30. _error->DumpErrors();
  31. return 0;
  32. }