testdeb.cc 961 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. static 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. if (argc != 2) {
  30. std::cout << "One parameter expected - given " << argc << std::endl;
  31. return 100;
  32. }
  33. Test(argv[1]);
  34. _error->DumpErrors();
  35. return 0;
  36. }