Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

creating a gzip file in memory looking for cpp example

Tags:

c++

gzip

zlib

I am using the zlib to compress data but I need to create a valid gzip file with it in memory.

How do I correctly do that?

I need the file to be in memory but I'm not sure how to assemble it without writing to disk.

I have looked around but nothing clear cut stood out as a how to.

I know there's a gz_header but I'm not sure where the offset is in the file or how that's handled. Apparently there can be a trailer as well?

like image 522
cynistersix Avatar asked Dec 04 '25 18:12

cynistersix


1 Answers

You can use Boost.Iostream with Gzip filters to compress data. You can adapt the example to use a memory stream instead of a file stream.

like image 163
Anthony Avatar answered Dec 06 '25 07:12

Anthony



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!