using System;
using System.IO;
using System.Threading.Tasks;
namespace VersOne.Epub
{
///
/// The base class for a content file reference located outside of 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 EpubRemoteContentFileRef : 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, and content downloader options.
///
/// Metadata of this content file reference.
/// A reference to the EPUB content loader which provides methods to download the content of this file.
/// The parameter is null.
/// The parameter is null.
protected EpubRemoteContentFileRef(EpubContentFileRefMetadata metadata, IEpubContentLoader epubContentLoader)
: base(metadata, epubContentLoader)
{
}
///
/// Gets the absolute URI of the remote content file (as it is specified in the EPUB manifest).
///
public string Url => Key;
///
/// Gets the location of the content file which is always for remote content file references.
///
public override EpubContentLocation ContentLocation => EpubContentLocation.REMOTE;
///
/// Downloads the whole content of the referenced file and returns it as a byte array.
///
/// Content of the referenced file.
public byte[] DownloadContentAsBytes()
{
return EpubContentLoader.LoadContentAsBytes(Metadata);
}
///
/// Asynchronously downloads the whole content of the referenced file and returns it as a byte array.
///
/// A task that represents the asynchronous download operation. The value of the TResult parameter contains the content of the referenced file.
public Task DownloadContentAsBytesAsync()
{
return EpubContentLoader.LoadContentAsBytesAsync(Metadata);
}
///
/// Downloads the whole content of the referenced file and returns it as a string.
///
/// Content of the referenced file.
public string DownloadContentAsText()
{
return EpubContentLoader.LoadContentAsText(Metadata);
}
///
/// Asynchronously downloads the whole content of the referenced file and returns it as a string.
///
/// A task that represents the asynchronous download operation. The value of the TResult parameter contains the content of the referenced file.
public Task DownloadContentAsTextAsync()
{
return EpubContentLoader.LoadContentAsTextAsync(Metadata);
}
///
/// Starts the download of the referenced file and returns a to access its content.
///
/// A to access the referenced file's content.
public Stream GetDownloadingContentStream()
{
return EpubContentLoader.GetContentStream(Metadata);
}
///
/// Starts the download of the referenced file and returns a to access its content.
///
///
/// A task that represents the asynchronous download operation.
/// The value of the TResult parameter contains a to access the referenced file's content.
///
public Task GetDownloadingContentStreamAsync()
{
return EpubContentLoader.GetContentStreamAsync(Metadata);
}
}
}