Class FolderAssetProvider
Provides the assets under a folder, read where they lie: the folder beside an executable, an app bundle, or a folder something else unpacked.
public class FolderAssetProvider : IAssetProvider
- Inheritance
-
FolderAssetProvider
- Implements
- Inherited Members
Remarks
A path that leads outside the folder, such as one with .., counts as an absent asset; a link on the disk may
still lead out. Absence is what Exists(string) tells.
Constructors
FolderAssetProvider(string)
Initializes a new instance of the FolderAssetProvider class.
public FolderAssetProvider(string folderPath)
Parameters
folderPathstringThe folder; a relative path is taken from the current directory.
Methods
OpenReadAsync(string, CancellationToken)
Opens the asset at a path, such as fonts/text.ttf.
public Task<Stream> OpenReadAsync(string assetPath, CancellationToken cancellationToken)
Parameters
assetPathstringThe asset's path.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
Remarks
It is asynchronous because a page in a browser fetches over the network and cannot wait. Read the stream
forward: whether it can seek is the platform's answer, not a promise; a file can, an HTTP body and an Android
asset cannot. A caller that needs more than one pass opens the asset again where it can, and copies it into
memory only where it cannot, so the cost is paid where it is decided. A caller that only asks, such as a language
falling back to another, takes TryOpenReadAsync, which gives null for an absent asset.
Exceptions
- AssetNotFoundException
The provider classes the asset as absent; exactly this type, as a file it finds and cannot open is another failure.