본문 바로가기

프로그래밍/C-CPP

[SO번역] zlib: `deflate` 함수와 `compress` 함수의 차이점은

반응형

http://stackoverflow.com/questions/10166122/zlib-differences-between-the-deflate-and-compress-functions


zlib: `deflate` 함수와 `compress` 함수의 차이점은

zlib: Differences Between the `deflate` and `compress` Functions





질문 :


zlib의 deflate() 과 compress() 함수의 차이점은 무엇인가요?

온라인 샘플을 훑어봤는데, 어떤 것은 deflate 를 쓰고, 다른 것은 compress 를 쓰더군요.

어떤 상황에서 어떤 것을 쓸지 어떻게 결정하나요?


What are the differences between the deflate() and compress() functions in zlib?

I have looked through online examples and some used deflate while others used compress.

How should I decide which situation I would use one over the other?


compression zlib deflate

shareeditflag

edited Jul 3 '13 at 7:21

asked Apr 15 '12 at 21:09





답변 : (답변자는 zlib 라이브러리 작성자임.)


compress() 는 한번의 호출로 압축할 때 씁니다. 언제나 zlib 포맷으로 저장합니다. 즉, 맨 앞의 2바이트 헤더와 제일 마지막 4바이트 체크값이 들어갑니다. compress() 는 이 함수 하나로 사용됩니다.


deflate() 는 한번에 한 덩어리씩 압축하는데 쓰입니다. 또는 gzip-wrapped, raw 형식 그리고 메모리 레벨이나 압축 방식의 다른 옵션과 함께 사용됩니다.


한번에 모든 데이터를 가지고 있고, 결과값을 모두 담을 충분한 메모리가 있으면 compress() 를 사용합니다. 또한 기본 압축포맷, 메모리사용, 압축방법을 사용하게 됩니다. 아니라면 deflate() 를 사용합니다.


deflate() 는 혼자서 사용되지 않고, deflateInit() 혹은 deflateInit2() 로 z_stream 구조체를 초기화한 후에 사용합니다. 초기화 후에 deflate() 를 한번 또는 여러번 사용하여 압축할 데이터를 처리하고, 결과를 만들어냅니다. 마지막에는 deflateEnd() 를 호출하여 구조체 메모리를 해제합니다. 더 상세한 정보는 zlib.h 의 다큐멘테이션을 읽거나, http://zlib.net/zlib_how.html 을 보세요.



compress() is used to compress the data in a single call, and always compresses to the zlib format, which is deflate data with a two-byte header and a four-byte check value trailer. compress() is used by itself.


deflate() is used to compress data a chunk at a time, and/or to compress to other formats such as gzip-wrapped or raw, and with other options, such as memory levels and compression strategies.


You would use compress() if you have all the data available at once and enough memory to hold the result, and you want the default compression format, memory usage, and strategy. Otherwise, you would use deflate().


deflate() is not used by itself. You need to use deflateInit() or deflateInit2() to initialize the z_stream structure used by deflate(). Then you call deflate() one or more times to take in data to compress and to make available the result. At the end, deflateEnd() is called to free the memory resources used in the structure. You can read the documentation in zlib.h and at http://zlib.net/zlib_how.html for more information.


shareeditflag

edited Apr 16 '12 at 3:42

answered Apr 16 '12 at 3:36


Mark Adler

25.4k13061

13

 

Mark Adler is definitely the authority on this one. – Xenon Apr 16 '12 at 3:52 

thank you. i read some of it but didn't quite understand it at first. It was just too much information, but i've gone and reread it. – mma1480 Apr 16 '12 at 7:24

great...now i know why it is called adler-32 – raj_gt1 Nov 27 '12 at 14:36

728x90