using System; using System.IO; using System.Threading.Tasks; namespace VersOne.Epub { /// /// The base class for a content file reference within the EPUB archive (e.g., an HTML file or an image). /// Unlike , the classes derived from this base class contain only a reference to the file but don't contain its content. /// public abstract class EpubLocalContentFileRef : EpubContentFileRef { /// /// Initializes a new instance of the class with a specified content file key, a content type of the file reference, /// a MIME type of the file's content, a EPUB file reference, a content directory path, and an optional content reader options. /// /// Metadata of this content file reference. /// The absolute path of the local content file in the EPUB archive. /// A reference to the EPUB content loader which provides methods to load the content of this file. /// The parameter is null. /// The parameter is null. /// The parameter is null. protected EpubLocalContentFileRef(EpubContentFileRefMetadata metadata, string filePath, IEpubContentLoader epubContentLoader) : base(metadata, epubContentLoader) { FilePath = filePath ?? throw new ArgumentNullException(nameof(filePath)); } /// /// Gets the absolute path of the local content file in the EPUB archive. /// public string FilePath { get; } /// /// Gets the location of the content file which is always for local content file references. /// public override EpubContentLocation ContentLocation => EpubContentLocation.LOCAL; /// /// Reads the whole content of the referenced file and returns it as a byte array. /// /// Content of the referenced file. public byte[] ReadContentAsBytes() { return EpubContentLoader.LoadContentAsBytes(Metadata); } /// /// Asynchronously reads the whole content of the referenced file and returns it as a byte array. /// /// A task that represents the asynchronous read operation. The value of the TResult parameter contains the content of the referenced file. public Task ReadContentAsBytesAsync() { return EpubContentLoader.LoadContentAsBytesAsync(Metadata); } /// /// Reads the whole content of the referenced file and returns it as a string. /// /// Content of the referenced file. public string ReadContentAsText() { return EpubContentLoader.LoadContentAsText(Metadata); } /// /// Asynchronously reads the whole content of the referenced file and returns it as a string. /// /// A task that represents the asynchronous read operation. The value of the TResult parameter contains the content of the referenced file. public Task ReadContentAsTextAsync() { return EpubContentLoader.LoadContentAsTextAsync(Metadata); } /// /// Opens the referenced file and returns a to access its content. /// /// A to access the referenced file's content. public Stream GetContentStream() { return EpubContentLoader.GetContentStream(Metadata); } /// /// Opens the referenced file and returns a to access its content. /// /// /// A task that represents the asynchronous open operation. The value of the TResult parameter contains the to access the referenced file's content. /// public Task GetContentStreamAsync() { return EpubContentLoader.GetContentStreamAsync(Metadata); } } }