From 6da252fc036890d7848f12ea2ac58f39a15bfed6 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 22 Jul 2008 05:38:05 +0000 Subject: [PATCH] Save Unicode files with Zotero.File.putContents() --- chrome/content/zotero/xpcom/file.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/chrome/content/zotero/xpcom/file.js b/chrome/content/zotero/xpcom/file.js index 668368b51..1750801c4 100644 --- a/chrome/content/zotero/xpcom/file.js +++ b/chrome/content/zotero/xpcom/file.js @@ -134,18 +134,22 @@ Zotero.File = new function(){ /* * Write string to a file, overwriting existing file if necessary - * - * Note: Can only handle ASCII text! */ function putContents(file, str) { if (file.exists()) { file.remove(null); } - var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"] - .createInstance(Components.interfaces.nsIFileOutputStream); - foStream.init(file, 0x02 | 0x08 | 0x20, 0664, 0); // write, create, truncate - foStream.write(str, str.length); - foStream.close(); + var fos = Components.classes["@mozilla.org/network/file-output-stream;1"]. + createInstance(Components.interfaces.nsIFileOutputStream); + fos.init(file, 0x02 | 0x08 | 0x20, 0664, 0); // write, create, truncate + + var os = Components.classes["@mozilla.org/intl/converter-output-stream;1"] + .createInstance(Components.interfaces.nsIConverterOutputStream); + os.init(fos, "UTF-8", 4096, "?".charCodeAt(0)); + os.writeString(str); + os.close(); + + fos.close(); }