openBook static method
Loads basics metadata.
Opens the book asynchronously without reading its main content. Holds the handle to the EPUB file.
Argument bytes
should be the bytes of
the epub file you have loaded with something like the dart:io
package's
readAsBytes()
.
This is a fast and convenient way to get the most important information
about the book, notably the Title
, Author
and AuthorList
.
Additional information is loaded in the Schema
property such as the
Epub version, Publishers, Languages and more.
Implementation
static Future<EpubBookRef> openBook(FutureOr<List<int>> bytes) async {
List<int> loadedBytes;
if (bytes is Future) {
loadedBytes = await bytes;
} else {
loadedBytes = bytes;
}
var epubArchive = ZipDecoder().decodeBytes(loadedBytes);
var bookRef = EpubBookRef(epubArchive);
bookRef.Schema = await SchemaReader.readSchema(epubArchive);
bookRef.Title = bookRef.Schema!.Package!.Metadata!.Titles!
.firstWhere((String name) => true, orElse: () => '');
bookRef.AuthorList = bookRef.Schema!.Package!.Metadata!.Creators!
.map((EpubMetadataCreator creator) => creator.Creator)
.toList();
bookRef.Author = bookRef.AuthorList!.join(', ');
bookRef.Content = ContentReader.parseContentMap(bookRef);
return bookRef;
}