Created
January 19, 2016 02:31
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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