0
votes

I am completely new to zLib and I am confused on how to use it. This is what I am trying to do using c++, but without writing to disk, so using a buffer or something:

Take a vector of integers stored in an std::vector print it all out in a text file with spaces in between each element. Compress it using zLib then save the size of that compressed file in bytes to an integer variable later used for computation and whatever.

Any help is appreciated, thanks :)

1
And your question is?..ForceBru
How would I do this in c++ using zLibAllen Huang

1 Answers

0
votes

zlib has compress and uncompress functions that take pointers to input and output buffers (along with a maximum size for each).

In your case, I'd start with a std::stringstream to turn the integers into text form (with spaces in between). Then use that stream's .str() to retrieve the content as a string. Use the string's .c_str() to retrieve a pointer to the data it contains, which you can then pass to compress.

For the destination, it takes a pointer to the buffer and a pointer to a long int. It writes the compressed size to that long int, so that's the value you seem to want to save for later computation and such.