diff --git a/chrome/content/zotero/xpcom/file.js b/chrome/content/zotero/xpcom/file.js index dcd7e24c9..5f61efdbd 100644 --- a/chrome/content/zotero/xpcom/file.js +++ b/chrome/content/zotero/xpcom/file.js @@ -221,7 +221,17 @@ Zotero.File = new function(){ } try { - var bytesToFetch = inputStream.available(); + try { + var bytesToFetch = inputStream.available(); + } + catch (e) { + // The stream is closed automatically when end-of-file is reached, + // so this throws for empty files + if (e.name == "NS_BASE_STREAM_CLOSED") { + deferred.resolve(""); + } + } + if (maxLength && maxLength < bytesToFetch) { bytesToFetch = maxLength; } diff --git a/test/tests/data/empty b/test/tests/data/empty new file mode 100644 index 000000000..e69de29bb diff --git a/test/tests/fileTest.js b/test/tests/fileTest.js index babf4509f..f30f869b1 100644 --- a/test/tests/fileTest.js +++ b/test/tests/fileTest.js @@ -1,4 +1,11 @@ describe("Zotero.File", function () { + describe("#getContentsAsync()", function () { + it("should handle an empty file", function* () { + var path = OS.Path.join(getTestDataDirectory().path, "empty"); + assert.equal((yield Zotero.File.getContentsAsync(path)), ""); + }) + }) + describe("#copyDirectory()", function () { it("should copy all files within a directory", function* () { var tmpDir = Zotero.getTempDirectory().path; diff --git a/test/tests/translateTest.js b/test/tests/translateTest.js index 081bf7fe0..0a5e7985a 100644 --- a/test/tests/translateTest.js +++ b/test/tests/translateTest.js @@ -378,11 +378,6 @@ describe("Zotero.Translate.ItemGetter", function() { } })); - // TEMP - describe("failure debugging", function () { - before(() => Zotero.Debug.init(true)) - after(() => Zotero.Debug.init()) - it('should return stored/linked file and URI attachments in expected format', Zotero.Promise.coroutine(function* () { this.timeout(60000); let file = getTestDataDirectory(); @@ -591,7 +586,5 @@ describe("Zotero.Translate.ItemGetter", function() { } } })); - - }) }); }); \ No newline at end of file