Skip to main content
Version: Next

Class: ResourceFetcher

Defined in: utils/ResourceFetcher.ts:54

Static entry point that delegates resource operations to the configured ResourceFetcherAdapter (registered via initExecutorch({ resourceFetcher })).

For storage-management utilities — deleting downloaded models, listing downloaded files, getting their total size, and pausing/resuming/cancelling downloads — use the adapter implementation directly. See ExpoResourceFetcher (in react-native-executorch-expo-resource-fetcher) or BareResourceFetcher (in react-native-executorch-bare-resource-fetcher).

Constructors

Constructor

new ResourceFetcher(): ResourceFetcher

Returns

ResourceFetcher

Properties

fs

static fs: object

Defined in: utils/ResourceFetcher.ts:133

Filesystem utilities for reading downloaded resources.

readAsString()

readAsString: (path) => Promise<string>

Reads the contents of a file as a string.

Parameters
path

string

Absolute file path to read.

Returns

Promise<string>

A promise that resolves to the file contents as a string.

Remarks

REQUIRED: Used internally for reading configuration files (e.g., tokenizer configs).

Remarks

Provides access to filesystem operations through the configured adapter. Currently supports reading file contents as strings for configuration files.

Methods

fetch()

static fetch(callback?, ...sources): Promise<string[]>

Defined in: utils/ResourceFetcher.ts:104

Fetches resources (remote URLs, local files or embedded assets), downloads or stores them locally for use by React Native ExecuTorch.

Parameters

callback?

(downloadProgress) => void

Optional callback to track progress of all downloads, reported between 0 and 1.

sources

...ResourceSource[]

Multiple resources that can be strings, asset references, or objects.

Returns

Promise<string[]>

If the fetch was successful, it returns a promise which resolves to an array of local file paths for the downloaded/stored resources (without file:// prefix). If the fetch was interrupted, it returns a promise which resolves to null.


getAdapter()

static getAdapter(): ResourceFetcherAdapter

Defined in: utils/ResourceFetcher.ts:83

Gets the current resource fetcher adapter instance.

Returns

ResourceFetcherAdapter

The configured ResourceFetcherAdapter instance.

Throws

If no adapter has been set via setAdapter.

Remarks

INTERNAL: Used internally by all resource fetching operations.


resetAdapter()

static resetAdapter(): void

Defined in: utils/ResourceFetcher.ts:72

Resets the resource fetcher adapter to null.

Returns

void

Remarks

INTERNAL: Used primarily for testing purposes to clear the adapter state.


setAdapter()

static setAdapter(adapter): void

Defined in: utils/ResourceFetcher.ts:63

Sets a custom resource fetcher adapter for resource operations.

Parameters

adapter

ResourceFetcherAdapter

The adapter instance to use for fetching resources.

Returns

void

Remarks

INTERNAL: Used by platform-specific init functions (expo/bare) to inject their fetcher implementation.