Пример #1
0
        /// <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);
        }
Пример #2
0
        /// <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);
        }
Пример #3
0
        /// <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);
        }
Пример #4
0
 public EpubByteContentFileRef(EpubBookRef epubBookRef)
     : base(epubBookRef)
 {
 }
Пример #5
0
 public EpubTextContentFileRef(EpubBookRef epubBookRef)
     : base(epubBookRef)
 {
 }
Пример #6
0
 public EpubContentFileRef(EpubBookRef epubBookRef)
 {
     this.epubBookRef = epubBookRef;
 }