Skip to content

Instantly share code, notes, and snippets.

@mikebranstein
Created January 19, 2016 02:31
Show Gist options
  • Save mikebranstein/b3ba202f4cbe025d9550 to your computer and use it in GitHub Desktop.
Save mikebranstein/b3ba202f4cbe025d9550 to your computer and use it in GitHub Desktop.
NativeScript module for storing data offline in a file within an app's file-system
var fsModule = require("file-system");
var offline = {
_fileName: "offline-data.json",
write: function(data) {
var file = fsModule.knownFolders.documents().getFile(offline._fileName);
return file.writeText(JSON.stringify(data));
},
remove: function() {
var file = fsModule.knownFolders.documents().getFile(offline._fileName);
return file.remove();
},
read: function() {
var file = fsModule.knownFolders.documents().getFile(offline._fileName);
return file.readText();
}
};
module.exports = offline;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment