Comments (10)
I identified an issue with the custom encoders - using base64 as a proof of concept - marking them as experimental until this is fixed (it's an awkward one - but they're only implemented on here and if not going into something that saves code they can decompress the compressed content safely)
from lz-string.
Short answer: no
Longer answer: In order to compress to something it needs to be able to decompress it again. When there are "special" codes such as in utf8 then the library would need to understand them all for both sides of that. Unfortunately utf is an evolving standard, and that would mean having it work at the time of coding (probably!), and then break at some point in the future when new utf codes are added and they get special meaning (or conversely unknown codes that get swapped with ?
get a glyph and suddenly start behaving differently).
If your code is getting z-lib compressed (ie, browser compression) then it won't make much difference using base64.
from lz-string.
I tried compressToUTF16
, and in the cases I ran it through it didn't produce codes like that. So this doesn't mean it will never produce UTF8 codes, right?
What if I replace \x
before saving with something unique, then change it back before decompressing? I think this would work if there are some characters that are guaranteed NOT to be generated in the compression output by the lib. Are there such characters?
from lz-string.
It's a plain encoded binary data blob - so every character is possible, and that means that whatever you replace it with is also potentially there already - I also don't know NetSuite, but given that most backend techs use UTF8 rather than UTF16 it definitely sounds like a development headache trying to account for these things.
from lz-string.
Got it.
I will use compressToBase64
or compressToEncodedURIComponent
, and try to be satisfied with the amount of compression ๐ข
Thanks for your explansation!
from lz-string.
compressToCustom and decompressFromCustom should work for your usecase, if you can provide the string of allowed characters.
from lz-string.
compressToCustom and decompressFromCustom should work for your usecase, if you can provide the string of allowed characters.
I tried it, but the length of the output is larger than compressToEncodedURIComponent
's output. I thought it would be as small as compress
while changing utf-8 codes with one of the characters I am passing.
from lz-string.
Can you provide the code you used? Since compressToEncodedURIComponent
only uses 65 characters, a compressToCustom with almost all utf8 characters should be significantly smaller...
from lz-string.
Sorry for the late reply.
I used ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
This is a simple example:
LZString.compress(`{"name": "Adam", "age": 30}`)
'ใโถเก ๋ๆ
์แไฆํๆฆฮ์์ฐใ๎'
LZString.compressToEncodedURIComponent(`{"name": "Adam", "age": 30}`)
'N4IgdghgtgpiBcACEBBAJtEAaZEDmcSAzAAwC+QA'
LZString.compressToCustom(`{"name": "Adam", "age": 30}`, `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`)
'DrMCKCAikMHoGgtMwyBEUEQ2N48HB3AO1NFWNkUDMXPLa'
from lz-string.
@marwan-nwh Check #200 - short answer is that it's deterministic, but not the expected output when using a dictionary that is a perfect binary length - your comparison is also not valid as EncodedURI has extra processing, should be using plain base64
from lz-string.
Related Issues (20)
- Crash with large strings when running on Hermes (React Native)
- Is there a way to allow custom dictionaries? HOT 9
- How to realize that only specified characters are allowed to appear in the compression result? HOT 1
- LZ-String port to current typescript HOT 9
- Tag for v1.5.0 HOT 2
- Version 2 TODO list HOT 15
- Feature request: compress to source-compatible character set HOT 1
- New port for a linux executable HOT 1
- `decompressFromBase64` can return `null` HOT 7
- Docs: JSPerf.com links are no longer valid
- Docs: A Complete Demo for various compression/decompression HOT 3
- Docs: TSDoc HOT 3
- License Inconsistencies HOT 5
- Community Question: Breaking Changes and Version 2! HOT 10
- [email protected] build with warnings HOT 4
- Feature request: a non minified js file as a result of building v2 HOT 2
- Chrome virus warning with compressToEncodedURIComponent URL HOT 2
- CLI support for decompressing base64 encoded files HOT 1
- Please investigate the slow (irresponsible) LZString issue in Edge HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lz-string.