MCPcopy Create free account
hub / github.com/callstackincubator/react-native-fast-io / FileSystemUI

Function FileSystemUI

example/tests/filesystem.tsx:9–79  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

7import { BASE_URL } from './benchmark'
8
9export function FileSystemUI() {
10 const [file, setFile] = useState<File | null>(null)
11
12 const pickFile = async (options?: Parameters<typeof showOpenFilePicker>[0]) => {
13 const [fileHandle] = await showOpenFilePicker(options)
14 const file = await fileHandle.getFile()
15 // @ts-ignore
16 setFile(file)
17 }
18
19 const sendFile = async (compression?: 'gzip' | 'deflate' | 'deflate-raw') => {
20 if (!file) {
21 return
22 }
23 const body = compression ? file.stream().pipeThrough(new CompressionStream(compression)) : file
24
25 await fetch(`http://${BASE_URL}:3002/upload`, {
26 method: 'POST',
27 body,
28 })
29 }
30
31 const logContents = async () => {
32 for await (const chunk of file!.stream()) {
33 console.log('Chunk length: ', chunk.length)
34 }
35 }
36
37 return (
38 <View>
39 <Text style={styles.header}>File System Test</Text>
40
41 <TouchableOpacity style={styles.button} onPress={() => pickFile()}>
42 <Text style={styles.buttonText}>Pick any file</Text>
43 </TouchableOpacity>
44
45 <TouchableOpacity
46 style={styles.button}
47 onPress={() => pickFile({ types: [{ accept: { 'image/*': ['.png', '.jpg', '.jpeg'] } }] })}
48 >
49 <Text style={styles.buttonText}>Pick image</Text>
50 </TouchableOpacity>
51
52 {file && (
53 <View style={styles.actions}>
54 <TouchableOpacity style={styles.button} onPress={() => sendFile()}>
55 <Text style={styles.buttonText}>Send Uncompressed</Text>
56 </TouchableOpacity>
57 <TouchableOpacity style={styles.button} onPress={() => sendFile('gzip')}>
58 <Text style={styles.buttonText}>Send Gzipped</Text>
59 </TouchableOpacity>
60 <TouchableOpacity style={styles.button} onPress={() => sendFile('deflate')}>
61 <Text style={styles.buttonText}>Send Deflated</Text>
62 </TouchableOpacity>
63 <TouchableOpacity style={styles.button} onPress={() => sendFile('deflate-raw')}>
64 <Text style={styles.buttonText}>Send Deflated Raw</Text>
65 </TouchableOpacity>
66 <TouchableOpacity style={styles.button} onPress={() => logContents()}>

Callers

nothing calls this directly

Calls 3

pickFileFunction · 0.85
sendFileFunction · 0.85
logContentsFunction · 0.85

Tested by

no test coverage detected