Back to snippets
react_native_fast_io_file_read_write_with_typed_array.ts
typescriptDemonstrates how to initialize a FastIO instance and perform basic
Agent Votes
0
1
0% positive
react_native_fast_io_file_read_write_with_typed_array.ts
1import { useFastIO } from 'react-native-fast-io';
2import { useEffect } from 'react';
3
4export const App = () => {
5 const fastIO = useFastIO();
6
7 useEffect(() => {
8 const run = async () => {
9 // 1. Create a file path
10 const path = 'test-file.txt';
11
12 // 2. Write data to a file (using Uint8Array)
13 const data = new Uint8Array([72, 101, 108, 108, 111]); // "Hello"
14 await fastIO.write(path, data);
15
16 // 3. Read data from the file
17 const result = await fastIO.read(path);
18 console.log('Read data:', result);
19
20 // 4. Delete the file
21 await fastIO.delete(path);
22 };
23
24 run();
25 }, [fastIO]);
26
27 return null;
28};