MCPcopy Create free account
hub / github.com/alpha0010/react-native-file-access / FsDemo

Function FsDemo

example/src/App.tsx:16–275  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

14} from 'react-native-safe-area-context';
15
16function FsDemo() {
17 const [info, setInfo] = useState<{ key: string; value: string }[]>([]);
18 const insets = useSafeAreaInsets();
19
20 useEffect(() => {
21 // Directory constants.
22 setInfo([
23 { key: 'CacheDir', value: Dirs.CacheDir },
24 { key: 'DatabaseDir', value: Dirs.DatabaseDir ?? '<undefined>' },
25 { key: 'DocumentDir', value: Dirs.DocumentDir },
26 { key: 'LibraryDir', value: Dirs.LibraryDir ?? '<undefined>' },
27 { key: 'MainBundleDir', value: Dirs.MainBundleDir },
28 { key: 'SDCardDir', value: Dirs.SDCardDir ?? '<undefined>' },
29 ]);
30
31 // Deletes and asset extraction.
32 FileSystem.unlink(Dirs.CacheDir + '/BundledData.txt')
33 .then(() => console.log('Deleted BundledData.txt'))
34 .catch(() => console.log('Did not delete BundledData.txt'))
35 .then(() =>
36 FileSystem.cpAsset(
37 'BundledData.txt',
38 Dirs.CacheDir + '/BundledData.txt'
39 )
40 )
41 .then(() => FileSystem.readFile(Dirs.CacheDir + '/BundledData.txt'))
42 .then((res) =>
43 setInfo((prev) => {
44 prev.push({
45 key: 'readFile(CacheDir/BundledData.txt)',
46 value: JSON.stringify(res),
47 });
48 return prev.slice();
49 })
50 );
51
52 if (Platform.OS === 'android') {
53 FileSystem.cpAsset(
54 'raw/android_resource',
55 Dirs.CacheDir + '/android_resource.txt',
56 'resource'
57 )
58 .then(() =>
59 FileSystem.readFile(Dirs.CacheDir + '/android_resource.txt')
60 )
61 .then((res) =>
62 setInfo((prev) => {
63 prev.push({
64 key: 'readFile(CacheDir/android_resource.txt)',
65 value: JSON.stringify(res),
66 });
67 return prev.slice();
68 })
69 );
70 }
71
72 // Disk usage.
73 FileSystem.df().then((res) =>

Callers

nothing calls this directly

Calls 15

unlinkMethod · 0.65
cpAssetMethod · 0.65
readFileMethod · 0.65
dfMethod · 0.65
existsMethod · 0.65
isDirMethod · 0.65
lsMethod · 0.65
writeFileMethod · 0.65
readFileChunkMethod · 0.65
hashMethod · 0.65
appendFileMethod · 0.65
concatFilesMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…