Created
June 8, 2011 10:44
-
-
Save nils-werner/1014188 to your computer and use it in GitHub Desktop.
Simple FileIO Service for WebOS
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 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 }; }); | |
} |
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 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 }; }); | |
} |
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
{ | |
"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 | |
} | |
] | |
} | |
] | |
} |
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
[ | |
{ "library": { "name": "foundations", "version": "1.0" } }, | |
{ "source": "ReadDirAssistant.js" }, | |
{ "source": "WriteFileAssistant.js" }, | |
{ "source": "ReadFileAssistant.js" } | |
] |
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 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