Browse Source

Change fs interface

Ben Hsieh 8 years ago
parent
commit
83525f1673
2 changed files with 10 additions and 41 deletions
  1. 10
    40
      src/fs.js
  2. 0
    1
      src/index.js

+ 10
- 40
src/fs.js View File

22
 
22
 
23
 const RNFetchBlob:RNFetchBlobNative = NativeModules.RNFetchBlob
23
 const RNFetchBlob:RNFetchBlobNative = NativeModules.RNFetchBlob
24
 const emitter = DeviceEventEmitter
24
 const emitter = DeviceEventEmitter
25
-
26
-// session table
27
-let sessions = {}
28
-
29
-/**
30
- * Get path of system directories.
31
- * @return {object} Map contains DocumentDir, CacheDir, DCIMDir, DownloadDir,
32
- * , some directory might not be supported by platform.
33
- */
34
-function getSystemDirs() {
35
-  return new Promise((resolve, reject) => {
36
-    try {
37
-      RNFetchBlob.getEnvironmentDirs((...dirs) => {
38
-        let [
39
-          DocumentDir,
40
-          CacheDir,
41
-          // Android only
42
-          DCIMDir,
43
-          DownloadDir,
44
-          PictureDir,
45
-          MusicDir,
46
-          MovieDir,
47
-          RingToneDir] = [...dirs]
48
-        resolve({
49
-          DocumentDir,
50
-          CacheDir,
51
-          DCIMDir,
52
-          DownloadDir,
53
-          PictureDir,
54
-          MusicDir,
55
-          MovieDir,
56
-          RingToneDir
57
-        })
58
-      })
59
-    } catch(err) {
60
-      reject(err)
61
-    }
62
-  })
25
+const dirs = {
26
+    DocumentDir :  RNFetchBlob.DocumentDir,
27
+    CacheDir : RNFetchBlob.CacheDir,
28
+    PictureDir : RNFetchBlob.PictureDir,
29
+    MusicDir : RNFetchBlob.MusicDir,
30
+    MovieDir : RNFetchBlob.MovieDir,
31
+    DownloadDir : RNFetchBlob.DownloadDir,
32
+    DCIMDir : RNFetchBlob.DCIMDir
63
 }
33
 }
64
 
34
 
65
 /**
35
 /**
289
   session,
259
   session,
290
   ls,
260
   ls,
291
   readStream,
261
   readStream,
292
-  getSystemDirs,
293
   mv,
262
   mv,
294
   cp,
263
   cp,
295
   writeStream,
264
   writeStream,
298
   isDir,
267
   isDir,
299
   stat,
268
   stat,
300
   lstat,
269
   lstat,
301
-  scanFile
270
+  scanFile,
271
+  dirs
302
 }
272
 }

+ 0
- 1
src/index.js View File

21
 import base64 from 'base-64'
21
 import base64 from 'base-64'
22
 const {
22
 const {
23
   RNFetchBlobSession,
23
   RNFetchBlobSession,
24
-  getSystemDirs,
25
   readStream,
24
   readStream,
26
   createFile,
25
   createFile,
27
   unlink,
26
   unlink,