Fix mangled output from Zotero.Utilities.getAsyncInputStream()
Proper fix (as opposed to 5236d01791
) for
https://forums.zotero.org/discussion/64022/5-0-beta-generate-report-is-often-garbled
This commit is contained in:
parent
10111dbd98
commit
b073c3e680
|
@ -658,16 +658,18 @@ Zotero.Utilities.Internal = {
|
||||||
var g = gen.next ? gen : gen();
|
var g = gen.next ? gen : gen();
|
||||||
var seq = 0;
|
var seq = 0;
|
||||||
|
|
||||||
|
const PR_UINT32_MAX = Math.pow(2, 32) - 1;
|
||||||
var pipe = Cc["@mozilla.org/pipe;1"].createInstance(Ci.nsIPipe);
|
var pipe = Cc["@mozilla.org/pipe;1"].createInstance(Ci.nsIPipe);
|
||||||
pipe.init(true, true, 0, 0, null);
|
pipe.init(true, true, 0, PR_UINT32_MAX, null);
|
||||||
|
|
||||||
var os = Components.classes["@mozilla.org/intl/converter-output-stream;1"]
|
var os = Components.classes["@mozilla.org/intl/converter-output-stream;1"]
|
||||||
.createInstance(Components.interfaces.nsIConverterOutputStream);
|
.createInstance(Components.interfaces.nsIConverterOutputStream);
|
||||||
os.init(pipe.outputStream, 'utf-8', 0, 0x0000);
|
os.init(pipe.outputStream, 'utf-8', 0, 0x0000);
|
||||||
|
|
||||||
|
|
||||||
pipe.outputStream.asyncWait({
|
pipe.outputStream.asyncWait({
|
||||||
onOutputStreamReady: function (aos) {
|
onOutputStreamReady: function (aos) {
|
||||||
Zotero.debug("Output stream is ready");
|
//Zotero.debug("Output stream is ready");
|
||||||
|
|
||||||
let currentSeq = seq++;
|
let currentSeq = seq++;
|
||||||
|
|
||||||
|
@ -710,6 +712,12 @@ Zotero.Utilities.Internal = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
Zotero.debug("Closing input stream");
|
||||||
|
aos.close();
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof data != 'string') {
|
if (typeof data != 'string') {
|
||||||
throw new Error("Yielded value is not a string or promise in " + funcName
|
throw new Error("Yielded value is not a string or promise in " + funcName
|
||||||
+ " ('" + data + "')");
|
+ " ('" + data + "')");
|
||||||
|
@ -733,14 +741,6 @@ Zotero.Utilities.Internal = {
|
||||||
Zotero.debug("Writing " + data.length + " characters");
|
Zotero.debug("Writing " + data.length + " characters");
|
||||||
os.writeString(data);
|
os.writeString(data);
|
||||||
|
|
||||||
if (error) {
|
|
||||||
Zotero.debug("Closing input stream");
|
|
||||||
aos.close();
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
|
|
||||||
Zotero.debug("Waiting to write more");
|
|
||||||
|
|
||||||
// Wait until stream is ready for more
|
// Wait until stream is ready for more
|
||||||
aos.asyncWait(this, 0, 0, null);
|
aos.asyncWait(this, 0, 0, null);
|
||||||
}, this)
|
}, this)
|
||||||
|
|
|
@ -444,26 +444,12 @@ function ZoteroProtocolHandler() {
|
||||||
|
|
||||||
default:
|
default:
|
||||||
this.contentType = 'text/html';
|
this.contentType = 'text/html';
|
||||||
|
return Zotero.Utilities.Internal.getAsyncInputStream(
|
||||||
// DEBUG: Results in mangled reports
|
|
||||||
//
|
|
||||||
// https://forums.zotero.org/discussion/64022/5-0-beta-generate-report-is-often-garbled
|
|
||||||
/*return Zotero.Utilities.Internal.getAsyncInputStream(
|
|
||||||
Zotero.Report.HTML.listGenerator(items, combineChildItems),
|
|
||||||
function () {
|
|
||||||
return '<span style="color: red; font-weight: bold">Error generating report</span>';
|
|
||||||
}
|
|
||||||
);*/
|
|
||||||
|
|
||||||
Components.utils.import("resource://gre/modules/NetUtil.jsm");
|
|
||||||
var is = Zotero.Utilities.Internal.getAsyncInputStream(
|
|
||||||
Zotero.Report.HTML.listGenerator(items, combineChildItems),
|
Zotero.Report.HTML.listGenerator(items, combineChildItems),
|
||||||
function () {
|
function () {
|
||||||
return '<span style="color: red; font-weight: bold">Error generating report</span>';
|
return '<span style="color: red; font-weight: bold">Error generating report</span>';
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
var str = NetUtil.readInputStreamToString(is, is.available(), { charset: "UTF-8" });
|
|
||||||
return Zotero.Promise.resolve(str);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user