Skip to content

@nils-werner /ReadDirAssistant.js
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
Something went wrong with that request. Please try again.