mobiletto 1.1.4 → 1.1.5
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 +17 -14
- package/index.js +8 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -58,38 +58,41 @@ To work with mobiletto at the command-line, use [mobiletto-cli](https://www.npmj
|
|
|
58
58
|
* [mobiletto on npm](https://www.npmjs.com/package/mobiletto)
|
|
59
59
|
|
|
60
60
|
## Quick Start
|
|
61
|
-
A
|
|
61
|
+
A short example using the mobiletto `s3` driver.
|
|
62
62
|
|
|
63
63
|
This code would run the same if the driver were `b2` or `local`.
|
|
64
64
|
|
|
65
65
|
const storage = require('mobiletto')
|
|
66
|
-
const
|
|
66
|
+
const bucket = await storage.connect('s3', aws_key, aws_secret, {bucket: 'bk'})
|
|
67
67
|
|
|
68
68
|
// list objects: returns array of metadata objects
|
|
69
|
-
const listing = await
|
|
70
|
-
const dirList = await
|
|
71
|
-
const everything = await
|
|
69
|
+
const listing = await bucket.list()
|
|
70
|
+
const dirList = await bucket.list('some/dir/')
|
|
71
|
+
const everything = await bucket.list('', {recursive: true})
|
|
72
72
|
|
|
73
73
|
// write an entire file in one-shot
|
|
74
|
-
let bytesWritten = await
|
|
74
|
+
let bytesWritten = await bucket.writeFile('some/path', someBufferOfData)
|
|
75
75
|
|
|
76
76
|
// write a file from a stream/generator
|
|
77
|
-
bytesWritten = await
|
|
77
|
+
bytesWritten = await bucket.write('some/path', streamOrGenerator)
|
|
78
78
|
|
|
79
79
|
// read an entire file in one-shot
|
|
80
|
-
|
|
80
|
+
// returns null if an exception would otherwise be thrown
|
|
81
|
+
const bufferOrNull = await bucket.safeReadFile('some/path')
|
|
81
82
|
|
|
82
|
-
// read
|
|
83
|
-
const bytesRead = await
|
|
83
|
+
// stream-read a file, passing data to callback
|
|
84
|
+
const bytesRead = await bucket.read('some/path', (chunk) => { ...do something with chunk... } )
|
|
84
85
|
|
|
85
86
|
// remove a file, returns the path removed
|
|
86
|
-
let removed = await
|
|
87
|
+
let removed = await bucket.remove('some/path') // removed is a string
|
|
87
88
|
|
|
88
89
|
// remove a directory, returns array of paths removed
|
|
89
|
-
removed = await
|
|
90
|
+
removed = await bucket.remove('some/directory', {recursive: true}) // removed is now an array!
|
|
90
91
|
|
|
91
92
|
----
|
|
92
93
|
## Basic usage
|
|
94
|
+
A much more extensive example, showing most of the features offered:
|
|
95
|
+
|
|
93
96
|
const { mobiletto } = require('mobiletto')
|
|
94
97
|
|
|
95
98
|
// General usage
|
|
@@ -105,8 +108,8 @@ This code would run the same if the driver were `b2` or `local`.
|
|
|
105
108
|
const local = await mobiletto('local', '/home/ubuntu/tmp', null, {fileMode: 0o0600, dirMode: '0700'})
|
|
106
109
|
|
|
107
110
|
// To use 's3' driver:
|
|
108
|
-
// * key: AWS
|
|
109
|
-
// * secret: AWS
|
|
111
|
+
// * key: AWS Access Key ID
|
|
112
|
+
// * secret: AWS Secret Key
|
|
110
113
|
// * opts object:
|
|
111
114
|
// * readOnly: optional, never change anything on the bucket; default is false
|
|
112
115
|
// * bucket: required, name of the S3 bucket
|
package/index.js
CHANGED
|
@@ -199,6 +199,14 @@ const UTILITY_FUNCTIONS = {
|
|
|
199
199
|
}
|
|
200
200
|
return data
|
|
201
201
|
},
|
|
202
|
+
safeReadFile: (client) => async (path) => {
|
|
203
|
+
try {
|
|
204
|
+
return await client.readFile(path)
|
|
205
|
+
} catch (e) {
|
|
206
|
+
logger.info(`safeReadFile(${path}): ${e}`)
|
|
207
|
+
return null
|
|
208
|
+
}
|
|
209
|
+
},
|
|
202
210
|
write: (client) => async (path, data) => {
|
|
203
211
|
logger.debug(`util.write(${path}) starting ...`)
|
|
204
212
|
// noinspection JSUnresolvedFunction
|