From 55d27273fb9b80ca17d663a025cbbf152ed54926 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sun, 31 May 2015 23:01:34 -0400 Subject: [PATCH] TextEncoder is no longer required for OS.File.writeAtomic() --- chrome/content/zotero/xpcom/file.js | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/chrome/content/zotero/xpcom/file.js b/chrome/content/zotero/xpcom/file.js index fdf8157cd..dcd7e24c9 100644 --- a/chrome/content/zotero/xpcom/file.js +++ b/chrome/content/zotero/xpcom/file.js @@ -340,29 +340,20 @@ Zotero.File = new function(){ path = path.path; } - if (typeof data == 'string' && (!charset || charset.toLowerCase() == 'utf-8')) { - let encoder = new TextEncoder(); - let array = encoder.encode(data); + if (typeof data == 'string') { return Zotero.Promise.resolve(OS.File.writeAtomic( path, - array, + data, { tmpPath: OS.Path.join( Zotero.getTempDirectory().path, OS.Path.basename(path) + ".tmp" - ) + ), + encoding: charset ? charset.toLowerCase() : 'utf-8' } )); } - // Convert text data to stream - if(!(data instanceof Components.interfaces.nsIInputStream)) { - var converter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"]. - createInstance(Components.interfaces.nsIScriptableUnicodeConverter); - converter.charset = charset ? Zotero.CharacterSets.getName(charset) : "UTF-8"; - data = converter.convertToInputStream(data); - } - var deferred = Zotero.Promise.defer(); var os = FileUtils.openSafeFileOutputStream(new FileUtils.File(path)); NetUtil.asyncCopy(data, os, function(inputStream, status) {