using System.IO; using System.Threading.Tasks; using VersOne.Epub.Environment; using VersOne.Epub.Environment.Implementation; using VersOne.Epub.Internal; using VersOne.Epub.Options; namespace VersOne.Epub { /// /// The main entry point of the EpubReader library. The methods in this class let the consumer to open/read EPUB books from a file or a . /// public static class EpubReader { private static readonly IEnvironmentDependencies environmentDependencies; static EpubReader() { environmentDependencies = new EnvironmentDependencies(); } /// /// Opens the book synchronously without reading its content. The object returned by this method holds a handle to the EPUB file. /// /// Path to the EPUB file. /// /// A preset to configure the behavior of the EPUB reader. /// Default value is EpubReaderOptionsPreset.RELAXED. /// /// EPUB book reference. This object holds a handle to the EPUB file. public static EpubBookRef OpenBook(string filePath, EpubReaderOptionsPreset epubReaderOptionsPreset = EpubReaderOptionsPreset.RELAXED) { BookRefReader bookRefReader = new(environmentDependencies, new EpubReaderOptions(epubReaderOptionsPreset)); return bookRefReader.OpenBook(filePath); } /// /// Opens the book synchronously without reading its content. The object returned by this method holds a handle to the EPUB file. /// /// Path to the EPUB file. /// Various options to configure the behavior of the EPUB reader. /// EPUB book reference. This object holds a handle to the EPUB file. public static EpubBookRef OpenBook(string filePath, EpubReaderOptions? epubReaderOptions) { BookRefReader bookRefReader = new(environmentDependencies, epubReaderOptions); return bookRefReader.OpenBook(filePath); } /// /// Opens the book synchronously without reading its content. The object returned by this method holds a handle to the EPUB file. /// /// Seekable stream containing the EPUB file. /// /// A preset to configure the behavior of the EPUB reader. /// Default value is EpubReaderOptionsPreset.RELAXED. /// /// EPUB book reference. This object holds a handle to the EPUB file. public static EpubBookRef OpenBook(Stream stream, EpubReaderOptionsPreset epubReaderOptionsPreset = EpubReaderOptionsPreset.RELAXED) { BookRefReader bookRefReader = new(environmentDependencies, new EpubReaderOptions(epubReaderOptionsPreset)); return bookRefReader.OpenBook(stream); } /// /// Opens the book synchronously without reading its content. The object returned by this method holds a handle to the EPUB file. /// /// Seekable stream containing the EPUB file. /// Various options to configure the behavior of the EPUB reader. /// EPUB book reference. This object holds a handle to the EPUB file. public static EpubBookRef OpenBook(Stream stream, EpubReaderOptions? epubReaderOptions) { BookRefReader bookRefReader = new(environmentDependencies, epubReaderOptions); return bookRefReader.OpenBook(stream); } /// /// Opens the book asynchronously without reading its content. The object returned by this method holds a handle to the EPUB file. /// /// Path to the EPUB file. /// /// A preset to configure the behavior of the EPUB reader. /// Default value is EpubReaderOptionsPreset.RELAXED. /// /// EPUB book reference. This object holds a handle to the EPUB file. public static Task OpenBookAsync(string filePath, EpubReaderOptionsPreset epubReaderOptionsPreset = EpubReaderOptionsPreset.RELAXED) { BookRefReader bookRefReader = new(environmentDependencies, new EpubReaderOptions(epubReaderOptionsPreset)); return bookRefReader.OpenBookAsync(filePath); } /// /// Opens the book asynchronously without reading its content. The object returned by this method holds a handle to the EPUB file. /// /// Path to the EPUB file. /// Various options to configure the behavior of the EPUB reader. /// EPUB book reference. This object holds a handle to the EPUB file. public static Task OpenBookAsync(string filePath, EpubReaderOptions? epubReaderOptions) { BookRefReader bookRefReader = new(environmentDependencies, epubReaderOptions); return bookRefReader.OpenBookAsync(filePath); } /// /// Opens the book asynchronously without reading its content. The object returned by this method holds a handle to the EPUB file. /// /// Seekable stream containing the EPUB file. /// /// A preset to configure the behavior of the EPUB reader. /// Default value is EpubReaderOptionsPreset.RELAXED. /// /// EPUB book reference. This object holds a handle to the EPUB file. public static Task OpenBookAsync(Stream stream, EpubReaderOptionsPreset epubReaderOptionsPreset = EpubReaderOptionsPreset.RELAXED) { BookRefReader bookRefReader = new(environmentDependencies, new EpubReaderOptions(epubReaderOptionsPreset)); return bookRefReader.OpenBookAsync(stream); } /// /// Opens the book asynchronously without reading its content. The object returned by this method holds a handle to the EPUB file. /// /// Seekable stream containing the EPUB file. /// Various options to configure the behavior of the EPUB reader. /// EPUB book reference. This object holds a handle to the EPUB file. public static Task OpenBookAsync(Stream stream, EpubReaderOptions? epubReaderOptions) { BookRefReader bookRefReader = new(environmentDependencies, epubReaderOptions); return bookRefReader.OpenBookAsync(stream); } /// /// Opens the book synchronously and reads all of its content into the memory. The object returned by this method does not retain a handle to the EPUB file. /// /// Path to the EPUB file. /// /// A preset to configure the behavior of the EPUB reader. /// Default value is EpubReaderOptionsPreset.RELAXED. /// /// EPUB book with all its content. This object does not retain a handle to the EPUB file. public static EpubBook ReadBook(string filePath, EpubReaderOptionsPreset epubReaderOptionsPreset = EpubReaderOptionsPreset.RELAXED) { BookReader bookReader = new(environmentDependencies, new EpubReaderOptions(epubReaderOptionsPreset)); return bookReader.ReadBook(filePath); } /// /// Opens the book synchronously and reads all of its content into the memory. The object returned by this method does not retain a handle to the EPUB file. /// /// Path to the EPUB file. /// Various options to configure the behavior of the EPUB reader. /// EPUB book with all its content. This object does not retain a handle to the EPUB file. public static EpubBook ReadBook(string filePath, EpubReaderOptions? epubReaderOptions) { BookReader bookReader = new(environmentDependencies, epubReaderOptions); return bookReader.ReadBook(filePath); } /// /// Opens the book synchronously and reads all of its content into the memory. The object returned by this method does not retain a handle to the EPUB file. /// /// Seekable stream containing the EPUB file. /// /// A preset to configure the behavior of the EPUB reader. /// Default value is EpubReaderOptionsPreset.RELAXED. /// /// EPUB book with all its content. This object does not retain a handle to the EPUB file. public static EpubBook ReadBook(Stream stream, EpubReaderOptionsPreset epubReaderOptionsPreset = EpubReaderOptionsPreset.RELAXED) { BookReader bookReader = new(environmentDependencies, new EpubReaderOptions(epubReaderOptionsPreset)); return bookReader.ReadBook(stream); } /// /// Opens the book synchronously and reads all of its content into the memory. The object returned by this method does not retain a handle to the EPUB file. /// /// Seekable stream containing the EPUB file. /// Various options to configure the behavior of the EPUB reader. /// EPUB book with all its content. This object does not retain a handle to the EPUB file. public static EpubBook ReadBook(Stream stream, EpubReaderOptions? epubReaderOptions) { BookReader bookReader = new(environmentDependencies, epubReaderOptions); return bookReader.ReadBook(stream); } /// /// Opens the book asynchronously and reads all of its content into the memory. The object returned by this method does not retain a handle to the EPUB file. /// /// Path to the EPUB file. /// /// A preset to configure the behavior of the EPUB reader. /// Default value is EpubReaderOptionsPreset.RELAXED. /// /// EPUB book with all its content. This object does not retain a handle to the EPUB file. public static Task ReadBookAsync(string filePath, EpubReaderOptionsPreset epubReaderOptionsPreset = EpubReaderOptionsPreset.RELAXED) { BookReader bookReader = new(environmentDependencies, new EpubReaderOptions(epubReaderOptionsPreset)); return bookReader.ReadBookAsync(filePath); } /// /// Opens the book asynchronously and reads all of its content into the memory. The object returned by this method does not retain a handle to the EPUB file. /// /// Path to the EPUB file. /// Various options to configure the behavior of the EPUB reader. /// EPUB book with all its content. This object does not retain a handle to the EPUB file. public static Task ReadBookAsync(string filePath, EpubReaderOptions? epubReaderOptions) { BookReader bookReader = new(environmentDependencies, epubReaderOptions); return bookReader.ReadBookAsync(filePath); } /// /// Opens the book asynchronously and reads all of its content into the memory. The object returned by this method does not retain a handle to the EPUB file. /// /// Seekable stream containing the EPUB file. /// /// A preset to configure the behavior of the EPUB reader. /// Default value is EpubReaderOptionsPreset.RELAXED. /// /// EPUB book with all its content. This object does not retain a handle to the EPUB file. public static Task ReadBookAsync(Stream stream, EpubReaderOptionsPreset epubReaderOptionsPreset = EpubReaderOptionsPreset.RELAXED) { BookReader bookReader = new(environmentDependencies, new EpubReaderOptions(epubReaderOptionsPreset)); return bookReader.ReadBookAsync(stream); } /// /// Opens the book asynchronously and reads all of its content into the memory. The object returned by this method does not retain a handle to the EPUB file. /// /// Seekable stream containing the EPUB file. /// Various options to configure the behavior of the EPUB reader. /// EPUB book with all its content. This object does not retain a handle to the EPUB file. public static Task ReadBookAsync(Stream stream, EpubReaderOptions? epubReaderOptions) { BookReader bookReader = new(environmentDependencies, epubReaderOptions); return bookReader.ReadBookAsync(stream); } } }