lz-string icon indicating copy to clipboard operation
lz-string copied to clipboard

Add "header" for compressed items

Open hefler opened this issue 5 years ago • 5 comments

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.

hefler avatar Oct 17 '18 11:10 hefler

That breaks compatibility - far better for you to do it yourself if there's a possibility it's not compressed.

Rycochet avatar Oct 17 '18 11:10 Rycochet

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.

hefler avatar Oct 17 '18 12:10 hefler

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) ;-)

Rycochet avatar Oct 17 '18 13:10 Rycochet

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 avatar Oct 19 '18 14:10 JobLeonard

@JobLeonard That's more like it! 😃 👏

hefler avatar Oct 19 '18 15:10 hefler