From 2732e172cd0b41bbb24053131e4a19e4bcd67f9c Mon Sep 17 00:00:00 2001 From: Christiaan Baartse Date: Thu, 21 May 2020 06:25:30 +0200 Subject: [PATCH] Fix opening an ArrayBuffer without options Opening an archived Epub in an ArrayBuffer without passing in options will never resolve its `book.opened` Promise. --- src/book.js | 3 ++- test/book.js | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/book.js b/src/book.js index bb0de20..0fcc30b 100644 --- a/src/book.js +++ b/src/book.js @@ -52,7 +52,8 @@ class Book { // Allow passing just options to the Book if (typeof(options) === "undefined" && typeof(url) !== "string" && - url instanceof Blob === false) { + url instanceof Blob === false && + url instanceof ArrayBuffer === false) { options = url; url = undefined; } diff --git a/test/book.js b/test/book.js index fa5a524..a6c8539 100644 --- a/test/book.js +++ b/test/book.js @@ -29,4 +29,25 @@ describe('Book', function() { assert( /^blob:http:\/\/localhost:9876\/[^\/]+$/.test(coverUrl), "cover url is available and a blob: url" ); }); }); + + describe('Archived epub in array buffer without options', function() { + let book; + + before(async function() { + const response = await fetch("/fixtures/alice.epub"); + const buffer = await response.arrayBuffer() + book = new Book(buffer) + }) + + it('should open a archived epub', async function() { + await book.opened + assert.equal(book.isOpen, true, "book is opened"); + assert(book.archive, "book is unarchived"); + }); + + it('should have a blob coverUrl', async function() { + let coverUrl = await book.coverUrl() + assert( /^blob:http:\/\/localhost:9876\/[^\/]+$/.test(coverUrl), "cover url is available and a blob: url" ); + }); + }); });