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;
|
path = path.path;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof data == 'string' && (!charset || charset.toLowerCase() == 'utf-8')) {
|
if (typeof data == 'string') {
|
||||||
let encoder = new TextEncoder();
|
|
||||||
let array = encoder.encode(data);
|
|
||||||
return Zotero.Promise.resolve(OS.File.writeAtomic(
|
return Zotero.Promise.resolve(OS.File.writeAtomic(
|
||||||
path,
|
path,
|
||||||
array,
|
data,
|
||||||
{
|
{
|
||||||
tmpPath: OS.Path.join(
|
tmpPath: OS.Path.join(
|
||||||
Zotero.getTempDirectory().path,
|
Zotero.getTempDirectory().path,
|
||||||
OS.Path.basename(path) + ".tmp"
|
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 deferred = Zotero.Promise.defer();
|
||||||
var os = FileUtils.openSafeFileOutputStream(new FileUtils.File(path));
|
var os = FileUtils.openSafeFileOutputStream(new FileUtils.File(path));
|
||||||
NetUtil.asyncCopy(data, os, function(inputStream, status) {
|
NetUtil.asyncCopy(data, os, function(inputStream, status) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user