/// <summary> /// Opens the book asynchronously without reading its content. Holds the handle to the EPUB file. /// </summary> /// <param name="stream">stream from the EPUB file</param> /// <returns></returns> public static async Task <EpubBookRef> OpenBookAsync(Stream stream) { ZipArchive epubArchive = new ZipArchive(stream); EpubBookRef bookRef = new EpubBookRef(epubArchive); bookRef.Schema = await SchemaReader.ReadSchemaAsync(epubArchive).ConfigureAwait(false); bookRef.Title = bookRef.Schema.Package.Metadata.Titles.FirstOrDefault() ?? String.Empty; bookRef.AuthorList = bookRef.Schema.Package.Metadata.Creators.Select(creator => creator.Creator).ToList(); bookRef.Author = String.Join(", ", bookRef.AuthorList); bookRef.Content = await Task.Run(() => ContentReader.ParseContentMap(bookRef)).ConfigureAwait(false); return(bookRef); }
/// <summary> /// Opens the book asynchronously without reading its content. Holds the handle to the EPUB file. /// </summary> /// <param name="filePath">path to the EPUB file</param> /// <returns></returns> public static async Task <EpubBookRef> OpenBookAsync(string filePath) { if (!File.Exists(filePath)) { throw new FileNotFoundException("Specified epub file not found.", filePath); } ZipArchive epubArchive = ZipFile.OpenRead(filePath); EpubBookRef bookRef = new EpubBookRef(epubArchive); bookRef.FilePath = filePath; bookRef.Schema = await SchemaReader.ReadSchemaAsync(epubArchive).ConfigureAwait(false); bookRef.Title = bookRef.Schema.Package.Metadata.Titles.FirstOrDefault() ?? String.Empty; bookRef.AuthorList = bookRef.Schema.Package.Metadata.Creators.Select(creator => creator.Creator).ToList(); bookRef.Author = String.Join(", ", bookRef.AuthorList); bookRef.Content = await Task.Run(() => ContentReader.ParseContentMap(bookRef)).ConfigureAwait(false); return(bookRef); }
/// <summary> /// Opens the book asynchronously and reads all of its content into the memory. Does not hold the handle to the EPUB file. /// </summary> /// <param name="stream">stream from the EPUB file</param> /// <returns></returns> public static async Task <EpubBook> ReadBookAsync(Stream stream) { EpubBook result = new EpubBook(); using (EpubBookRef epubBookRef = await OpenBookAsync(stream).ConfigureAwait(false)) { result.Schema = epubBookRef.Schema; result.Title = epubBookRef.Title; result.AuthorList = epubBookRef.AuthorList; result.Author = epubBookRef.Author; result.Content = await ReadContent(epubBookRef.Content).ConfigureAwait(false); result.CoverImage = await epubBookRef.ReadCoverAsync().ConfigureAwait(false); List <EpubChapterRef> chapterRefs = await epubBookRef.GetChaptersAsync().ConfigureAwait(false); result.Chapters = await ReadChapters(chapterRefs).ConfigureAwait(false); } return(result); }
public EpubByteContentFileRef(EpubBookRef epubBookRef) : base(epubBookRef) { }
public EpubTextContentFileRef(EpubBookRef epubBookRef) : base(epubBookRef) { }
public EpubContentFileRef(EpubBookRef epubBookRef) { this.epubBookRef = epubBookRef; }