Yep, that’s a performance optimization that’s actually useful in the library, but not really for demonstrating how it works (which is why I left the optimization out of my answer; in the library, I don’t “re-read” the file when I already “know” its contents). I didn’t have the time to rewrite this code when I answered the question, so that’s why it’s in my answer
That once upon a time was an option with which it was possible to append to a file’s content using UXP. It seems to be removed (at least from the docs) now, though
@aldobsom Sorry, but I’ll need some more details in order to help . What do you expect the code to do, what does it do, what doesn’t it do, what have you tried so far etc.
Generally speaking, the code I posted here was more of a reference on how it might be possible to do it, not a copy-and-paste example (my library does this storage, after all, and the code is just a pointer to the way the library does it). For example, when using the code outside a class (with a function init), this doesn’t exist, meaning this.init() becomes init() and so on. All in all, this isn’t a copy-and-pastable example.
If you want to store JSON-based data, I recommend (shameless advertisement of a free-to-use thing ) using the library instead of using my code posted here since the lib is maintained and therefore won’t break in the future. In other use-cases, the example code above is more about giving an idea on how to do it.
@pklaschka for example this code will not read the json file and if there is no such file it will not create a new one since file.isFile seems to break the plugin frozen
I’m currently unable to test it myself, right now. I do know that the code of the actual library works (cf. https://github.com/pklaschka/xd-storage-helper/blob/master/storage-helper.js), as I use it in my plugins and have tested it earlier today. I’ll hopefully be able to test (and maybe correct) the code I’ve posted here in a few days and come back to you on it, but for now, I’ll have to leave it like this: