mobiletto 1.0.23 → 1.0.26

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 CHANGED
@@ -12,27 +12,33 @@ 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
- A simple CRUD example using the mobiletto S3 driver.
20
+ A simple CRUD example using the mobiletto `s3` driver.
17
21
 
18
22
  This code would run the same if the driver were `local`.
19
23
 
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
@@ -63,7 +63,10 @@ class StorageClient {
63
63
  normalizePath = (path) => path.startsWith(this.baseDir)
64
64
  ? path
65
65
  : this.baseDir + (path.startsWith('/') ? path.substring(1) : path)
66
- denormalizePath = (path) => path.startsWith(this.baseDir) ? path.substring(this.baseDir.length) : path
66
+ denormalizePath = (path) => {
67
+ const norm = path.startsWith(this.baseDir) ? path.substring(this.baseDir.length) : path
68
+ return norm.startsWith('/') ? norm.substring(1) : norm
69
+ }
67
70
 
68
71
  fileToObject = (dir) => (f) => {
69
72
  const stat = fs.lstatSync(dir + '/' + f)
package/index.js CHANGED
@@ -66,7 +66,7 @@ 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
- if (results.cached) { return results }
69
+ if (Array.isArray(results)) { return results }
70
70
  throw results
71
71
  }
72
72
  }
@@ -78,7 +78,6 @@ const UTILITY_FUNCTIONS = {
78
78
  try {
79
79
  const results = await client.driver_list(path, recursive, visitor)
80
80
  if (client.listingCache) {
81
- results.cached = true
82
81
  client.listingCache.set(cacheKey, results)
83
82
  }
84
83
  return results
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mobiletto",
3
- "version": "1.0.23",
3
+ "version": "1.0.26",
4
4
  "description": "A storage abstraction layer",
5
5
  "main": "index.js",
6
6
  "author": "Jonathan Cobb",