| 12 | * 二进制加载器实现 |
| 13 | */ |
| 14 | export class BinaryLoader implements IAssetLoader<IBinaryAsset> { |
| 15 | readonly supportedType = AssetType.Binary; |
| 16 | readonly supportedExtensions = [ |
| 17 | '.bin', '.dat', '.raw', '.bytes', |
| 18 | '.wasm', '.so', '.dll', '.dylib' |
| 19 | ]; |
| 20 | readonly contentType: AssetContentType = 'binary'; |
| 21 | |
| 22 | /** |
| 23 | * Parse binary from content. |
| 24 | * 从内容解析二进制。 |
| 25 | */ |
| 26 | async parse(content: IAssetContent, _context: IAssetParseContext): Promise<IBinaryAsset> { |
| 27 | if (!content.binary) { |
| 28 | throw new Error('Binary content is empty'); |
| 29 | } |
| 30 | |
| 31 | return { |
| 32 | data: content.binary |
| 33 | }; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Dispose loaded asset |
| 38 | * 释放已加载的资产 |
| 39 | */ |
| 40 | dispose(asset: IBinaryAsset): void { |
| 41 | // 释放二进制数据引用以允许垃圾回收 |
| 42 | // Release binary data reference to allow garbage collection |
| 43 | (asset as { data: ArrayBuffer | null }).data = null; |
| 44 | } |
| 45 | } |
nothing calls this directly
no outgoing calls
no test coverage detected