(options: WebAssetOptions = {})
| 161 | } |
| 162 | |
| 163 | export function getNativeWebAssetsDir(options: WebAssetOptions = {}): string | null { |
| 164 | const source = options.source ?? getSeaAssetSource(); |
| 165 | if (source === null) return null; |
| 166 | |
| 167 | const manifest = options.manifest ?? getEmbeddedWebAssetManifest(source, currentTarget()); |
| 168 | if (manifest === null) return null; |
| 169 | |
| 170 | const cacheRoot = getWebAssetCacheRoot(manifest, options); |
| 171 | for (const file of manifest.files) { |
| 172 | assertSafeRelativePath(file.relativePath); |
| 173 | const bytes = toBuffer(source.getRawAsset(file.assetKey)); |
| 174 | const actualSha256 = sha256(bytes); |
| 175 | if (actualSha256 !== file.sha256) { |
| 176 | throw new Error( |
| 177 | `Web asset checksum mismatch for ${file.assetKey}: ${actualSha256} !== ${file.sha256}`, |
| 178 | ); |
| 179 | } |
| 180 | ensureFile(join(cacheRoot, file.relativePath), bytes, file.sha256); |
| 181 | } |
| 182 | return cacheRoot; |
| 183 | } |
no test coverage detected