-
Hi, I am trying to use fflate to compress some text content in a way that can be embedded in a URL query param. This implementation only works passing the Ideally I would like to use the full utf-8 and use base64 to encode that as binary data, but it seems to fail due to "invalid characters" My guess is that Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You're actually already using the most effective strategy possible for what you're trying to do. If you log the compressed and base64 encoded lengths, you'll see that The one change you can make is how you encode the original string. Right now you're assuming your input is only Latin-1, i.e. adding emojis will break it. If you change your call for the string to Uint8Array conversion from It's not optimal but for Base64 this is as good as it gets. Let me know if you have any questions. |
Beta Was this translation helpful? Give feedback.
You're actually already using the most effective strategy possible for what you're trying to do. If you log the compressed and base64 encoded lengths, you'll see that
btoa(strFromU8(compressedData, true))
is always 33% larger thancompressedData
, which is the optimal result for Base64 encoding. You're correct thatbtoa
andatob
don't support Unicode: they only support Latin-1, a 256 character subset. Regardless, if you try to dostrToU8(strFromU8(compressedData))
it will actually not work becausecompressedData
is not valid UTF-8 in the first place.The one change you can make is how you encode the original string. Right now you're assuming your input is only Latin-1, i.e. adding emojis w…