-
Couldn't load subscription status.
- Fork 253
Open
Description
I was using epub package just to see how it works. I read an epub book with
EpubBook epubBook = await EpubReader.readBook(bytes);
then i saved it without any changes then I read it again
var written = EpubWriter.writeBook(epubBook); var newBook = await EpubReader.readBook(written);
I got "EPUB parsing error: root file not found in archive." exception.
I investigated for a while and I found:
- My epub book contains content.opf in the root of epubArchive, not in OEBPS/content.opf
- while writing my epub book, _EpubWriter.container_file constant contains OEBPS/content.opf
- As a result, adding the container file META-INF/container.xml, the OEBPS/content.opf reference was set while content.opf was on the root.
- Subseguent searches throw an exception when I re-read saved epub book.
I think the following quick patch of EpubWriter can help and, perhaps, it's possible to apply an even better one.
static Archive _createArchive(EpubBook book) {
var arch = Archive();
final StringBuffer buffer = StringBuffer('<?xml version="1.0"?><container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container"><rootfiles><rootfile full-path=')
..write('"')
..write(book.Schema.ContentDirectoryPath)
..write(book.Schema.ContentDirectoryPath.isEmpty ? 'content.opf' : '/content.opf' )
..write('"')
..write(' media-type="application/oebps-package+xml"/></rootfiles></container>');
final String _container_file = buffer.toString();
// Add simple metadata
arch.addFile(ArchiveFile.noCompress(
"metadata", 20, convert.utf8.encode("application/epub+zip")));
// Add Container file
arch.addFile(ArchiveFile("META-INF/container.xml", _container_file.length,
convert.utf8.encode(_container_file)));
...
Lamda303
Metadata
Metadata
Assignees
Labels
No labels