From ff5007fdeabc58d8948525f8e9b48425ae75ed68 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 3 Sep 2014 19:39:32 -0400 Subject: [PATCH] Fix error fetching empty file via File.getContentsAsync() --- chrome/content/zotero/xpcom/file.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/chrome/content/zotero/xpcom/file.js b/chrome/content/zotero/xpcom/file.js index 6da8901a66..3605d715fb 100644 --- a/chrome/content/zotero/xpcom/file.js +++ b/chrome/content/zotero/xpcom/file.js @@ -212,10 +212,20 @@ Zotero.File = new function(){ } try { + var bytesToFetch = inputStream.available(); + if (maxLength && maxLength < bytesToFetch) { + bytesToFetch = maxLength; + } + + if (bytesToFetch == 0) { + deferred.resolve(""); + return; + } + deferred.resolve( NetUtil.readInputStreamToString( inputStream, - Math.min(maxLength, inputStream.available()), + bytesToFetch, options ) );