zlib - compress 함수

1942 단어
/*
× zlib compress uncompress     ,
×                  
××××××××××××××××××××××××××××××××××××××××××××××××
×   :z_compress           ××××××××××
××××××××××××××××××××××××××××××××××××××××××××××××
×     :     +       +    ××
××××××××××××××××××××××××××××××××××××××××××××××××
*/

#include 
#include 
#include 

int main(int argc,char* argv[]) {
    FILE* file;
    uLong flen;
    unsigned char* fbuf = NULL;
    uLong clen;
    unsigned char* cbuf = NULL;

    //        srcfile           dstfile   
    if(argc<3) {
        printf("Usage: z_compress srcfile dstfile
"); return -1; } if ( (file = fopen(argv[1],"rb")) ==NULL) { printf("Can\'t open %s!
",argv[1]); return -1; } // fseek(file,0L,SEEK_END); // flen = ftell(file); // fseek(file,0L,SEEK_SET); if ( (fbuf=(unsigned char*)malloc(sizeof(unsigned char)* flen))==NULL) { printf("No enough memory!
"); fclose(file); return -1; } fread(fbuf, sizeof(unsigned char),flen,file); // clen = compressBound(flen); if ( (cbuf=(unsigned char*)malloc(sizeof(unsigned char)* clen))==NULL) { printf("No enough memory!
"); fclose(file); return -1; } if (compress(cbuf,&clen,fbuf,flen)!=Z_OK) { printf("Compress %s failed!
",argv[1]); return -1; } fclose(file); if ((file = fopen(argv[2],"wb")) ==NULL) { printf("Can\'t create %s!
",argv[2]); return -1; } // fwrite(&flen, sizeof(uLong),1,file); // fwrite(&clen,sizeof(uLong),1,file); // fwrite(cbuf,sizeof(unsigned char),clen,file); fclose(file); free(fbuf); free(cbuf); return 0; }

좋은 웹페이지 즐겨찾기