#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <stdlib.h>#include <libtar.h>#include <bzlib.h>#include <unistd.h>int main(){ TAR *pTar; char tar@R_404_6852@name[] = "@R_404_6852@.tar"; char srcDir[] = "dirToZip/"; char extractTo[] = "."; tar_open(&pTar,tar@R_404_6852@name,NulL,O_WRONLY | O_CREAT,0644,TAR_GNU); tar_append_tree(pTar,srcDir,extractTo); close(tar_fd(pTar)); int tarFD = open(tar@R_404_6852@name,O_RDONLY); char tbz2@R_404_6852@name[] = "@R_404_6852@.tar.bz2"; @R_404_6852@ *tbz2@R_404_6852@ = fopen(tbz2@R_404_6852@name,"wb"); int bzError; const int BLOCK_MulTIPLIER = 7; BZ@R_404_6852@ *pBz = BZ2_bzWriteOpen(&bzError,tbz2@R_404_6852@,BLOCK_MulTIPLIER,0); const int BUF_SIZE = 10000; char* buf = new char[BUF_SIZE]; ssize_t bytesRead; while((bytesRead = read(tarFD,buf,BUF_SIZE)) > 0) { BZ2_bzWrite(&bzError,pBz,bytesRead); } BZ2_bzWriteClose(&bzError,NulL); close(tarFD); remove(tar@R_404_6852@name); delete[] buf;}总结
以上是内存溢出为你收集整理的如何使用C中的libbz2压缩目录全部内容,希望文章能够帮你解决如何使用C中的libbz2压缩目录所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)