public
Last active

Simple FileIO Service for WebOS

  • Download Gist
ReadDirAssistant.js
JavaScript
1 2 3 4 5 6 7 8 9 10
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 }; });
}
ReadFileAssistant.js
JavaScript
1 2 3 4 5 6 7 8 9 10
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 }; });
}
WriteFileAssistant.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11
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 }; });
}
services.json
JSON
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
{
"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
}
]
}
]
}
sources.json
JSON
1 2 3 4 5 6
[
{ "library": { "name": "foundations", "version": "1.0" } },
{ "source": "ReadDirAssistant.js" },
{ "source": "WriteFileAssistant.js" },
{ "source": "ReadFileAssistant.js" }
]

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.