diff --git a/chrome/content/zotero/xpcom/utilities_internal.js b/chrome/content/zotero/xpcom/utilities_internal.js
index e629db44d..d5935527e 100644
--- a/chrome/content/zotero/xpcom/utilities_internal.js
+++ b/chrome/content/zotero/xpcom/utilities_internal.js
@@ -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)
diff --git a/components/zotero-protocol-handler.js b/components/zotero-protocol-handler.js
index c82fade40..372e470e1 100644
--- a/components/zotero-protocol-handler.js
+++ b/components/zotero-protocol-handler.js
@@ -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 'Error generating report';
- }
- );*/
-
- 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 'Error generating report';
}
);
- var str = NetUtil.readInputStreamToString(is, is.available(), { charset: "UTF-8" });
- return Zotero.Promise.resolve(str);
}
});
}