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
2 changed files with 11 additions and 25 deletions
|
@ -658,16 +658,18 @@ Zotero.Utilities.Internal = {
|
|||
var g = gen.next ? gen : gen();
|
||||
var seq = 0;
|
||||
|
||||
const PR_UINT32_MAX = Math.pow(2, 32) - 1;
|
||||
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"]
|
||||
.createInstance(Components.interfaces.nsIConverterOutputStream);
|
||||
os.init(pipe.outputStream, 'utf-8', 0, 0x0000);
|
||||
|
||||
|
||||
pipe.outputStream.asyncWait({
|
||||
onOutputStreamReady: function (aos) {
|
||||
Zotero.debug("Output stream is ready");
|
||||
//Zotero.debug("Output stream is ready");
|
||||
|
||||
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') {
|
||||
throw new Error("Yielded value is not a string or promise in " + funcName
|
||||
+ " ('" + data + "')");
|
||||
|
@ -733,14 +741,6 @@ Zotero.Utilities.Internal = {
|
|||
Zotero.debug("Writing " + data.length + " characters");
|
||||
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
|
||||
aos.asyncWait(this, 0, 0, null);
|
||||
}, this)
|
||||
|
|
|
@ -444,26 +444,12 @@ function ZoteroProtocolHandler() {
|
|||
|
||||
default:
|
||||
this.contentType = 'text/html';
|
||||
|
||||
// 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(
|
||||
return Zotero.Utilities.Internal.getAsyncInputStream(
|
||||
Zotero.Report.HTML.listGenerator(items, combineChildItems),
|
||||
function () {
|
||||
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…
Add table
Reference in a new issue