Example string compression/decompression somewhere?


#1

Does anyone have an example of how to use the GZIP classes to simply compress an arbitrary string to a new string and vice versa?

Essentially, I’d like to be able to write

String foo = Compress(“This is a test”);

and then later

String bar = Decompress(foo)

In practice, these strings could be many megabytes long

Candidly, I’m struggling with how to use MemoryBlock, MemoryInputStream, MemoryOutputStream with the GZIPCompressorOutputStream and GZIPDecompressorInputStream to do what seems like ought to be very simple.

While I have found a few questions about this stuff from search, answers are not so forthcoming. I know how to do this kind of thing with the zlib directly but I’d like to “live” in JUCE for this.

Thanks in advance


#2

https://forum.juce.com/search?q=ZipFile


#3

Sigh — not intending to be rude but what part of While I have found a few questions about this stuff from search, answers are not so forthcoming wasn’t clear?

Of course I did that search (and other similar searches) already (and had found your question about hex strings and decompression by the way)


#4

Have you tried looking at the unit tests at the bottom of juce_ZipFile.cpp?


#5

No I had not — that’s a great suggestion - just looked — I can probably use that approach. I was trying to use the GZIP* classes — but this looks like it will do just as well.

Thanks so much


#6

You could also look at GZIPDecompressorInputStreamTests and friends.