Skip to content

Instantly share code, notes, and snippets.

@nils-werner
Created June 8, 2011 10:44
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nils-werner/1014188 to your computer and use it in GitHub Desktop.
Save nils-werner/1014188 to your computer and use it in GitHub Desktop.
Simple FileIO Service for WebOS
var ReadDirAssistant = function() {
}
ReadDirAssistant.prototype.run = function(future) {
var fs = IMPORTS.require("fs");
var path = this.controller.args.path;
fs.readdir(path, function(err, files) { future.result = { path: path, files: files }; });
}
var ReadFileAssistant = function() {
}
ReadFileAssistant.prototype.run = function(future) {
var fs = IMPORTS.require("fs");
var path = this.controller.args.path
fs.readFile(path, 'utf8', function(err,data) { future.result = { path: path, content: data }; });
}
{
"id": "com.yourapp.fileio",
"description": "FileIO Service",
"services": [
{
"name": "com.yourapp.fileio",
"description": "FileIO Service",
"commands": [
{
"name": "readdir",
"assistant": "ReadDirAssistant",
"public": true
},
{
"name": "writefile",
"assistant": "WriteFileAssistant",
"public": true
},
{
"name": "readfile",
"assistant": "ReadFileAssistant",
"public": true
}
]
}
]
}
[
{ "library": { "name": "foundations", "version": "1.0" } },
{ "source": "ReadDirAssistant.js" },
{ "source": "WriteFileAssistant.js" },
{ "source": "ReadFileAssistant.js" }
]
var WriteFileAssistant = function() {
}
WriteFileAssistant.prototype.run = function(future) {
var fs = IMPORTS.require("fs");
var path = this.controller.args.path
var content = this.controller.args.content
fs.writeFile(path, content, 'utf8', function(err) { future.result = { path: path, bytes: content.length, error: err }; });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment