Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Somehow compressToBase64() returns string end with 3 equal sign "===" #110

Open
linkenmin opened this issue Dec 14, 2017 · 12 comments
Open
Labels

Comments

@linkenmin
Copy link

linkenmin commented Dec 14, 2017

Somehow compressToBase64() returns string end with 3 equal sign "===", which is not a valid format by base64 definition.
Does this behavior meet your expectation?
Thank you.

Example source:
abcdef

Result:
IYIwxgJgpgZkA===

@nickion
Copy link

nickion commented Dec 15, 2017

The faulty code is
switch (res.length % 4) { // To produce valid Base64
and the following switch statement. It should be a mod 3 with cases for 0, 1 and 2.

@pieroxy
Copy link
Owner

pieroxy commented Jan 7, 2018

Nice catch, thanks. Will fix soon.

@nickion
Copy link

nickion commented Jan 8, 2018

and thanks for the library; spent a while looking and testing libs for compressing local storage, and yours was by far the best overall that I found.

@GeekStocks
Copy link

Yes @pieroxy we love this lib too — will likely implement it when this Base64 bug is squashed. Use the Base64 in testing alot, thanks @linkenmin for the catch and @nickion for the fix!

@Rycochet Rycochet added the bug label Jun 29, 2018
@AmericanY
Copy link

import lzstring


x = "N4IgLgngDgpiBcIBGAnAhgOwCYgDQgBs0EQYM8QBHASxIAYBaGAOSwAUAOAMzAHY0AYgHcAWtQCuADQD2WNAQBeADyRIhCgIIBFLABlpANQIARAEIBNABIQAVlwCi0gKoBZALwVK4mN4QBGfAB9Ej8/Og46EABfIAAA="

z = lzstring.LZString().decompressFromBase64(x)

y = lzstring.LZString().compressToBase64(z)

print(y)

print(x == y)

The padding is incorrect!

@AmericanY
Copy link

@nickion Hello, could you please help me out to solve that?

@pieroxy
Copy link
Owner

pieroxy commented Mar 23, 2021

LZString works the other way: For any string, if you compress it and then decompress it, the original and resulting strings will be equal.

The padding changed in a version (I don't remember which one to be honest). What are you trying to achieve here ?

@AmericanY
Copy link

@pieroxy Thanks for your response. Actually, am trying to decompress and compress the value to be equal together. as am trying to call an API with those value which require lzstring compress

@AmericanY
Copy link

@pieroxy solved by installing pip install "lzstring==1.0.3"

@pieroxy
Copy link
Owner

pieroxy commented Mar 23, 2021

Great. There's probably a tiny bit of loss in performance, but this should be nothing to worry about.

@Rycochet Rycochet reopened this Jun 22, 2023
@Rycochet
Copy link
Collaborator

Discussion - 64f2f29#commitcomment-119254610

@Rycochet
Copy link
Collaborator

Will create a second endpoint that has the correct base64 encoding, and mark the old one as deprecated (in Typescript typing, and a one-time console warning about the old one) - will be released as part of v2, and the other implementations will be poked to support the correct encoding, followed by the old endpoint being removed in v3 and correct encoding being the way forward (no idea of that release date, but not any time soon!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants