Closed jcalfee closed 8 years ago
Good point. I use this library for either: 1) testing code that will have to operate in a browser, or (much less often) 2) code that has to operate in both the browser and server. If the latter, the lack of atomicity would not be critical for my applications.
I'm busy with some other stuff right now, but I would gladly consider a pull request that is either atomic or add some warning to the docs. I suspect it could be easily done by using a temporary file and renaming (as suggested in the SO post you also provided).
On another note, I have thoughts of upgrading this to support associative array syntax (e.g. localStorage['myKey'] = 'myValue'
) using the harmony support for Proxies.
I could be swayed to work on both depending upon how you are using node-localstorage. I want to support its users needs. Can you tell me more about your use case?
It will be testing and development only for now. However, it is for crypto so if anyone sets up a server that will be important. I was thinking a simple file rename too.
With the new atomic file operations, this is more atomic now. There still may be some issues if more than one file operation is necessary for the method, but the probability is greatly reduced now.
Please add a warning or fix (I prefer the later)...
http://www.w3.org/TR/webstorage/#the-storage-interface
"The setItem() and removeItem() methods must be atomic with respect to failure. In the case of failure, the method does nothing. That is, changes to the data storage area must either be successful, or the data storage area must not be changed at all."