TextEncoder is no longer required for OS.File.writeAtomic()
This commit is contained in:
parent
4fd65fec4c
commit
55d27273fb
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user