Guest User

Untitled

a guest
Jun 19th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #include <sys/types.h>
  2. #include <sys/stat.h>
  3. #include <fcntl.h>
  4. #include <stdlib.h>
  5. #include <libtar.h>
  6. #include <bzlib.h>
  7. #include <unistd.h>
  8.  
  9. int main()
  10. {
  11. TAR *pTar;
  12. char tarFilename[] = "file.tar";
  13. char srcDir[] = "dirToZip/";
  14. char extractTo[] = ".";
  15.  
  16. tar_open(&pTar, tarFilename, NULL, O_WRONLY | O_CREAT, 0644, TAR_GNU);
  17. tar_append_tree(pTar, srcDir, extractTo);
  18.  
  19. close(tar_fd(pTar));
  20.  
  21. int tarFD = open(tarFilename, O_RDONLY);
  22.  
  23. char tbz2Filename[] = "file.tar.bz2";
  24. FILE *tbz2File = fopen(tbz2Filename, "wb");
  25. int bzError;
  26. const int BLOCK_MULTIPLIER = 7;
  27. BZFILE *pBz = BZ2_bzWriteOpen(&bzError, tbz2File, BLOCK_MULTIPLIER, 0, 0);
  28.  
  29. const int BUF_SIZE = 10000;
  30. char* buf = new char[BUF_SIZE];
  31. ssize_t bytesRead;
  32. while((bytesRead = read(tarFD, buf, BUF_SIZE)) > 0)
  33. {
  34. BZ2_bzWrite(&bzError, pBz, buf, bytesRead);
  35. }
  36. BZ2_bzWriteClose(&bzError, pBz, 0, NULL, NULL);
  37. close(tarFD);
  38. remove(tarFilename);
  39.  
  40. delete[] buf;
  41.  
  42. }
  43.  
  44. system("/path/to/gtar cfj tarballname.tar.bz2 dirname");
Add Comment
Please, Sign In to add comment