mobiletto 1.0.22 → 1.0.25

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 +12 -6
  2. package/index.js +13 -5
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -12,6 +12,10 @@ Today the supported drivers are:
12
12
  * `s3`: read/write an Amazon S3 bucket
13
13
  * `local`: read/write to local filesystem
14
14
 
15
+ ### Source
16
+ * [Mobiletto on GitHub](https://github.com/cobbzilla/mobiletto)
17
+ * [Mobiletto on npm](https://www.npmjs.com/package/mobiletto)
18
+
15
19
  ## TLDR
16
20
  A simple CRUD example using the mobiletto S3 driver.
17
21
 
@@ -20,19 +24,21 @@ This code would run the same if the driver were `local`.
20
24
  const storage = require('mobiletto')
21
25
  const s3 = await storage.connect('s3', aws_key, aws_secret, {bucket: 'bk', region: 'us-east-1', cacheSize: 100})
22
26
 
23
- // returns array of metadata objects
27
+ // list objects: returns array of metadata objects
24
28
  const listing = await s3.list()
29
+ const dirList = await s3.list('some/dir/')
30
+ const everything = await s3.list('', {recursive: true})
25
31
 
26
32
  // write an entire file in one-shot
27
- await s3.writeFile('some/path', someBufferOfData)
33
+ let bytesWritten = await s3.writeFile('some/path', someBufferOfData)
28
34
 
29
- // write a stream
30
- const bytesWritten = await s3.write('some/path', streamOrGenerator)
35
+ // write a file from a stream/generator
36
+ bytesWritten = await s3.write('some/path', streamOrGenerator)
31
37
 
32
38
  // read an entire file in one-shot
33
- const objectData = await s3.readFile('some/path')
39
+ const byteBuffer = await s3.readFile('some/path')
34
40
 
35
- // read a stream
41
+ // read file as a stream using data callback
36
42
  const bytesRead = await s3.read('some/path', (chunk) => { ...do something with chunk... } )
37
43
 
38
44
  // remove a file, returns true upon success
package/index.js CHANGED
@@ -66,7 +66,8 @@ const UTILITY_FUNCTIONS = {
66
66
  cacheKey = shasum(path + ' ' + (opts ? JSON.stringify(opts) : '~'))
67
67
  const results = client.listingCache.get(cacheKey)
68
68
  if (results) {
69
- return results
69
+ if (Array.isArray(results)) { return results }
70
+ throw results
70
71
  }
71
72
  }
72
73
  const recursive = opts && opts.recursive ? opts.recursive : false
@@ -74,11 +75,18 @@ const UTILITY_FUNCTIONS = {
74
75
  if (visitor && typeof visitor !== 'function') {
75
76
  throw new MobilettoError(`list: visitor is not a function: ${typeof visitor}`)
76
77
  }
77
- const results = await client.driver_list(path, recursive, visitor)
78
- if (client.listingCache) {
79
- client.listingCache.set(cacheKey, results)
78
+ try {
79
+ const results = await client.driver_list(path, recursive, visitor)
80
+ if (client.listingCache) {
81
+ client.listingCache.set(cacheKey, results)
82
+ }
83
+ return results
84
+ } catch (e) {
85
+ if (client.listingCache && e instanceof MobilettoNotFoundError) {
86
+ client.listingCache.set(cacheKey, e)
87
+ }
88
+ throw e
80
89
  }
81
- return results
82
90
  },
83
91
  safeList: (client) => async (path, opts) => {
84
92
  const recursive = opts && opts.recursive ? opts.recursive : false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mobiletto",
3
- "version": "1.0.22",
3
+ "version": "1.0.25",
4
4
  "description": "A storage abstraction layer",
5
5
  "main": "index.js",
6
6
  "author": "Jonathan Cobb",