프로그램언어/C++
zlib을 이용한 간단한 예제
에블릿
2009. 8. 7. 10:42
unsigned char* inbuf; unsigned char* outbuf; unsigned long INBUFSIZE; unsigned long OUTBUFSIZE; inbuf=new unsigned char[1000]; strcpy((char*)inbuf,"Is good?"); INBUFSIZE=strlen((char*)inbuf)+1; fprintf(stdout,"테스트용 문자열은 다음과 같다.\n"); fprintf(stdout,"%s\n\n",inbuf); //Upon entry, destLen is the total size of the destination buffer, //which must be at least 0.1% larger than sourceLen plus 12 bytes. //Integer의 반올림 문제 때문에 1을 더했다. OUTBUFSIZE=(unsigned long)1.001*(INBUFSIZE+12) + 1; outbuf=new unsigned char[OUTBUFSIZE]; //in-memory 압축을 위한 함수는 compress()와 compress2()가 있다. //여기서는 압축 레벨을 정할 수 있는 compress2()를 사용해 보겠다. //Compression Level은 다음과 같이 정의되어 있다. //#define Z_NO_COMPRESSION 0 //#define Z_BEST_SPEED 1 //#define Z_BEST_COMPRESSION 9 //#define Z_DEFAULT_COMPRESSION (-1) //default 압축은 레벨 6 int err=compress2(outbuf, &OUTBUFSIZE, inbuf, INBUFSIZE, Z_DEFAULT_COMPRESSION); //int err=compress(outbuf, &OUTBUFSIZE, inbuf, INBUFSIZE); //Compress2함수는 다음과 같은 에러 코드를 반환한다. //compress2 returns Z_OK if success, //Z_MEM_ERROR if there was not enough memory, //Z_BUF_ERROR if there was not enough room in the output buffer //Z_STREAM_ERROR if the level parameter is invalid
샘플 예제는 vc6으로 되어 있습니다.
출처 : http://kaistizen.net/project/Zip/UtilityFunction.htm 에서 좀 더 자세한 내용을 볼 수 있습니다.