Bug: can not decompress for some compressed string
norangit opened this issue · comments
Hi,
I have a case to compress json string, bug can not decompress correctly;
input:
const data = {"tabs":[],"config":{"editable":false,"pinnedTab":false}}
then call LZString.compress(JSON.stringify(data))
output:
'㞂ࡠ䘌쁭˨ڄذ㶀急胦⦀☆䔀㙤➄듆稀㠓躔ʭ⍦갂\x00'
then JSON.parse(LZString.decompress(str))
got null, can not get back to origin data.
can you help me?
Please do not use the compress
method, which produces an output that cannot be reliably stored in some some browsers, as specified in the documentation. Use compressToUTF16
instead (and decompressFromUTF16
to decompress)
got it. thanks very much!
@yarden-app There is no issue with compressToUTF16
if you feed decompress with the exact output of compress. If, however, you convert that UTF16 to something else, such as UTF8 then back to UTF16, chances are the UTF16 string you get back is not what you had in the beginning, so obviously you cannot decompress it.