react-native-executorch
Version:
An easy way to run AI models in React Native with ExecuTorch
54 lines • 2.62 kB
TypeScript
/**
* Resource Fetcher
*
* Provides an interface for downloading files (via `ResourceFetcher.fetch()`)
*
* Key functionality:
* - Download control: pause, resume, and cancel operations through:
* - Single file: `.pauseFetching()`, `.resumeFetching()`, `.cancelFetching()`
* - Downloaded file management:
* - `.getFilesTotalSize()`, `.listDownloadedFiles()`, `.listDownloadedModels()`, `.deleteResources()`
*
* Remark: The pausing/resuming/canceling works only for fetching remote resources.
*
* Most exported functions accept:
* - Multiple `ResourceSource` arguments, (union type of string, number or object)
*
* Method `.fetch()` takes argument as callback that reports download progress.
* Method`.fetch()` returns array of paths to successfully saved files or null if the download was paused or cancelled (then resume functions can return paths).
*
* Technical Implementation:
* - Maintains a `downloads` Map instance that tracks:
* - Currently downloading resources
* - Paused downloads
* - Successful downloads are automatically removed from the `downloads` Map
* - Uses the `ResourceSourceExtended` interface to enable pause/resume functionality:
* - Wraps user-provided `ResourceSource` elements
* - Implements linked list behavior via the `.next` attribute
* - Automatically processes subsequent downloads when `.next` contains a valid resource
*/
import { ResourceSource } from '../types/common';
import { DownloadResource } from './ResourceFetcherUtils';
export declare class ResourceFetcher {
static downloads: Map<ResourceSource, DownloadResource>;
static fetch(callback?: (downloadProgress: number) => void, ...sources: ResourceSource[]): Promise<string[] | null>;
private static singleFetch;
private static returnOrStartNext;
private static pause;
private static resume;
private static cancel;
static pauseFetching(...sources: ResourceSource[]): Promise<void>;
static resumeFetching(...sources: ResourceSource[]): Promise<void>;
static cancelFetching(...sources: ResourceSource[]): Promise<void>;
private static findActive;
static listDownloadedFiles(): Promise<string[]>;
static listDownloadedModels(): Promise<string[]>;
static deleteResources(...sources: ResourceSource[]): Promise<void>;
static getFilesTotalSize(...sources: ResourceSource[]): Promise<number>;
private static handleObject;
private static handleLocalFile;
private static handleReleaseModeFile;
private static handleDevModeFile;
private static handleRemoteFile;
}
//# sourceMappingURL=ResourceFetcher.d.ts.map