1

I try to compress memory data by using libbz2 library in C program.

Should I use this function of libbz2?:

int BZ2_bzCompress ( bz_stream *strm, int action );

Can anyone show me an example?

Thank you.

mechanical_meat
  • 163,903
  • 24
  • 228
  • 223
ziguli
  • 161
  • 1
  • 5
  • possible duplicate of [How to compress a directory with libbz2 in C++](http://stackoverflow.com/questions/813223/how-to-compress-a-directory-with-libbz2-in-c) – Alok Save Mar 06 '12 at 04:09

1 Answers1

2

http://www.bzip.org/1.0.3/html/util-fns.html

Use BZ2_bzBuffToBuffCompress() and BZ2_bzBuffToBuffDecompress() for simple paired compress/decompress.

This page describes the meaning of the last 3 parms: http://www.bzip.org/1.0.3/html/low-level.html

Joe
  • 2,946
  • 18
  • 17
  • How do I know the compress/decompress size so I can allocate the buffers properly? – karliwson Nov 20 '16 at 16:19
  • @karliwson, you can't... Either this information is already known (you have it previously stored, such as you stored the initial buffer length elsewhere), or you over-allocate. For decompression, the latter is nearly impossible. – Alex Huszagh Apr 08 '17 at 22:58