openBook static method

Future<EpubBookRef> openBook(
  1. FutureOr<List<int>> bytes

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.


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)
  bookRef.Author = bookRef.AuthorList!.join(', ');
  bookRef.Content = ContentReader.parseContentMap(bookRef);
  return bookRef;