@@ -22,13 +22,9 @@ import {
22
22
23
23
import {
24
24
Colors ,
25
- DebugInstructions ,
26
- ReloadInstructions ,
27
25
} from 'react-native/Libraries/NewAppScreen' ;
28
26
29
27
import RNFetchBlob from 'rn-fetch-blob' ;
30
-
31
-
32
28
33
29
const App : ( ) => React$Node = ( ) => {
34
30
@@ -41,6 +37,16 @@ const App: () => React$Node = () => {
41
37
42
38
const [ unlinkParam , setUnlinkParam ] = useState ( '' ) ;
43
39
40
+ const [ statParam , setStatParam ] = useState ( '' ) ;
41
+
42
+ const [ mkdirParam , setMkdirParam ] = useState ( '' ) ;
43
+ const [ mkdirURIParam , setMkdirURIParam ] = useState ( '' ) ;
44
+
45
+ const [ readParam , setReadParam ] = useState ( '' ) ;
46
+
47
+ const [ hashPathParam , setHashPathParam ] = useState ( '' ) ;
48
+ const [ hashAlgValue , setHashAlgValue ] = useState ( 'md5' ) ;
49
+
44
50
// Methods ********************************************************************
45
51
// exists()
46
52
const existsCall = ( ) => {
@@ -118,6 +124,105 @@ const App: () => React$Node = () => {
118
124
} )
119
125
}
120
126
127
+ // stat(), lstat()
128
+ const statCall = ( ) => {
129
+ RNFetchBlob . fs . stat ( RNFetchBlob . fs . dirs . DocumentDir + '/' + statParam )
130
+ . then ( ( stats ) => {
131
+ console . log ( stats ) ;
132
+ Alert . alert ( "stat() result (others logged in console)" ,
133
+ "filename: " + stats . filename +
134
+ "\nlastModified: " + stats . lastModified +
135
+ "\npath: " + stats . path +
136
+ "\nsize: " + stats . size +
137
+ "\ntype: " + stats . type )
138
+ } )
139
+ . catch ( ( err ) => {
140
+ Alert . alert ( err . message ) ;
141
+ } )
142
+ }
143
+
144
+ const lstatCall = ( ) => {
145
+ RNFetchBlob . fs . lstat ( RNFetchBlob . fs . dirs . DocumentDir + '/' + statParam )
146
+ . then ( ( stats ) => {
147
+ console . log ( stats ) ;
148
+ Alert . alert ( "lstat() result (others logged in console)" , "filename: " + stats [ 0 ] . filename +
149
+ "\nlastModified: " + stats [ 0 ] . lastModified +
150
+ "\npath: " + stats [ 0 ] . path +
151
+ "\nsize: " + stats [ 0 ] . size +
152
+ "\ntype: " + stats [ 0 ] . type ) ;
153
+ } )
154
+ . catch ( ( err ) => {
155
+ Alert . alert ( err . message ) ;
156
+ } )
157
+ }
158
+
159
+ // mkdir()
160
+ const mkdirCall = ( ) => {
161
+ if ( mkdirParam . length > 0 )
162
+ {
163
+ RNFetchBlob . fs . mkdir ( RNFetchBlob . fs . dirs . DocumentDir + '/' + mkdirParam )
164
+ . then ( ( ) => {
165
+ Alert . alert ( 'successfully created file:' , RNFetchBlob . fs . dirs . DocumentDir + '/' + mkdirParam ) ;
166
+ } )
167
+ . catch ( ( err ) => {
168
+ Alert . alert ( err . message ) ;
169
+ } )
170
+ }
171
+ else {
172
+ Alert . alert ( 'Cannot make file with no name provided' )
173
+ }
174
+ }
175
+
176
+ // createFile()
177
+ const createFileUTF8Call = ( ) => {
178
+ RNFetchBlob . fs . createFile ( RNFetchBlob . fs . dirs . DocumentDir + '/' + mkdirParam , 'foo' , 'utf8' ) ;
179
+ }
180
+
181
+ const createFileASCIICall = ( ) => {
182
+ RNFetchBlob . fs . createFile ( RNFetchBlob . fs . dirs . DocumentDir + '/' + mkdirParam , [ 102 , 111 , 111 ] , 'ascii' ) ;
183
+ }
184
+
185
+ const createFileBase64Call = ( ) => {
186
+ RNFetchBlob . fs . createFile ( RNFetchBlob . fs . dirs . DocumentDir + '/' + mkdirParam , 'Zm9v' , 'base64' ) ;
187
+ }
188
+
189
+ const createFileURICall = ( ) => {
190
+ RNFetchBlob . fs . createFile ( RNFetchBlob . fs . dirs . DocumentDir + '/' + mkdirParam , RNFetchBlob . fs . dirs . DocumentDir + '/' + mkdirURIParam , 'uri' ) ;
191
+ }
192
+
193
+ // readFile()
194
+ const readFileUTF8Call = ( ) => {
195
+ RNFetchBlob . fs . readFile ( RNFetchBlob . fs . dirs . DocumentDir + '/' + readParam , 'utf8' )
196
+ . then ( ( data ) => {
197
+ Alert . alert ( 'UTF8 result of ' + readParam , data ) ;
198
+ } ) ;
199
+ }
200
+
201
+ const readFileASCIICall = ( ) => {
202
+ RNFetchBlob . fs . readFile ( RNFetchBlob . fs . dirs . DocumentDir + '/' + readParam , 'ascii' )
203
+ . then ( ( data ) => {
204
+ Alert . alert ( 'UTF8 result of ' + readParam , data ) ;
205
+ } ) ;
206
+ }
207
+
208
+ const readFileBase64Call = ( ) => {
209
+ RNFetchBlob . fs . readFile ( RNFetchBlob . fs . dirs . DocumentDir + '/' + readParam , 'base64' )
210
+ . then ( ( data ) => {
211
+ Alert . alert ( 'UTF8 result of ' + readParam , data ) ;
212
+ } )
213
+ }
214
+
215
+ // hash()
216
+ const hashCall = ( ) => {
217
+ RNFetchBlob . fs . hash ( RNFetchBlob . fs . dirs . DocumentDir + '/' + hashPathParam , hashAlgValue )
218
+ . then ( ( hash ) => {
219
+ Alert . alert ( hashAlgValue , hash ) ;
220
+ } )
221
+ . catch ( ( err ) => {
222
+ console . log ( hashAlgValue + ': ' + err ) ;
223
+ } ) ;
224
+ }
225
+
121
226
// App ************************************************************************
122
227
return (
123
228
< >
@@ -262,7 +367,145 @@ const App: () => React$Node = () => {
262
367
onPress = { unlinkCall }
263
368
/>
264
369
</ View >
265
- </ View >
370
+ </ View >
371
+
372
+ < View style = { styles . body } >
373
+ < View style = { styles . sectionContainer } >
374
+ < Text style = { styles . sectionTitle } >
375
+ { "stat - stat(), lstat()" }
376
+ </ Text >
377
+ < View style = { styles . sectionDescription } >
378
+ < TextInput style = { styles . input }
379
+ placeholder = "Source path"
380
+ onChangeText = { statParam => setStatParam ( statParam ) }
381
+ placeholderTextColor = "#9a73ef"
382
+ autoCapitalize = "none"
383
+ />
384
+ </ View >
385
+ < Button
386
+ title = "stat Call"
387
+ color = "#9a73ef"
388
+ onPress = { statCall }
389
+ />
390
+ < Button
391
+ title = "lstat Call"
392
+ color = "#9a73ef"
393
+ onPress = { lstatCall }
394
+ />
395
+ </ View >
396
+ </ View >
397
+
398
+ < View style = { styles . body } >
399
+ < View style = { styles . sectionContainer } >
400
+ < Text style = { styles . sectionTitle } >
401
+ { "mkdir - mkdir(), createFile()" }
402
+ </ Text >
403
+ < View style = { styles . sectionDescription } >
404
+ < TextInput style = { styles . input }
405
+ placeholder = "Source path"
406
+ onChangeText = { mkdirParam => setMkdirParam ( mkdirParam ) }
407
+ placeholderTextColor = "#9a73ef"
408
+ autoCapitalize = "none"
409
+ />
410
+ < TextInput style = { styles . input }
411
+ placeholder = "URI source path"
412
+ onChangeText = { mkdirURIParam => setMkdirURIParam ( mkdirURIParam ) }
413
+ placeholderTextColor = "#9a73ef"
414
+ autoCapitalize = "none"
415
+ />
416
+ </ View >
417
+ < Button
418
+ title = "mkdir"
419
+ color = "#9a73ef"
420
+ onPress = { mkdirCall }
421
+ />
422
+ < Button
423
+ title = "Create UTF8 file"
424
+ color = "#9a73ef"
425
+ onPress = { createFileUTF8Call }
426
+ />
427
+ < Button
428
+ title = "Create ASCII file"
429
+ color = "#9a73ef"
430
+ onPress = { createFileASCIICall }
431
+ />
432
+ < Button
433
+ title = "Create base64 file"
434
+ color = "#9a73ef"
435
+ onPress = { createFileBase64Call }
436
+ />
437
+ < Button
438
+ title = "Create file from URI"
439
+ color = "#9a73ef"
440
+ onPress = { createFileURICall }
441
+ />
442
+ </ View >
443
+ </ View >
444
+
445
+ < View style = { styles . body } >
446
+ < View style = { styles . sectionContainer } >
447
+ < Text style = { styles . sectionTitle } >
448
+ { "readFile - readFile()" }
449
+ </ Text >
450
+ < View style = { styles . sectionDescription } >
451
+ < TextInput style = { styles . input }
452
+ placeholder = "Source path"
453
+ onChangeText = { readParam => setReadParam ( readParam ) }
454
+ placeholderTextColor = "#9a73ef"
455
+ autoCapitalize = "none"
456
+ />
457
+ </ View >
458
+ < Button
459
+ title = "Read UTF8 file"
460
+ color = "#9a73ef"
461
+ onPress = { readFileUTF8Call }
462
+ />
463
+ < Button
464
+ title = "Read ASCII file"
465
+ color = "#9a73ef"
466
+ onPress = { readFileASCIICall }
467
+ />
468
+ < Button
469
+ title = "Read base64 file"
470
+ color = "#9a73ef"
471
+ onPress = { readFileBase64Call }
472
+ />
473
+ </ View >
474
+ </ View >
475
+
476
+ < View style = { styles . body } >
477
+ < View style = { styles . sectionContainer } >
478
+ < Text style = { styles . sectionTitle } >
479
+ { "Hash - hash()" }
480
+ </ Text >
481
+ < View style = { styles . sectionDescription } >
482
+ < TextInput style = { styles . input }
483
+ placeholder = "Source path"
484
+ onChangeText = { hashPathParam => setHashPathParam ( hashPathParam ) }
485
+ placeholderTextColor = "#9a73ef"
486
+ autoCapitalize = "none"
487
+ />
488
+ < Picker
489
+ hashAlgValue = { hashAlgValue }
490
+ onChangeText = { readPositionParam => setReadPositionParam ( readPositionParam ) }
491
+ style = { { height : 50 , width : 150 } }
492
+ onValueChange = { ( itemValue , itemIndex ) => setHashAlgValue ( itemValue ) }
493
+ >
494
+ < Picker . Item label = "MD5" value = "md5" />
495
+ < Picker . Item label = "SHA1" value = "sha1" />
496
+ < Picker . Item label = "SHA224" value = "sha224" />
497
+ < Picker . Item label = "SHA256" value = "sha256" />
498
+ < Picker . Item label = "SHA384" value = "sha384" />
499
+ < Picker . Item label = "SHA512" value = "sha512" />
500
+ </ Picker >
501
+ </ View >
502
+ < Button
503
+ title = "Hash File"
504
+ color = "#9a73ef"
505
+ onPress = { hashCall }
506
+ />
507
+ </ View >
508
+ </ View >
266
509
267
510
</ ScrollView >
268
511
</ SafeAreaView >
0 commit comments