mobiletto 1.1.40 → 1.2.1

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
@@ -9,6 +9,7 @@ Mobiletto is a JavaScript storage abstraction layer, with optional transparent c
9
9
  * [Mobiletto CLI](#mobiletto-cli)
10
10
  * [Source](#Source)
11
11
  * [Installation](#Installation)
12
+ * [Minimal install](#Minimal-install)
12
13
  * [Support and Funding](#Support-and-Funding)
13
14
  * [Basic usage](#Basic-usage)
14
15
  * [Metadata](#Metadata)
@@ -91,9 +92,42 @@ Current Mobiletto storage drivers:
91
92
  * `s3`: Amazon S3
92
93
  * `b2`: Backblaze B2
93
94
  * `local`: local filesystem
95
+ * `indexeddb`: IndexedDB storage
94
96
 
95
97
  *Contributions to support more cloud storage providers are very welcome!*
96
98
 
99
+ ## Quick Start
100
+ A short example using the mobiletto `s3` driver.
101
+
102
+ This code would run the same with any other mobiletto storage driver.
103
+
104
+ const storage = require('mobiletto')
105
+ const bucket = await storage.connect('s3', aws_key, aws_secret, {bucket: 'bk'})
106
+
107
+ // list objects: returns array of metadata objects
108
+ const listing = await bucket.list()
109
+ const dirList = await bucket.list('some/dir/')
110
+ const everything = await bucket.list('', {recursive: true})
111
+
112
+ // write an entire file
113
+ let bytesWritten = await bucket.writeFile('some/path', someBufferOfData)
114
+
115
+ // write a file from a stream/generator
116
+ bytesWritten = await bucket.write('some/path', streamOrGenerator)
117
+
118
+ // read an entire file
119
+ // returns null if an exception would otherwise be thrown
120
+ const bufferOrNull = await bucket.safeReadFile('some/path')
121
+
122
+ // stream-read a file, passing data to callback
123
+ const bytesRead = await bucket.read('some/path', (chunk) => { ...do something with chunk... } )
124
+
125
+ // remove a file, returns the path removed
126
+ let removed = await bucket.remove('some/path') // removed is a string
127
+
128
+ // remove a directory, returns array of paths removed
129
+ removed = await bucket.remove('some/directory', {recursive: true}) // removed is now an array!
130
+
97
131
  ## mobiletto-cli
98
132
  Mobiletto is intended to be used as a library by other JavaScript code.
99
133
 
@@ -118,44 +152,44 @@ If you really want the README files in every language, install the full version:
118
152
  npm install mobiletto
119
153
  yarn add mobiletto
120
154
 
121
- ## Quick Start
122
- A short example using the mobiletto `s3` driver.
155
+ ### Minimal install
156
+ The `mobiletto` and `mobiletto-lite` packages include support for all mobiletto storage drivers.
123
157
 
124
- This code would run the same if the driver were `b2` or `local`.
158
+ If you know the storage driver(s) that you will need ahead of time, you can lighten your app's
159
+ footprint by installing the `mobiletto-base` package, and then one or more of the `mobiletto-driver-` packages:
125
160
 
126
- const storage = require('mobiletto')
127
- const bucket = await storage.connect('s3', aws_key, aws_secret, {bucket: 'bk'})
161
+ #### Minimal installation with npm
128
162
 
129
- // list objects: returns array of metadata objects
130
- const listing = await bucket.list()
131
- const dirList = await bucket.list('some/dir/')
132
- const everything = await bucket.list('', {recursive: true})
133
-
134
- // write an entire file
135
- let bytesWritten = await bucket.writeFile('some/path', someBufferOfData)
136
-
137
- // write a file from a stream/generator
138
- bytesWritten = await bucket.write('some/path', streamOrGenerator)
163
+ npm install mobiletto-base # install driver-less mobiletto
139
164
 
140
- // read an entire file
141
- // returns null if an exception would otherwise be thrown
142
- const bufferOrNull = await bucket.safeReadFile('some/path')
165
+ npm install mobiletto-driver-s3 # install Amazon S3 driver
166
+ npm install mobiletto-driver-b2 # install Backblaze B2 driver
167
+ npm install mobiletto-driver-local # install local filesystem driver
168
+ npm install mobiletto-driver-indexeddb # install IndexedDB driver
143
169
 
144
- // stream-read a file, passing data to callback
145
- const bytesRead = await bucket.read('some/path', (chunk) => { ...do something with chunk... } )
170
+ #### Minimal installation with yarn
146
171
 
147
- // remove a file, returns the path removed
148
- let removed = await bucket.remove('some/path') // removed is a string
172
+ yarn add mobiletto-base # install driver-less mobiletto
149
173
 
150
- // remove a directory, returns array of paths removed
151
- removed = await bucket.remove('some/directory', {recursive: true}) // removed is now an array!
174
+ yarn add mobiletto-driver-s3 # install Amazon S3 driver
175
+ yarn add mobiletto-driver-b2 # install Backblaze B2 driver
176
+ yarn add mobiletto-driver-local # install local filesystem driver
177
+ yarn add mobiletto-driver-indexeddb # install IndexedDB driver
152
178
 
153
179
  ----
154
180
  ## Basic usage
155
181
  A much more extensive example, showing most of the features offered:
156
182
 
183
+ // When using mobiletto or mobiletto-lite, all drivers are included
157
184
  const { mobiletto } = require('mobiletto')
158
185
 
186
+ // When using mobiletto-base, use registerDriver to load a storage driver before connecting
187
+ const { registerDriver, mobiletto } = = require('mobiletto-base')
188
+ registerDriver('s3', require('mobiletto-driver-s3'))
189
+ registerDriver('b2', require('mobiletto-driver-b2'))
190
+ registerDriver('local', require('mobiletto-driver-local'))
191
+ registerDriver('indexeddb', require('mobiletto-driver-indexeddb'))
192
+
159
193
  // General usage
160
194
  const api = await mobiletto(driverName, key, secret, opts)
161
195
 
@@ -190,6 +224,13 @@ A much more extensive example, showing most of the features offered:
190
224
  // * partSize: optional, large files will be split into chunks of this size when uploading
191
225
  const b3 = await mobiletto('b2', b2_key_id, b2_app_key, {bucket: 'bk', partSize: 10000000})
192
226
 
227
+ // To use 'indexeddb' driver:
228
+ // * key: IndexedDB database name
229
+ // * secret: ignored, can be null
230
+ // * opts object:
231
+ // * indexedDB: required, the indexedDB object (an instance of IDBFactory)
232
+ const idb = await mobiletto('indexeddb', 'my_db', null, { indexedDB })
233
+
193
234
  // List files
194
235
  api.list() // --> returns an array of metadata objects
195
236
 
@@ -431,11 +472,11 @@ The object that the storageClient function returns must define these functions:
431
472
  // Read metadata for a path
432
473
  async metadata (path)
433
474
 
434
- // Read a file
475
+ // Read a file, return bytes read
435
476
  // callback receives a chunk of data. endCallback is called at end-of-stream
436
477
  async read (path, callback, endCallback = null)
437
478
 
438
- // Write a file
479
+ // Write a file, return bytes written
439
480
  // driver must be able to handle a generator or a stream
440
481
  async write (path, generatorOrReadableStream)
441
482