lz-string
lz-string copied to clipboard
Add "header" for compressed items
Since your main goal was to use it with localStorage
(similar to mine). It would be interesting to prepend on the compressed string a kind of header. Something along the lines of data URIs in CSS but less verbose. Example:
"lz;<encoded data>"
In that way it makes easier to identify if the data being used is compressed or not.
That breaks compatibility - far better for you to do it yourself if there's a possibility it's not compressed.
Fair enough, I've done it myself, I just thought it would be a good "enhancement". Regarding compatibility that would be an easy fix, just add a version flag and check against that, or add some global options for LZString
, for instance.
It's cross-platform and cross-language compatibility - there's no version string in it, just raw compressed data (which is where the command line archive tools wrap the raw data with all that extra info) ;-)
just add a version flag and check against that
As Rycochet mentioned: that's not so simple because the current format is pure a raw compression string without any metadata. However, I just wrote a proposal for how one might want to approach a newer format in a backwards-compatible way. Have a look.
@JobLeonard That's more like it! 😃 👏