I am using this function to write text to a file via iMacros addon in FireFox.
//This function writes string into a file
function WriteFile(path,string)
{
//import FileUtils.jsm
Components.utils.import("resource://gre/modules/FileUtils.jsm");
//declare file
var file = new FileUtils.File(path);
//declare file path
file.initWithPath(path);
//if it exists move on if not create it
if (!file.exists())
{
file.create(file.NORMAL_FILE_TYPE, 0666);
}
var charset = 'EUC-JP';
var fileStream = Components.classes['@mozilla.org/network/file-output-stream;1']
.createInstance(Components.interfaces.nsIFileOutputStream);
fileStream.init(file, 18, 0x200, false);
var converterStream = Components
.classes['@mozilla.org/intl/converter-output-stream;1']
.createInstance(Components.interfaces.nsIConverterOutputStream);
converterStream.init(fileStream, charset, string.length,
Components.interfaces.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER);
//write file to location
converterStream.writeString("\r\n"+string);
converterStream.close();
fileStream.close();
}
But as for yesterday I started getting this message, regardless of which browser I tried and on different PC.
[Exception... "Component returned failure code: 0x80460003 (NS_ERROR_LOSS_OF_SIGNIFICANT_DATA) [nsIConverterOutputStream.writeString]" nsresult: "0x80460003 (NS_ERROR_LOSS_OF_SIGNIFICANT_DATA)" location: "JS frame :: chrome://imacros/content/iMacros.js :: WriteFile :: line 329" data: no] (Error code: 991)
So I checked on mozilla developers what does this error mean and found this.
NS_ERROR_LOSS_OF_SIGNIFICANT_DATA (0x80460003)
NS_ERROR_ILLEGAL_DURING_SHUTDOWN (0x8046001E)
Many operations cannot be performed once the application is being shutdown. This error will occur in this situation.
But I can't figure out what is the error here since I didn't change the function code in any way. Can someone interpret this error ?
I replaced this
with this
and it solved my problems.