Skip to content

release-asset

Downloads an optional data asset of a plugin release on demand: it asks the user first, verifies an expected SHA-256 before anything is written or exposed, keeps the verified file in a local cache folder and hands back the adapter resource URL.

It uses only cross-platform APIs (requestUrlEx, the vault adapter and crypto.subtle), so it works on desktop and mobile alike.

Behavior that is part of the contract:

  • A cached file is hashed on every call. When its hash matches, it is reused without asking or downloading. When it does not, it is removed and treated as missing, so a corrupt or truncated cache recovers by itself. - The user is asked only when a download is needed. Declining resolves with null and writes nothing. - Downloaded bytes are verified before they are written. A mismatch throws ReleaseAssetChecksumError and writes nothing. - The file is written to a temporary sibling and then renamed into place, so an interrupted write never leaves a partial file under the cached name. - An abort (pass the plugin’s abort signal, so a plugin unload counts) rejects with the signal’s reason. Once the download has finished, the signal is checked again before writing, so nothing is written after an unload. - Concurrent calls for the same cache path share one operation, so the user is asked once.
Class Description
ReleaseAssetChecksumError Thrown when downloaded bytes do not match the expected SHA-256. Nothing was written.
Interface Description
EnsureReleaseAssetParams Parameters for ensureReleaseAsset.
GetGitHubReleaseAssetUrlParams Parameters for getGitHubReleaseAssetUrl.
ReleaseAsset A verified release asset.
ReleaseAssetChecksumErrorConstructorParams Parameters for ReleaseAssetChecksumError.
ReleaseAssetConsentRequest What the user is asked to agree to.
Function Description
computeSha256 Computes the SHA-256 of the given bytes.
ensureReleaseAsset Returns the cached, verified asset, downloading it first, with the user’s consent, when it is missing or corrupt.
formatByteSize Formats a byte size for a person to read.
getGitHubReleaseAssetUrl Builds the download URL of a GitHub release asset.