mobiletto 1.1.4 → 1.1.7

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.
Files changed (3) hide show
  1. package/README.md +17 -14
  2. package/index.js +11 -3
  3. 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 simple example using the mobiletto `s3` driver.
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 s3 = await storage.connect('s3', aws_key, aws_secret, {bucket: 'bk'})
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 s3.list()
70
- const dirList = await s3.list('some/dir/')
71
- const everything = await s3.list('', {recursive: true})
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 s3.writeFile('some/path', someBufferOfData)
74
+ let bytesWritten = await bucket.writeFile('some/path', someBufferOfData)
75
75
 
76
76
  // write a file from a stream/generator
77
- bytesWritten = await s3.write('some/path', streamOrGenerator)
77
+ bytesWritten = await bucket.write('some/path', streamOrGenerator)
78
78
 
79
79
  // read an entire file in one-shot
80
- const byteBuffer = await s3.readFile('some/path')
80
+ // returns null if an exception would otherwise be thrown
81
+ const bufferOrNull = await bucket.safeReadFile('some/path')
81
82
 
82
- // read file as a stream using data callback
83
- const bytesRead = await s3.read('some/path', (chunk) => { ...do something with chunk... } )
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 s3.remove('some/path')
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 s3.remove('some/directory', {recursive: true})
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 access key
109
- // * secret: AWS secret key
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
@@ -37,8 +37,8 @@ function MobilettoError (message, err) {
37
37
  // noinspection JSUnusedGlobalSymbols
38
38
  this.stack = (new Error(this.message)).stack
39
39
  }
40
+ MobilettoError.prototype.toString = () => JSON.stringify(this)
40
41
  }
41
- MobilettoError.prototype.toString = () => JSON.stringify(this)
42
42
 
43
43
  // adapted from https://stackoverflow.com/a/27724419
44
44
  function MobilettoNotFoundError (message) {
@@ -50,8 +50,8 @@ function MobilettoNotFoundError (message) {
50
50
  // noinspection JSUnusedGlobalSymbols
51
51
  this.stack = (new Error(this.message)).stack
52
52
  }
53
+ MobilettoNotFoundError.prototype.toString = () => JSON.stringify(this)
53
54
  }
54
- MobilettoNotFoundError.prototype.toString = () => JSON.stringify(this)
55
55
 
56
56
  const reader = (chunks) => (chunk) => { if (chunk) { chunks.push(chunk) } }
57
57
 
@@ -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
@@ -576,7 +584,7 @@ async function mobiletto (driverPath, key, secret, opts, encryption = null) {
576
584
  throw new MobilettoError('write: error writing dirent file')
577
585
  }
578
586
  p = dirname(p)
579
- if (p === '.' || p === '') {
587
+ if (p === '.' || p === '' || p === '/') {
580
588
  break
581
589
  }
582
590
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mobiletto",
3
- "version": "1.1.4",
3
+ "version": "1.1.7",
4
4
  "description": "A storage layer that presents a uniform interface to Amazon S3, Backblaze B2, and local storage",
5
5
  "main": "index.js",
6
6
  "keywords": [