# Example string compression/decompression somewhere?

**URL:** <https://forum.juce.com/t/example-string-compression-decompression-somewhere/31809>\
**Category:** General JUCE discussion\
**Created:** [February 17, 2019, 4:16pm UTC](https://forum.juce.com/t/example-string-compression-decompression-somewhere/31809 "2019-02-17T16:16:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dhjdhj](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dhjdhj/32/39_2.png) [@dhjdhj](https://forum.juce.com/u/dhjdhj)\
**Post date:** [February 17, 2019, 4:16pm UTC](https://forum.juce.com/t/example-string-compression-decompression-somewhere/31809/1 "2019-02-17T16:16:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![matkatmusic](https://avatars.discourse-cdn.com/v4/letter/m/dfb087/32.png) [@matkatmusic](https://forum.juce.com/u/matkatmusic)\
**Post date:** [February 17, 2019, 5:29pm UTC](https://forum.juce.com/t/example-string-compression-decompression-somewhere/31809/2 "2019-02-17T17:29:07Z")

</div>

[https://forum.juce.com/search?q=ZipFile](https://forum.juce.com/search?q=ZipFile)

---

<div class="post-metadata">

**Author:** ![dhjdhj](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dhjdhj/32/39_2.png) [@dhjdhj](https://forum.juce.com/u/dhjdhj)\
**Post date:** [February 17, 2019, 5:50pm UTC](https://forum.juce.com/t/example-string-compression-decompression-somewhere/31809/3 "2019-02-17T17:50:32Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![t0m](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/t0m/32/16413_2.png) [@t0m](https://forum.juce.com/u/t0m)\
**Post date:** [February 18, 2019, 11:20am UTC](https://forum.juce.com/t/example-string-compression-decompression-somewhere/31809/4 "2019-02-18T11:20:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dhjdhj](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dhjdhj/32/39_2.png) [@dhjdhj](https://forum.juce.com/u/dhjdhj)\
**Post date:** [February 18, 2019, 12:07pm UTC](https://forum.juce.com/t/example-string-compression-decompression-somewhere/31809/5 "2019-02-18T12:07:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![t0m](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/t0m/32/16413_2.png) [@t0m](https://forum.juce.com/u/t0m)\
**Post date:** [February 18, 2019, 12:37pm UTC](https://forum.juce.com/t/example-string-compression-decompression-somewhere/31809/6 "2019-02-18T12:37:51Z")

</div>

You could also look at `GZIPDecompressorInputStreamTests` and friends.
