eduardtomasek / lz-string-python Goto Github PK
View Code? Open in Web Editor NEWlz-string for python 3
License: Do What The F*ck You Want To Public License
lz-string for python 3
License: Do What The F*ck You Want To Public License
There seems to be some issue in decompressFromUTF16.. the following code does not work. Is there something wrong?
chk_str = "Test String"
compressed = x.compressToUTF16(chk_str)
print(compressed)
print(x.decompressFromUTF16(compressed))
Hi,
because of changes made in the encoding method of lz-string(pieroxy/lz-string@2d5a419), the javascript version can produce strings that can't be decompressed with this version.
This example raise an IndexError:
l=lzstring.LZString()
l.decompresFromBase64("A4cwdA9gtAcg9APyA===")
If anyone is interested I've found this https://github.com/pieroxy/lz-string/blob/0dda98caa06c4c09e251a96378538169dfbc5a5f/libs/lz-string.js as the last version compatible.
import lzstring
x = "N4IgLgngDgpiBcIBGAnAhgOwCYgDQgBs0EQYM8QBHASxIAYBaGAOSwAUAOAMzAHY0AYgHcAWtQCuADQD2WNAQBeADyRIhCgIIBFLABlpANQIARAEIBNABIQAVlwCi0gKoBZALwVK4mN4QBGfAB9Ej8/Og46EABfIAAA="
z = lzstring.LZString().decompressFromBase64(x)
y = lzstring.LZString().compressToBase64(z)
print(y)
print(x == y)
The padding is incorrect!
Hi,
I'd like to use this in a little project I'm working on at work, and I was wondering if you could clarify the license this code is under. Is it WTFPL like lz-string itself?
Many thanks!
Taking this code out for a spin, because I use Python to generate JS code in one application, I loaded a random text file off my system into Python, it was 253990 characters, and ran compress, and got 41993 characters back. It decompressed fine. Yay!
But then I tried out compressToUTF16, and got 8 characters back. And there seems not to be a decompressFromUTF16! But I sort of doubt that 8 characters could hold the original file...
import lzstring
x = lzstring.LZString()
Error:
Traceback (most recent call last):
File "try.py", line 5, in
print x.compressToBase64("Dak0tajdjdjdddddddddddddddddddddddd")
File "/home/solstice/lzstring.py", line 256, in compressToBase64
string = self.compress(string)
File "/home/solstice/lzstring.py", line 64, in compress
context_data_string += chr(context_data_val)
ValueError: chr() arg not in range(256)
the context_data_val is 2180 at this point!!
Hi,
When I execute in python
a = "N4IgKgTglghgNgBQPZQHYBcQC4DaOCMALPgOwn4AcJFhAnAMwkA0IAVOwAQDK6ME6HdNHgd2rEAF0JAXyAA="
x = lzstring.LZString()
x.decompresFromBase64(a)
it throws me the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "lzstring.py", line 578, in decompresFromBase64
output += chr(output_ | chr2)
ValueError: chr() arg not in range(256)
But in the javascript implementation it decodes it perfectly.
Im trying to decompress an api response that is compressed in utf-16 but when i try it i get the following error "UnicodeEncodeError: 'utf-8' codec can't encode character '\udc00' in position 0: surrogates not allowed" (note that the character is not always the same). I researched it and i found that the character is probably an emoji. I tryied to encode and decode the string before the decpmpress with surrogateescape, or surrogatepass with no luck.. Any idea how to fix it?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.