|
1 | | -/** |
2 | | - * Resource Fetcher |
3 | | - * |
4 | | - * Provides an interface for downloading files (via `ResourceFetcher.fetch()`) |
5 | | - * |
6 | | - * Key functionality: |
7 | | - * - Download control: pause, resume, and cancel operations through: |
8 | | - * - Single file: `.pauseFetching()`, `.resumeFetching()`, `.cancelFetching()` |
9 | | - * - Downloaded file management: |
10 | | - * - `.getFilesTotalSize()`, `.listDownloadedFiles()`, `.listDownloadedModels()`, `.deleteResources()` |
11 | | - * |
12 | | - * Remark: The pausing/resuming/canceling works only for fetching remote resources. |
13 | | - * |
14 | | - * Most exported functions accept: |
15 | | - * - Multiple `ResourceSource` arguments, (union type of string, number or object) |
16 | | - * |
17 | | - * Method `.fetch()` takes argument as callback that reports download progress. |
18 | | - * 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). |
19 | | - * |
20 | | - * Technical Implementation: |
21 | | - * - Maintains a `downloads` Map instance that tracks: |
22 | | - * - Currently downloading resources |
23 | | - * - Paused downloads |
24 | | - * - Successful downloads are automatically removed from the `downloads` Map |
25 | | - * - Uses the `ResourceSourceExtended` interface to enable pause/resume functionality: |
26 | | - * - Wraps user-provided `ResourceSource` elements |
27 | | - * - Implements linked list behavior via the `.next` attribute |
28 | | - * - Automatically processes subsequent downloads when `.next` contains a valid resource |
29 | | - */ |
30 | | - |
31 | 1 | import { ResourceSource } from '../types/common'; |
32 | 2 | import { RnExecutorchError } from '../errors/errorUtils'; |
33 | 3 | import { RnExecutorchErrorCode } from '../errors/ErrorCodes'; |
34 | 4 |
|
| 5 | +/** |
| 6 | + * Adapter interface for resource fetching operations. |
| 7 | + * |
| 8 | + * **Required Methods:** |
| 9 | + * - {@link fetch}: Download resources to local storage (used by all modules) |
| 10 | + * - {@link readAsString}: Read file contents as string (used for config files) |
| 11 | + * |
| 12 | + * @remarks |
| 13 | + * This interface is intentionally minimal. Custom fetchers only need to implement |
| 14 | + * these two methods for the library to function correctly. |
| 15 | + */ |
35 | 16 | export interface ResourceFetcherAdapter { |
| 17 | + /** |
| 18 | + * Download resources to local storage. |
| 19 | + * |
| 20 | + * @param callback - Progress callback (0-100) |
| 21 | + * @param sources - One or more resources to download |
| 22 | + * @returns Array of local file paths, or null if download was interrupted |
| 23 | + * |
| 24 | + * @remarks |
| 25 | + * **REQUIRED**: Used by all library modules for downloading models and resources. |
| 26 | + */ |
36 | 27 | fetch( |
37 | 28 | callback: (downloadProgress: number) => void, |
38 | 29 | ...sources: ResourceSource[] |
39 | 30 | ): Promise<string[] | null>; |
40 | | - pauseFetching(...sources: ResourceSource[]): Promise<void>; |
41 | | - resumeFetching(...sources: ResourceSource[]): Promise<void>; |
42 | | - cancelFetching(...sources: ResourceSource[]): Promise<void>; |
43 | | - listDownloadedFiles(): Promise<string[]>; |
44 | | - listDownloadedModels(): Promise<string[]>; |
45 | | - deleteResources(...sources: ResourceSource[]): Promise<void>; |
46 | | - getFilesTotalSize(...sources: ResourceSource[]): Promise<number>; |
| 31 | + |
| 32 | + /** |
| 33 | + * Read file contents as a string. |
| 34 | + * |
| 35 | + * @param path - Absolute file path |
| 36 | + * @returns File contents as string |
| 37 | + * |
| 38 | + * @remarks |
| 39 | + * **REQUIRED**: Used internally for reading configuration files (e.g., tokenizer configs). |
| 40 | + */ |
47 | 41 | readAsString(path: string): Promise<string>; |
48 | 42 | } |
49 | 43 |
|
|
0 commit comments