MCPcopy Index your code
hub / github.com/NativeScript/NativeScript / fromPath

Method fromPath

packages/core/file-system/index.ts:315–344  ·  view source on GitHub ↗
(path: string, copy: boolean = false)

Source from the content-addressed store, hash-verified

313 }
314
315 public static fromPath(path: string, copy: boolean = false) {
316 const onError = function (error) {
317 throw error;
318 };
319
320 if (__ANDROID__ && copy) {
321 if (path.startsWith('content:')) {
322 const fileInfo = getFileAccess().getFile(path, onError);
323 // falls back to creating a temp file without a known extension.
324 if (!fileInfo) {
325 const tempFile = `${knownFolders.temp().path}/${java.util.UUID.randomUUID().toString()}`;
326 org.nativescript.widgets.Async.File.copySync(path, tempFile, getNativeApp<android.app.Application>().getApplicationContext());
327 path = tempFile;
328 } else {
329 const ext = fileInfo.extension;
330 const name = `${fileInfo.name.replace(`.${ext}`, '')}.${ext}`;
331 const tempFile = `${knownFolders.temp().path}/${name}`;
332 getFileAccess().copySync(path, tempFile);
333 path = tempFile;
334 }
335 }
336 }
337
338 const fileInfo = getFileAccess().getFile(path, onError);
339 if (!fileInfo) {
340 return undefined;
341 }
342
343 return createFile(fileInfo);
344 }
345
346 public static exists(path: string): boolean {
347 return getFileAccess().fileExists(path);

Callers 15

safeReadTextFunction · 0.45
loadAndExtractMapFunction · 0.45
toFileFunction · 0.45
toFileFunction · 0.45
registerFontsInFolderFunction · 0.45
loadMethod · 0.45
processFolderFunction · 0.45
createFileMethod · 0.45
doWorkFunction · 0.45
pickFileFunction · 0.45
saveFileFunction · 0.45
copyFileFunction · 0.45

Calls 8

getNativeAppFunction · 0.90
getFileAccessFunction · 0.85
createFileFunction · 0.85
replaceMethod · 0.80
getFileMethod · 0.65
copySyncMethod · 0.65
toStringMethod · 0.45
randomUUIDMethod · 0.45

Tested by

no test coverage detected