I have a Firefox
addon which is able to save a piece of text to a file on the user's hard-disk.
I've been doing some research on porting this part of functionality over to Google Chrome
but looks like there is a lot of challenges, examples:
How can a Chrome extension save many files to a user-specified directory?
Is there a standardized way of achieving this functionality?
I am amazed at how difficult it is to implement something so trivial.
The suggested answer above is to basically implement an extension and packaged app, but this is not an option for me as it will be available to user on internet.
And having to install 2 separate entities seem arkward.
Sample of my Firefox
addon code which saves text to a file in a directory of my choice.
I'm looking for the same kind of functionality except in Google Chrome
..
var ostream;
var file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
file.initWithPath('/home/rob/Desktop/');
file.append('Test.txt');
try{
if (file.exists() === false) {file.create(Ci.nsIFile.NORMAL_FILE_TYPE, 420);}
ostream = FileUtils.openFileOutputStream(file, FileUtils.MODE_WRONLY | FileUtils.MODE_APPEND);
var converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Ci.nsIScriptableUnicodeConverter);
converter.charset = "UTF-8";
var istream = converter.convertToInputStream('This is my string of text');
// The last argument (the callback) is optional.
NetUtil.asyncCopy(istream, ostream, function(status) {
if (!components.isSuccessCode(status)) {
alert('error');
}else{
alert('success');
}
});
} catch (e) {
return false;
}