added jsdoc tags

This commit is contained in:
David Westgate 2013-04-29 13:33:50 -03:00
parent 47aa3228c1
commit f4d6ff2f1f

View File

@ -1,98 +1,102 @@
/*
@author David Westgate, Rylan Doherty
@fileOverview The Input/Output functions of firerecord. Setting Path, creating files, and reading files
*/
var io = { var io = {
openPath : function() { /*
@description sets the paths of the script
const @return path of script selected
nsIFilePicker = Components.interfaces.nsIFilePicker; @see <a href="https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIFilePicker"> Mozilla Developer Network Example </a>
*/
var fp = Components.classes["@mozilla.org/filepicker;1"] openPath: function () {
.createInstance(nsIFilePicker); const
fp.init(window, "Dialog Title", nsIFilePicker.modeOpen); nsIFilePicker = Components.interfaces.nsIFilePicker;
fp.appendFilters(nsIFilePicker.filterAll | nsIFilePicker.filterText); var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
var rv = fp.show(); fp.init(window, "Dialog Title", nsIFilePicker.modeOpen);
if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) { fp.appendFilters(nsIFilePicker.filterAll | nsIFilePicker.filterText);
var file = fp.file; var rv = fp.show();
// Get the path as string. Note that you usually won't if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) {
// need to work with the string paths. var file = fp.file;
var path = fp.file.path; // Get the path as string. Note that you usually won't
// work with returned nsILocalFile... // need to work with the string paths.
} var path = fp.file.path;
return path; // work with returned nsILocalFile...
}, }
appendPath : function(path, contents) { return path;
alert("appended File"); },
var file1 = Components.classes["@mozilla.org/file/local;1"] /*
.createInstance(Components.interfaces.nsILocalFile); @description appends script by contents of event click
file1.initWithPath(path); @see <a href="https://developer.mozilla.org/en-US/docs/Code_snippets/File_I_O"> Mozilla Developer Network Example </a>
// alert("append file nullcheck: "+file1.toString()); */
var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"] appendPath: function (path, contents) {
.createInstance(Components.interfaces.nsIFileOutputStream); alert("appended File");
// use 0x02 | 0x10 to open file for appending. var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
foStream.init(file1, 0x02 | 0x10, 438, 0); file.initWithPath(path);
var converter = Components.classes["@mozilla.org/intl/converter-output-stream;1"] // alert("append file nullcheck: "+file1.toString());
.createInstance(Components.interfaces.nsIConverterOutputStream); var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutputStream);
converter.init(foStream, "UTF-8", 0, 0); // use 0x02 | 0x10 to open file for appending.
converter.writeString(contents); foStream.init(file, 0x02 | 0x10, 438, 0);
converter.close(); var converter = Components.classes["@mozilla.org/intl/converter-output-stream;1"].createInstance(Components.interfaces.nsIConverterOutputStream);
}, converter.init(foStream, "UTF-8", 0, 0);
newPath : function(path) { converter.writeString(contents);
converter.close();
const },
nsIFilePicker = Components.interfaces.nsIFilePicker; /*
@description sets path to address of a new file
var fp = Components.classes["@mozilla.org/filepicker;1"] @return path of new file
.createInstance(nsIFilePicker); @see <a href="https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIFilePicker"> Mozilla Developer Network Example </a>
fp.init(window, "Dialog Title", nsIFilePicker.modeSave); */
fp.appendFilters(nsIFilePicker.filterAll | nsIFilePicker.filterText); newPath: function (path) {
const
var rv = fp.show(); nsIFilePicker = Components.interfaces.nsIFilePicker;
if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) { var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
var file = fp.file; fp.init(window, "Dialog Title", nsIFilePicker.modeSave);
// Get the path as string. Note that you usually won't fp.appendFilters(nsIFilePicker.filterAll | nsIFilePicker.filterText);
// need to work with the string paths. var rv = fp.show();
var path = fp.file.path; if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) {
// work with returned nsILocalFile... var file = fp.file;
// Get the path as string. Note that you usually won't
} // need to work with the string paths.
return path; var path = fp.file.path;
}, // work with returned nsILocalFile...
createFile : function(path) { }
return path;
alert("created File"); },
var file1 = Components.classes["@mozilla.org/file/local;1"] /*
.createInstance(Components.interfaces.nsILocalFile); @description creates new file from path of newPath
file1.initWithPath(path); @see <a href="https://developer.mozilla.org/en-US/docs/Code_snippets/File_I_O"> Mozilla Developer Network Example </a>
*/
var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"] createFile: function (path) {
.createInstance(Components.interfaces.nsIFileOutputStream); alert("created File");
// use 0x02 | 0x10 to open file for appending. var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
foStream.init(file1, 0x02 | 0x08 | 0x20, 438, 0); file.initWithPath(path);
var converter = Components.classes["@mozilla.org/intl/converter-output-stream;1"] var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutputStream);
.createInstance(Components.interfaces.nsIConverterOutputStream); // use 0x02 | 0x10 to open file for appending.
converter.init(foStream, "UTF-8", 0, 0); foStream.init(file, 0x02 | 0x08 | 0x20, 438, 0);
var converter = Components.classes["@mozilla.org/intl/converter-output-stream;1"].createInstance(Components.interfaces.nsIConverterOutputStream);
converter.close(); // this closes foStream converter.init(foStream, "UTF-8", 0, 0);
}, converter.close(); // this closes foStream
getLine : function(path) { },
// open an input stream from file /*
@description gets an entire script into an array, seperated by lines
var file = Components.classes["@mozilla.org/file/local;1"] @return array of lines
.createInstance(Components.interfaces.nsILocalFile); @see <a href="https://developer.mozilla.org/en-US/docs/Code_snippets/File_I_O"> Mozilla Developer Network Example </a>
file.initWithPath(path); */
var istream = Components.classes["@mozilla.org/network/file-input-stream;1"] getScript: function (path) {
.createInstance(Components.interfaces.nsIFileInputStream); // open an input stream from file
istream.init(file, 0x01, 0444, 0); var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
istream.QueryInterface(Components.interfaces.nsILineInputStream); file.initWithPath(path);
var istream = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream);
// read lines into array istream.init(file, 0x01, 0444, 0);
var line = {}, lines = [], hasmore; istream.QueryInterface(Components.interfaces.nsILineInputStream);
do { // read lines into array
hasmore = istream.readLine(line); var line = {}, lines = [],
lines.push(line.value); hasmore;
} while (hasmore); do {
hasmore = istream.readLine(line);
istream.close(); lines.push(line.value);
} while (hasmore);
// do something with read data istream.close();
return lines; return lines;
} }
} }