File extension?
Richienb opened this issue · comments
If I were to store the output of lz-string
as a file, what should the extension be?
Well, LZString compresses UTF16 strings to more compact UTF16 strings, so it's not really intended to have its own file format. So none of what I'm about to write is official guidelines, I'm just trying to think along and give some helpful suggestions. Let me know if it works for you.
Given that we don't really need a file format of our own, your question becomes more one about storing plain-text, for which you have a number of options. The most obvious and cross-platform friendly would be a simple .txt
file (UTF encoded of course). Alternatively, if you are compressing JSON data, .json
arguably also works, since storing a plain string is actually valid JSON!
But that misses the point a bit: I guess you want to know which file extension is appropriate so that intent is stored in the filename, right? And something like mydata.txt
or mydata.json
does not convey that the data in that text is compressed. But there's a simple way to achieve that: mydata.lzstring.txt
or mydata.lzstring.json
. The latter can be interpreted as "a JSON file compressed with lzstring".
Then, if you want load the data later you can just test if the filename ends with .lzstring.txt
to verify it's a LZString compressed string, or .lzstring.json
to verify it's data that you should run through JSON.parse(LZString.decompress(<some DOMString to your file>))
(assuming you are using JavaScript in your browser) to get your data back.
Does this answer your questions, or were you trying to do something else?
Yep. Thanks for that information!