/// <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 (UrlUtils.FileIsUrl(filePath)) { var localFilePath = await UrlUtils.UrlToFile(filePath); if (string.IsNullOrEmpty(localFilePath)) { throw new FileNotFoundException("Specified remote ePub file could not be downloaded to local filesystem.", filePath); } filePath = localFilePath; } if (!File.Exists(filePath)) { throw new FileNotFoundException("Specified local 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="filePath">path to the EPUB file</param> /// <returns></returns> public static async Task <EpubBook> ReadBookAsync(string filePath) { EpubBook result = new EpubBook(); using (EpubBookRef epubBookRef = await OpenBookAsync(filePath).ConfigureAwait(false)) { result.FilePath = epubBookRef.FilePath; 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 EpubContentFileRef(EpubBookRef epubBookRef) { this.epubBookRef = epubBookRef; }
public EpubByteContentFileRef(EpubBookRef epubBookRef) : base(epubBookRef) { }
public EpubTextContentFileRef(EpubBookRef epubBookRef) : base(epubBookRef) { }