hyperxpro / Brotli4j

Brotli4j provides Brotli compression and decompression for Java.
Apache License 2.0
102 stars 35 forks source link

[Bug] Data changes when encode and then decode with dictionary #114

Closed tohkayuri closed 10 months ago

tohkayuri commented 10 months ago
  1. I trained a dict using https://github.com/google/brotli/blob/master/research/dictionary_generator.cc
  2. encode a byte array using this dict
  3. and then decode it
  4. I got different bytes compare to the original

So what's the problem?

I guess it may be brotli's bug, so I wonder if the new release version can solve this problem.

hyperxpro commented 10 months ago

Hey, Sorry I couldn't follow up since I was on vacation. Since you closed the issue, would you mind explaining how you fixed it?

tohkayuri commented 10 months ago

I mistakenly used the decompressed sdk. I should pass the raw dict data not PreparedDictionary.getData() to brotliOutputStream.attachDictionary. I have no idea why the compress and decompress have such a different interface.

hyperxpro commented 10 months ago

I agree about the problems with the Brotli API design. It's coming directly from the official repo. For 1.x releases, I choose to use the majority of official APIs but for 2.x release, I will re-write user-friendly APIs from scratch.