MCPcopy
hub / github.com/diegomura/react-pdf / fetchLocalFile

Function fetchLocalFile

packages/image/src/resolve.js:27–45  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25};
26
27const fetchLocalFile = src =>
28 new Promise((resolve, reject) => {
29 try {
30 if (BROWSER) {
31 reject(new Error('Cannot fetch local file in this environemnt'));
32 return;
33 }
34 const absolutePath = getAbsoluteLocalPath(src);
35 if (!absolutePath) {
36 reject(new Error(`Cannot fetch non-local path: ${src}`));
37 return;
38 }
39 fs.readFile(absolutePath, (err, data) =>
40 err ? reject(err) : resolve(data),
41 );
42 } catch (err) {
43 reject(err);
44 }
45 });
46
47const fetchRemoteFile = async (uri, options) => {
48 const response = await fetch(uri, options);

Callers 1

resolveImageFromUrlFunction · 0.85

Calls 2

getAbsoluteLocalPathFunction · 0.85
resolveFunction · 0.85

Tested by

no test coverage detected