Files
esengine/packages/asset-system/src/interfaces/IAssetReader.ts

91 lines
2.5 KiB
TypeScript
Raw Normal View History

/**
* Asset Reader Interface
*
*
* Provides unified file reading abstraction across different platforms.
*
*/
/**
* Asset content types.
*
*/
export type AssetContentType = 'text' | 'binary' | 'image' | 'audio';
/**
* Asset content result.
*
*/
export interface IAssetContent {
/** Content type. | 内容类型。 */
type: AssetContentType;
/** Text content (for text/json files). | 文本内容。 */
text?: string;
/** Binary content. | 二进制内容。 */
binary?: ArrayBuffer;
/** Image element (for textures). | 图片元素。 */
image?: HTMLImageElement;
/** Audio buffer (for audio files). | 音频缓冲区。 */
audioBuffer?: AudioBuffer;
}
/**
* Asset reader interface.
*
*
* Abstracts platform-specific file reading operations.
*
*/
export interface IAssetReader {
/**
* Read file as text.
*
*
* @param absolutePath - Absolute file path. |
* @returns Text content. |
*/
readText(absolutePath: string): Promise<string>;
/**
* Read file as binary.
*
*
* @param absolutePath - Absolute file path. |
* @returns Binary content. |
*/
readBinary(absolutePath: string): Promise<ArrayBuffer>;
/**
* Load image from file.
*
*
* @param absolutePath - Absolute file path. |
* @returns Image element. |
*/
loadImage(absolutePath: string): Promise<HTMLImageElement>;
/**
* Load audio from file.
*
*
* @param absolutePath - Absolute file path. |
* @returns Audio buffer. |
*/
loadAudio(absolutePath: string): Promise<AudioBuffer>;
/**
* Check if file exists.
*
*
* @param absolutePath - Absolute file path. |
* @returns True if exists. |
*/
exists(absolutePath: string): Promise<boolean>;
}
/**
* Service identifier for IAssetReader.
* IAssetReader
*/
export const IAssetReaderService = Symbol.for('IAssetReaderService');