Fix NS_BASE_STREAM_CLOSED error, for real
The input stream produced by asyncFetch is closed automatically at EOL, so the available() call throws this for an empty file.
This commit is contained in:
parent
ee777c5be6
commit
77f12527aa
|
@ -221,7 +221,17 @@ Zotero.File = new function(){
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
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) {
|
if (maxLength && maxLength < bytesToFetch) {
|
||||||
bytesToFetch = maxLength;
|
bytesToFetch = maxLength;
|
||||||
}
|
}
|
||||||
|
|
0
test/tests/data/empty
Normal file
0
test/tests/data/empty
Normal file
|
@ -1,4 +1,11 @@
|
||||||
describe("Zotero.File", function () {
|
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 () {
|
describe("#copyDirectory()", function () {
|
||||||
it("should copy all files within a directory", function* () {
|
it("should copy all files within a directory", function* () {
|
||||||
var tmpDir = Zotero.getTempDirectory().path;
|
var tmpDir = Zotero.getTempDirectory().path;
|
||||||
|
|
|
@ -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* () {
|
it('should return stored/linked file and URI attachments in expected format', Zotero.Promise.coroutine(function* () {
|
||||||
this.timeout(60000);
|
this.timeout(60000);
|
||||||
let file = getTestDataDirectory();
|
let file = getTestDataDirectory();
|
||||||
|
@ -591,7 +586,5 @@ describe("Zotero.Translate.ItemGetter", function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
});
|
});
|
Loading…
Reference in New Issue
Block a user