The jQuery.twFile plugin does not save the file in UTF-8 format Firefiox 11.0

206 views
Skip to first unread message

Michal

unread,
Apr 4, 2012, 7:22:18 AM4/4/12
to TiddlyWikiDev
The jQuery.twFile plugin does not save the file in UTF-8 format
Firefiox 11.0
checked with german chars ßüöä

After adding a converter as described in Writing a File section on
https://developer.mozilla.org/en/Code_snippets/File_I%2F%2FO

it works :)

maybe it would be good idea to add this code to twFile plugin ?

The modified function for drivers.mozilla

saveFile: function(filePath,content) {
// Returns null if it can't do it, false if there's an error, true
if it saved OK
if(window.Components) {
try {

netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var file = Components.classes["@mozilla.org/file/local;
1"].createInstance(Components.interfaces.nsILocalFile);
file.initWithPath(filePath);
if(!file.exists())
file.create(0,0664);
var out = Components.classes["@mozilla.org/network/file-output-
stream;1"].createInstance(Components.interfaces.nsIFileOutputStream);
out.init(file,0x20|0x02,00004,null);

var converter = Components.classes["@mozilla.org/intl/converter-
output-stream;1"].

createInstance(Components.interfaces.nsIConverterOutputStream);
converter.init(out, "UTF-8", 0, 0);
converter.writeString(content);
converter.close(); // this closes foStream

return true;
} catch(ex) {
alert("Exception while attempting to save\n\n" + ex);
return false;
}
}
return null;
}
Reply all
Reply to author
Forward
0 new messages