Class ZipAssetProvider
Provides the entries of a zip as assets: extracted once into a folder named after the zip's stamp (ZipStamp), and read from there as files.
public class ZipAssetProvider : IAssetProvider
- Inheritance
-
ZipAssetProvider
- Implements
- Inherited Members
Remarks
A start reads only the stamp in front of the zip, and the whole zip only to extract it; a zip without a stamp is hashed whole instead, a pass over it before the first read. A name from outside the bytes would not do: a phone's update unpacks the app again, changed or not, and a file's time and size are not reliable.
The folder is the provider's: it tries to delete the other folders in it, so no other zip may be given it. Two instances, or two processes, each write their copy to a folder of their own and move it into place, and a version already there is taken as it stands; a race between them is not fully guarded.
Constructors
ZipAssetProvider(IAsset, string)
Provides the entries of a zip as assets: extracted once into a folder named after the zip's stamp (ZipStamp), and read from there as files.
public ZipAssetProvider(IAsset zip, string extractFolderPath)
Parameters
zipIAssetThe zip.
extractFolderPathstringThe folder the zip is extracted into, the provider's alone.
Remarks
A start reads only the stamp in front of the zip, and the whole zip only to extract it; a zip without a stamp is hashed whole instead, a pass over it before the first read. A name from outside the bytes would not do: a phone's update unpacks the app again, changed or not, and a file's time and size are not reliable.
The folder is the provider's: it tries to delete the other folders in it, so no other zip may be given it. Two instances, or two processes, each write their copy to a folder of their own and move it into place, and a version already there is taken as it stands; a race between them is not fully guarded.
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.