3

If I use the java.util.zip.Deflater to compress a piece of text with a set dictionary of "apple orange banana" for the sake of argument, do I have to use this exact dictionary to decompress the text?

If I were to use a more up to date dictionary to decompress it, "apple orange banana grape", then the decompressed text is just garbage. Is it possible to update a dictionary without breaking the Inflater or do I have to implement some sort of versioning?

Thanks, Samuel.

Qor
  • 153
  • 5

2 Answers2

1

Ok so I solved the issue (sort of).

It is ok to append new elements to the dictionary so long as it is to the start of the dictionary. eg.

  • "apple orange banana" - original dictionary
  • "apple orange banana grape" - will break decompression, garbage output
  • "grape apple orange banana" - will work, just a little fragile.

Thanks to anyone who took a look at this question :-)

Qor
  • 153
  • 5
0

You must use exactly the same dictionary when compressing and decompressing. Anything else may result in corrupted data.

Mark Adler
  • 101,978
  • 13
  • 118
  • 158