unpak.js
Version:
Modern TypeScript library for reading Unreal Engine pak files and assets, inspired by CUE4Parse
140 lines • 3.69 kB
TypeScript
/**
* Phase 10: Advanced File Systems - Virtual File System implementation
*
* Provides a unified interface for accessing files from multiple archives
* with intelligent caching, prioritization, and async loading capabilities.
*/
import { IArchive } from '../../core/io/IArchive';
/**
* Priority levels for file loading
*/
export declare enum LoadPriority {
LOW = 0,
NORMAL = 1,
HIGH = 2,
CRITICAL = 3
}
/**
* Cache entry with metadata
*/
export interface ICacheEntry {
/** Cached file data */
data: Buffer;
/** Last access timestamp */
lastAccess: number;
/** File size in bytes */
size: number;
/** Access count */
accessCount: number;
/** Load priority */
priority: LoadPriority;
}
/**
* Virtual file mount point
*/
export interface IVirtualMount {
/** Archive instance */
archive: IArchive;
/** Mount path prefix */
mountPath: string;
/** Mount priority (higher = preferred) */
priority: number;
/** Whether this mount is read-only */
readOnly: boolean;
}
/**
* Async loading request
*/
export interface ILoadRequest {
/** File path to load */
filePath: string;
/** Loading priority */
priority: LoadPriority;
/** Request timestamp */
timestamp: number;
/** Promise resolver */
resolve: (data: Buffer | null) => void;
/** Promise rejector */
reject: (error: Error) => void;
}
/**
* VFS Configuration options
*/
export interface IVFSConfig {
/** Maximum cache size in bytes (default: 256MB) */
maxCacheSize?: number;
/** Maximum number of cached files (default: 1000) */
maxCacheEntries?: number;
/** Enable LRU cache eviction (default: true) */
enableLRU?: boolean;
/** Maximum concurrent loads (default: 4) */
maxConcurrentLoads?: number;
/** Cache statistics interval in ms (default: 30000) */
statsInterval?: number;
}
/**
* Virtual File System for multi-archive support
*
* Features:
* - Mount multiple archives with priority system
* - Intelligent LRU caching with size limits
* - Asynchronous loading with priority queues
* - File override system for modding
* - Performance monitoring and statistics
*/
export declare class VirtualFileSystem {
private mounts;
private cache;
private loadQueue;
private activeLoads;
private config;
private stats;
constructor(config?: IVFSConfig);
/**
* Mount an archive at the specified path
*/
mount(mountPath: string, archive: IArchive, priority?: number, readOnly?: boolean): void;
/**
* Unmount an archive
*/
unmount(mountPath: string): boolean;
/**
* Get file data synchronously (cache only)
*/
getFileSync(filePath: string): Buffer | null;
/**
* Get file data asynchronously with priority support
*/
getFileAsync(filePath: string, priority?: LoadPriority): Promise<Buffer | null>;
/**
* Check if file exists in any mounted archive
*/
fileExists(filePath: string): boolean;
/**
* List all files matching pattern
*/
listFiles(pattern?: RegExp): string[];
/**
* Clear cache
*/
clearCache(): void;
/**
* Get VFS statistics
*/
getStats(): typeof this.stats & {
cacheEntries: number;
mountedArchives: number;
};
private startLoad;
private findBestMount;
private loadFromArchive;
private addToCache;
private evictIfNeeded;
private evictLRUEntry;
private removeFromCache;
private processQueuedRequests;
private normalizePath;
private getRelativePath;
private reportStats;
}
//# sourceMappingURL=VirtualFileSystem.d.ts.map