Open AndreevskiAleksandar opened 5 years ago
Hopefully it's helpful to you
import { Book } from 'epubjs'
const blob: Blob = ... // Blob from HTTP request or file uploading
const buf = await blob.arrayBuffer()
const book = new Book(buf as any, { openAs: 'binary' })
The line buf as any
is because of the incorrect type definition in epubjs
, however, it's ok to use.
Hello, I am trying to download epubs from a server and then open them with the epub.js library. I dont supply the url directly to the ePub library like in the examples (
ePub('url')
), since the books can get up to 100mb, so I cache them, and then try to open them with epub.js. The problem is when I try to supply the binary file or as a blob right after downloading it with XHR, the library does not throw any kind of error, but also does not show anything. It works fine when I supply the url directly and the epub.js loads the file itself.The code that I try to execute is the following.
` var oReq = new XMLHttpRequest();
`
Also after some tinkering with the code and debugging the epub.js library, I found the problematic code. In the
openEpub
function there is this codeI added a catch at the end to log an error
.catch(err => console.error(err));
and I got this error that points to the jszip library.epub.js:11669 Error: End of data reached (data length = 447427, asked index = 508794). Corrupted zip ?
The file is not corrupted, its length is 447427 bytes. I dont know why the decompression tries to find index that is 6000 bytes away...
On another book the error is
Corrupted zip: missing 860709509 bytes
. Again the size is around 300000 bytes.The books I am using are: https://www.gutenberg.org/ebooks/1661 and the second one is Moby Dick from the example http://s3.amazonaws.com/moby-dick/moby-dick.epub