Table of Contents

Interface IAssetProvider

Namespace
VpnHood.Net.Toolkit.Assets
Assembly
VpnHood.Net.Toolkit.dll

Represents where a build's data files ended up on this platform, read by path: beside the executable, inside an app bundle, inside an Android package, or over HTTP for a page that has nothing placed beside it.

public interface IAssetProvider

Remarks

There is one implementation per platform, not per set of files, so a new set of files is a new path and nothing else.

Methods

OpenReadAsync(string, CancellationToken)

Opens the asset at a path, such as fonts/text.ttf.

Task<Stream> OpenReadAsync(string assetPath, CancellationToken cancellationToken)

Parameters

assetPath string

The asset's path.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task<Stream>

A task whose result is a new stream, which the caller owns and disposes.

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.