mobiletto 1.0.15 → 1.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -1
- package/index.js +22 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ Mobiletto is a JavaScript storage abstraction layer, with optional transparent c
|
|
|
5
5
|
|
|
6
6
|
It supports apps that are agnostic to where files are stored.
|
|
7
7
|
|
|
8
|
-
All drivers are tested for identical behavior with over
|
|
8
|
+
All drivers are tested for identical behavior with over 40 tests for each driver.
|
|
9
9
|
|
|
10
10
|
Today the supported drivers are:
|
|
11
11
|
|
|
@@ -53,10 +53,18 @@ Today the supported drivers are:
|
|
|
53
53
|
// Visit files in a directory -- visitor function must be async
|
|
54
54
|
local.list(path, { visitor: myAsyncFunc })
|
|
55
55
|
s3.list(path, { visitor: myAsyncFunc, recursive: true })
|
|
56
|
+
|
|
57
|
+
// The `list` method throws MobilettoNotFoundError if the path does not exist
|
|
58
|
+
// When you call `safeList` on a non-existent path, it returns an empty array
|
|
59
|
+
s3.safeList('/path/that/does/not/exist') // returns []
|
|
56
60
|
|
|
57
61
|
// Read metadata for a file
|
|
58
62
|
local.metadata(path)
|
|
59
63
|
s3.metadata(path)
|
|
64
|
+
|
|
65
|
+
// The `metadata` method throws MobilettoNotFoundError if the path does not exist
|
|
66
|
+
// When you call `safeMetadata` on a non-existent path, it returns null
|
|
67
|
+
local.safeMetadata('/tmp/does_not_exist') // returns null
|
|
60
68
|
|
|
61
69
|
// Read a file
|
|
62
70
|
// Provide a callback that writes the data someplace
|
package/index.js
CHANGED
|
@@ -67,6 +67,28 @@ const UTILITY_FUNCTIONS = {
|
|
|
67
67
|
}
|
|
68
68
|
return await client.driver_list(path, recursive, visitor)
|
|
69
69
|
},
|
|
70
|
+
safeList: (client) => async (path, opts) => {
|
|
71
|
+
const recursive = opts && opts.recursive ? opts.recursive : false
|
|
72
|
+
const visitor = opts && opts.visitor ? opts.visitor : null
|
|
73
|
+
try {
|
|
74
|
+
return await client.driver_list(path, recursive, visitor)
|
|
75
|
+
} catch (e) {
|
|
76
|
+
if (e instanceof MobilettoNotFoundError) {
|
|
77
|
+
return []
|
|
78
|
+
}
|
|
79
|
+
throw e
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
safeMetadata: (client) => async (path) => {
|
|
83
|
+
try {
|
|
84
|
+
return await client.metadata(path)
|
|
85
|
+
} catch (e) {
|
|
86
|
+
if (e instanceof MobilettoNotFoundError) {
|
|
87
|
+
return null
|
|
88
|
+
}
|
|
89
|
+
throw e
|
|
90
|
+
}
|
|
91
|
+
},
|
|
70
92
|
remove: (client) => async (path, opts) => {
|
|
71
93
|
const recursive = opts && opts.recursive ? opts.recursive : false
|
|
72
94
|
const quiet = opts && opts.quiet ? opts.quiet : false
|