MCPcopy
hub / github.com/huggingface/transformers.js / getFile

Function getFile

packages/transformers/src/utils/hub.js:60–74  ·  view source on GitHub ↗
(urlOrPath)

Source from the content-addressed store, hash-verified

58 * @returns {Promise<FileResponse|Response>} A promise that resolves to a FileResponse object (if the file is retrieved using the FileSystem API), or a Response object (if the file is retrieved using the Fetch API).
59 */
60export async function getFile(urlOrPath) {
61 if (env.useFS && !isValidUrl(urlOrPath, ['http:', 'https:', 'blob:'])) {
62 return new FileResponse(
63 urlOrPath instanceof URL
64 ? urlOrPath.protocol === 'file:'
65 ? urlOrPath.pathname
66 : urlOrPath.toString()
67 : urlOrPath,
68 );
69 } else {
70 return env.fetch(urlOrPath, {
71 headers: getFetchHeaders(urlOrPath),
72 });
73 }
74}
75
76/**
77 * Generates appropriate HTTP headers for fetching resources.

Callers 5

fromURLMethod · 0.90
load_audioFunction · 0.90
_get_file_metadataFunction · 0.90
utils.test.jsFile · 0.90
loadResourceFileFunction · 0.85

Calls 2

isValidUrlFunction · 0.90
getFetchHeadersFunction · 0.85

Tested by

no test coverage detected