Update fireio.js

Updated IO to allow the reading of source file for playback
This commit is contained in:
David Westgate 2013-04-28 13:53:56 -03:00
parent edb54b86e1
commit 1b5d18921c

View File

@ -1,59 +1,98 @@
var io = { var io = {
openPath : function(){ openPath : function() {
alert("test2");
const nsIFilePicker = Components.interfaces.nsIFilePicker;
var fp = Components.classes["@mozilla.org/filepicker;1"] const
.createInstance(nsIFilePicker); nsIFilePicker = Components.interfaces.nsIFilePicker;
fp.init(window, "Dialog Title", nsIFilePicker.modeOpen);
fp.appendFilters(nsIFilePicker.filterAll | nsIFilePicker.filterText);
var rv = fp.show(); var fp = Components.classes["@mozilla.org/filepicker;1"]
if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) { .createInstance(nsIFilePicker);
var file = fp.file; fp.init(window, "Dialog Title", nsIFilePicker.modeOpen);
// 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...
appendPath: function (path, contents) }
{ return path;
alert("appended File"); },
var file1 = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); appendPath : function(path, contents) {
file1.initWithPath(path); alert("appended File");
//alert("append file nullcheck: "+file1.toString()); var file1 = Components.classes["@mozilla.org/file/local;1"]
var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutputStream); .createInstance(Components.interfaces.nsILocalFile);
// use 0x02 | 0x10 to open file for appending. file1.initWithPath(path);
foStream.init(file1, 0x02 | 0x10, 438, 0); // alert("append file nullcheck: "+file1.toString());
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.nsIConverterOutputStream); .createInstance(Components.interfaces.nsIFileOutputStream);
converter.init(foStream, "UTF-8", 0, 0); // use 0x02 | 0x10 to open file for appending.
converter.writeString(contents); foStream.init(file1, 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);
converter.writeString(contents);
converter.close();
},
newPath : function(path) {
newPath: function() { const
const nsIFilePicker = Components.interfaces.nsIFilePicker; nsIFilePicker = Components.interfaces.nsIFilePicker;
var fp = Components.classes["@mozilla.org/filepicker;1"] var fp = Components.classes["@mozilla.org/filepicker;1"]
.createInstance(nsIFilePicker); .createInstance(nsIFilePicker);
fp.init(window, "Dialog Title", nsIFilePicker.modeSave); fp.init(window, "Dialog Title", nsIFilePicker.modeSave);
fp.appendFilters(nsIFilePicker.filterAll | nsIFilePicker.filterText); fp.appendFilters(nsIFilePicker.filterAll | nsIFilePicker.filterText);
var rv = fp.show(); var rv = fp.show();
if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) { if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) {
var file = fp.file; var file = fp.file;
// Get the path as string. Note that you usually won't // Get the path as string. Note that you usually won't
// need to work with the string paths. // need to work with the string paths.
var path = fp.file.path; var path = fp.file.path;
// work with returned nsILocalFile... // work with returned nsILocalFile...
} }
return path; return path;
}, },
createFile : function(path) {
alert("created File");
var file1 = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
file1.initWithPath(path);
var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
.createInstance(Components.interfaces.nsIFileOutputStream);
// use 0x02 | 0x10 to open file for appending.
foStream.init(file1, 0x02 | 0x08 | 0x20, 438, 0);
var converter = Components.classes["@mozilla.org/intl/converter-output-stream;1"]
.createInstance(Components.interfaces.nsIConverterOutputStream);
converter.init(foStream, "UTF-8", 0, 0);
converter.close(); // this closes foStream
},
getLine : function(path) {
// open an input stream from file
var file = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
file.initWithPath(path);
var istream = Components.classes["@mozilla.org/network/file-input-stream;1"]
.createInstance(Components.interfaces.nsIFileInputStream);
istream.init(file, 0x01, 0444, 0);
istream.QueryInterface(Components.interfaces.nsILineInputStream);
// read lines into array
var line = {}, lines = [], hasmore;
do {
hasmore = istream.readLine(line);
lines.push(line.value);
} while (hasmore);
istream.close();
// do something with read data
return lines;
}
} }