mobiletto 1.1.8 → 1.1.11

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 (117) hide show
  1. package/README.md +56 -4
  2. package/docs/README.md +113 -0
  3. package/docs/af/README.md +455 -0
  4. package/docs/am/README.md +455 -0
  5. package/docs/ar/README.md +455 -0
  6. package/docs/az/README.md +455 -0
  7. package/docs/be/README.md +455 -0
  8. package/docs/bg/README.md +455 -0
  9. package/docs/bn/README.md +455 -0
  10. package/docs/bs/README.md +455 -0
  11. package/docs/ca/README.md +455 -0
  12. package/docs/ceb/README.md +455 -0
  13. package/docs/co/README.md +455 -0
  14. package/docs/cs/README.md +455 -0
  15. package/docs/cy/README.md +455 -0
  16. package/docs/da/README.md +455 -0
  17. package/docs/de/README.md +455 -0
  18. package/docs/el/README.md +455 -0
  19. package/docs/eo/README.md +455 -0
  20. package/docs/es/README.md +455 -0
  21. package/docs/et/README.md +455 -0
  22. package/docs/eu/README.md +455 -0
  23. package/docs/fa/README.md +455 -0
  24. package/docs/fi/README.md +455 -0
  25. package/docs/fr/README.md +455 -0
  26. package/docs/fy/README.md +455 -0
  27. package/docs/ga/README.md +455 -0
  28. package/docs/gd/README.md +455 -0
  29. package/docs/gl/README.md +455 -0
  30. package/docs/gu/README.md +455 -0
  31. package/docs/ha/README.md +455 -0
  32. package/docs/haw/README.md +455 -0
  33. package/docs/he/README.md +455 -0
  34. package/docs/hi/README.md +455 -0
  35. package/docs/hmn/README.md +455 -0
  36. package/docs/hr/README.md +455 -0
  37. package/docs/ht/README.md +455 -0
  38. package/docs/hu/README.md +455 -0
  39. package/docs/hy/README.md +455 -0
  40. package/docs/id/README.md +455 -0
  41. package/docs/ig/README.md +455 -0
  42. package/docs/is/README.md +455 -0
  43. package/docs/it/README.md +455 -0
  44. package/docs/iw/README.md +455 -0
  45. package/docs/ja/README.md +455 -0
  46. package/docs/jv/README.md +455 -0
  47. package/docs/ka/README.md +455 -0
  48. package/docs/kk/README.md +455 -0
  49. package/docs/km/README.md +455 -0
  50. package/docs/kn/README.md +455 -0
  51. package/docs/ko/README.md +455 -0
  52. package/docs/ku/README.md +455 -0
  53. package/docs/ky/README.md +455 -0
  54. package/docs/la/README.md +455 -0
  55. package/docs/lb/README.md +455 -0
  56. package/docs/lo/README.md +455 -0
  57. package/docs/lt/README.md +455 -0
  58. package/docs/lv/README.md +455 -0
  59. package/docs/mg/README.md +455 -0
  60. package/docs/mi/README.md +455 -0
  61. package/docs/mk/README.md +455 -0
  62. package/docs/ml/README.md +455 -0
  63. package/docs/mn/README.md +455 -0
  64. package/docs/mr/README.md +455 -0
  65. package/docs/ms/README.md +455 -0
  66. package/docs/mt/README.md +455 -0
  67. package/docs/my/README.md +455 -0
  68. package/docs/ne/README.md +455 -0
  69. package/docs/nl/README.md +455 -0
  70. package/docs/no/README.md +455 -0
  71. package/docs/ny/README.md +455 -0
  72. package/docs/or/README.md +455 -0
  73. package/docs/pa/README.md +455 -0
  74. package/docs/pl/README.md +455 -0
  75. package/docs/ps/README.md +455 -0
  76. package/docs/pt/README.md +455 -0
  77. package/docs/ro/README.md +455 -0
  78. package/docs/ru/README.md +455 -0
  79. package/docs/rw/README.md +455 -0
  80. package/docs/sd/README.md +455 -0
  81. package/docs/si/README.md +455 -0
  82. package/docs/sk/README.md +455 -0
  83. package/docs/sl/README.md +455 -0
  84. package/docs/sm/README.md +455 -0
  85. package/docs/sn/README.md +455 -0
  86. package/docs/so/README.md +455 -0
  87. package/docs/sq/README.md +455 -0
  88. package/docs/sr/README.md +455 -0
  89. package/docs/st/README.md +455 -0
  90. package/docs/su/README.md +455 -0
  91. package/docs/sv/README.md +455 -0
  92. package/docs/sw/README.md +455 -0
  93. package/docs/ta/README.md +455 -0
  94. package/docs/te/README.md +455 -0
  95. package/docs/tg/README.md +455 -0
  96. package/docs/th/README.md +455 -0
  97. package/docs/tk/README.md +455 -0
  98. package/docs/tl/README.md +455 -0
  99. package/docs/tr/README.md +455 -0
  100. package/docs/tt/README.md +455 -0
  101. package/docs/ug/README.md +455 -0
  102. package/docs/uk/README.md +455 -0
  103. package/docs/ur/README.md +455 -0
  104. package/docs/uz/README.md +455 -0
  105. package/docs/vi/README.md +455 -0
  106. package/docs/xh/README.md +455 -0
  107. package/docs/yi/README.md +455 -0
  108. package/docs/yo/README.md +455 -0
  109. package/docs/zh/README.md +455 -0
  110. package/docs/zu/README.md +455 -0
  111. package/drivers/b2/index.js +24 -6
  112. package/hokey.json +16 -0
  113. package/index.js +33 -17
  114. package/package.json +3 -2
  115. package/test/api.spec.js +319 -306
  116. package/util/logger.js +1 -1
  117. package/util/redis.js +1 -1
@@ -0,0 +1,455 @@
1
+ Mobiletto
2
+ =========
3
+
4
+ Mobiletto yog ib txheej JavaScript cia abstraction txheej, nrog kev xaiv pob tshab tus neeg siv sab encryption.
5
+
6
+ # Cov ntsiab lus
7
+ * [Vim li cas Mobiletto?](#Why-Mobiletto?)
8
+ * [Quick start](#Quick-start)
9
+ * [Mobiletto CLI](#mobiletto-cli)
10
+ * [Source](#Source)
11
+ * [Basic siv](#Basic-siv)
12
+ * [Metadata](#Metadata)
13
+ * [Lwm hom ntshuam](#Alternate-import-style)
14
+ * [Caching](#Caching)
15
+ * [Daim iav](# Mirroring)
16
+ * [Transparent encryption](#Transparent-encryption)
17
+ * [Key rotation](#Key-rotation)
18
+ * [Driver interface](#Driver-interface)
19
+ * [Logging](#Logging)
20
+
21
+ # Nyeem qhov no ua lwm hom lus
22
+ Cov ntaub ntawv README.md no tau raug muab txhais, ntawm [hokeylization](https://github.com/cobbzilla/hokeylization), rau hauv
23
+ **[txhua hom lus txhawb nqa los ntawm Google Txhais](https://cloud.google.com/translate/docs/languages)!**
24
+
25
+ Kuv paub tseeb tias nws tsis zoo tag nrho, tab sis kuv vam tias nws zoo dua tsis muaj dab tsi!
26
+
27
+ [🇸🇦 Arabic](../ar/README.md)
28
+ [🇧🇩 Bengali](../bn/README.md)
29
+ [🇩🇪 German](../de/README.md)
30
+ [🇺🇸 English](../en/README.md)
31
+ [🇪🇸 Spanish](../es/README.md)
32
+ [🇫🇷 Fab Kis](../fr/README.md)
33
+ [🇹🇩 Hausa](../ha/README.md)
34
+ [🇮🇳 Hindi](../hi/README.md)
35
+ [🇮🇩 Indonesian](../id/README.md)
36
+ [🇮🇹 Italian](../it/README.md)
37
+ [🇯🇵 Nyiv](../ja/README.md)
38
+ [🇰🇷 Korean](../ko/README.md)
39
+ [🇮🇳 Maranthi](../mr/README.md)
40
+ [🇵🇱 Polish](../pl/README.md)
41
+ [🇧🇷 Portuguese](../pt/README.md)
42
+ [🇷🇺 Russian](../ru/README.md)
43
+ [🇰🇪 Swahili](../sw/README.md)
44
+ [🇵🇭 Tagalog](../tl/README.md)
45
+ [🇹🇷 Turkish](../tr/README.md)
46
+ [🇵🇰 Urdu](../ur/README.md)
47
+ [🇻🇳 Nyab Laj](../vi/README.md)
48
+ [🇨🇳 Suav](../zh/README.md)
49
+
50
+
51
+ **[📚...Txhua Yam Lus...](../README.md)**
52
+ ----
53
+
54
+ ### Puas muaj teeb meem nrog qhov kev txhais lus ntawm README?
55
+ Qhov kev txhais lus tshwj xeeb ntawm tus thawj [README](https://github.com/cobbzilla/mobiletto/blob/master/README.md)
56
+ tej zaum yuav muaj qhov tsis txaus ntseeg -- * kho tau zoo siab txais tos!* Thov xa [rub thov ntawm GitHub](https://github.com/cobbzilla/mobiletto/pulls),
57
+ lossis yog tias koj tsis xis nyob ua qhov ntawd, [qhib qhov teeb meem](https://github.com/cobbzilla/mobiletto/issues)
58
+
59
+ Thaum koj tsim qhov teeb meem tshiab GitHub txog kev txhais lus, thov ua:
60
+ * suav nrog nplooj URL (copy / paste los ntawm browser chaw nyob bar)
61
+ * suav nrog cov ntawv tseeb uas tsis yog (copy / paste los ntawm browser)
62
+ * thov piav qhia qhov tsis raug - puas yog kev txhais lus tsis raug? yog formatting puas lawm?
63
+ * Ua siab zoo muab cov lus pom zoo ntawm kev txhais lus zoo dua, lossis yuav ua li cas cov ntawv yuav tsum raug formatted kom raug
64
+ ** Ua tsaug!**
65
+
66
+ ## Vim li cas Mobiletto?
67
+
68
+ ### Goodbye vendor lock-in!
69
+ Cov chaw muab huab cia ntau yam muaj qhov tsis sib xws APIs. Txawm tias cov uas siv zog rau "S3 compatibility"
70
+ muaj tus cwj pwm idiosyncratic.
71
+
72
+ Thaum koj xaiv ib lub chaw muag khoom tshwj xeeb rau koj lub app, yog tias koj code ncaj qha rau lawv API, koj lub app
73
+ tam sim no nyob ntawm qhov kev pabcuam ntawd. Raws li lub sij hawm dhau mus thiab code accumulates, hloov cov neeg muag khoom ua
74
+ nce untenable. Txais tos rau lub ntiaj teb kev lom zem ntawm tus neeg muag khoom xauv-hauv!
75
+
76
+ Mobiletto tau tsim los daws qhov teeb meem no. Los ntawm coding koj app rau mobiletto's API, koj tuaj yeem yooj yim
77
+ hloov chaw khaws cia thiab paub tias koj lub app cov txheej txheem cia yuav coj zoo ib yam.
78
+
79
+ ### Kev sim dav dav
80
+ Txhua tus tsav tsheb raug sim rau tus cwj pwm zoo ib yam nrog 60+ kev xeem rau txhua tus tsav tsheb.
81
+ Peb sim txhua tus tsav tsheb nrog txhua qhov sib xyaw ua ke ntawm:
82
+ * Encryption: ob qho tib si qhib thiab ua tsis taus
83
+ * Redis cache: ob qho tib si qhib thiab ua tsis taus
84
+
85
+ Txoj hauv kev no ua rau peb muaj kev thaj yeeb nyab xeeb uas mobiletto yuav coj zoo ib yam tsis hais tus tsav tsheb twg koj siv,
86
+ thiab tsis hais seb koj puas qhib caching thiab / lossis encryption.
87
+
88
+ ### Kev them nyiaj yug tsav tsheb
89
+ Tam sim no Mobiletto cia tsav tsheb:
90
+ * `s3` : Amazon S3
91
+ * `b2` : Backblaze B2
92
+ * `local` : local filesystem
93
+
94
+ * Kev koom tes los txhawb ntau cov chaw muab huab cia tau txais tos heev!*
95
+
96
+ ## mobiletto-cli
97
+ Mobiletto yog npaj los siv los ua ib lub tsev qiv ntawv los ntawm lwm yam JavaScript code.
98
+
99
+ Txhawm rau ua haujlwm nrog mobiletto ntawm kab hais kom ua, siv [mobiletto-cli](https://www.npmjs.com/package/mobiletto-cli)
100
+
101
+ ## Source
102
+ * [mobiletto ntawm GitHub](https://github.com/cobbzilla/mobiletto)
103
+ * [mobiletto on npm](https://www.npmjs.com/package/mobiletto)
104
+
105
+ ## Quick Start
106
+ Piv txwv luv luv siv mobiletto `s3` tsav tsheb.
107
+
108
+ Cov cai no yuav khiav zoo ib yam yog tias tus tsav tsheb yog `b2` lossis `local` .
109
+
110
+ const storage = require('mobiletto')
111
+ const bucket = await storage.connect('s3', aws_key, aws_secret, {bucket: 'bk'})
112
+
113
+ // list objects: returns array of metadata objects
114
+ const listing = await bucket.list()
115
+ const dirList = await bucket.list('some/dir/')
116
+ const everything = await bucket.list('', {recursive: true})
117
+
118
+ // write an entire file
119
+ let bytesWritten = await bucket.writeFile('some/path', someBufferOfData)
120
+
121
+ // write a file from a stream/generator
122
+ bytesWritten = await bucket.write('some/path', streamOrGenerator)
123
+
124
+ // read an entire file
125
+ // returns null if an exception would otherwise be thrown
126
+ const bufferOrNull = await bucket.safeReadFile('some/path')
127
+
128
+ // stream-read a file, passing data to callback
129
+ const bytesRead = await bucket.read('some/path', (chunk) => { ...do something with chunk... } )
130
+
131
+ // remove a file, returns the path removed
132
+ let removed = await bucket.remove('some/path') // removed is a string
133
+
134
+ // remove a directory, returns array of paths removed
135
+ removed = await bucket.remove('some/directory', {recursive: true}) // removed is now an array!
136
+
137
+ ----
138
+ ## Kev siv yooj yim
139
+ Ib qho piv txwv ntau dua, qhia txog feem ntau ntawm cov yam ntxwv muaj:
140
+
141
+ const { mobiletto } = require('mobiletto')
142
+
143
+ // General usage
144
+ const api = await mobiletto(driverName, key, secret, opts)
145
+
146
+ // To use 'local' driver:
147
+ // * key: base directory
148
+ // * secret: ignored, can be null
149
+ // * opts object:
150
+ // * readOnly: optional, never change anything on the filesystem; default is false
151
+ // * fileMode: optional, permissions used when creating new files, default is 0600. can be string or integer
152
+ // * dirMode: optional, permissions used when creating new directories, default is 0700. can be string or integer
153
+ const local = await mobiletto('local', '/home/ubuntu/tmp', null, {fileMode: 0o0600, dirMode: '0700'})
154
+
155
+ // To use 's3' driver:
156
+ // * key: AWS Access Key ID
157
+ // * secret: AWS Secret Key
158
+ // * opts object:
159
+ // * readOnly: optional, never change anything on the bucket; default is false
160
+ // * bucket: required, name of the S3 bucket
161
+ // * region: optional, the AWS region to communicate with, default is us-east-1
162
+ // * prefix: optional, all read/writes within the S3 bucket will be under this prefix
163
+ // * delimiter: optional, directory delimiter, default is '/' (note: always '/' when encryption is enabled)
164
+ const s3 = await mobiletto('s3', aws_key, aws_secret, {bucket: 'bk', region: 'us-east-1'})
165
+
166
+ // To use 'b2' driver:
167
+ // * key: Backblaze Key ID
168
+ // * secret: Backblaze Application Key
169
+ // * opts object:
170
+ // * readOnly: optional, never change anything on the bucket; default is false
171
+ // * bucket: required, the ID (**not the name**) of the B2 bucket
172
+ // * prefix: optional, all read/writes within the B2 bucket will be under this prefix
173
+ // * delimiter: optional, directory delimiter, default is '/' (note: always '/' when encryption is enabled)
174
+ // * partSize: optional, large files will be split into chunks of this size when uploading
175
+ const b3 = await mobiletto('b2', b2_key_id, b2_app_key, {bucket: 'bk', partSize: 10000000})
176
+
177
+ // List files
178
+ api.list() // --> returns an array of metadata objects
179
+
180
+ // List files recursively
181
+ api.list({ recursive: true })
182
+
183
+ // List files in a directory
184
+ const path = 'some/path'
185
+ api.list(path)
186
+ api.list(path, { recursive: true }) // also supports recursive flag
187
+
188
+ // Visit files in a directory -- visitor function must be async
189
+ api.list(path, { visitor: myAsyncFunc })
190
+ api.list(path, { visitor: myAsyncFunc, recursive: true })
191
+
192
+ // The `list` method throws MobilettoNotFoundError if the path does not exist
193
+ // When you call `safeList` on a non-existent path, it returns an empty array
194
+ api.safeList('/path/that/does/not/exist') // returns []
195
+
196
+ // Read metadata for a file
197
+ api.metadata(path) // returns metadata object
198
+
199
+ // The `metadata` method throws MobilettoNotFoundError if the path does not exist
200
+ // When you call `safeMetadata` on a non-existent path, it returns null
201
+ api.safeMetadata('/tmp/does_not_exist') // returns null
202
+
203
+ // Read a file
204
+ // Provide a callback that writes the data someplace
205
+ const callback = (chunk) => { ... write chunk somewhere ... }
206
+ api.read(path, callback) // returns count of bytes read
207
+
208
+ // Read an entire file at once
209
+ const data = await api.readFile(path) // returns a byte Buffer of the file contents
210
+
211
+ // Read an entire file at once
212
+ // returns null if an exception would otherwise be thrown
213
+ const bufferOrNull = await bucket.safeReadFile('some/path')
214
+
215
+ // Write a file
216
+ // Provide a generator function that yields chunks of data
217
+ const generator = function* () {
218
+ while ( ... more-data-to-return ... ) {
219
+ data = ... load-data ...
220
+ yield data
221
+ }
222
+ }
223
+ local.api(path, generator) // returns count of bytes written
224
+
225
+ // Write an entire file at once (convenience method)
226
+ await api.writeFile(path, bufferOrString) // returns count of bytes written
227
+
228
+ // Delete a file
229
+ // Quiet param is optional (default false), when set errors will not be thrown if the path does not exist
230
+ // Always returns a value or throws an error.
231
+ // Return value may be a single string of the file removed, or an array of all files removed (driver-dependent)
232
+ const quiet = true
233
+ api.remove(path, {quiet}) // returns single path removed
234
+
235
+ // Recursively delete a directory and do it quietly (do not report errors)
236
+ const recursive = true
237
+ const quiet = true
238
+ api.remove(path, {recursive, quiet}) // returns array of paths removed
239
+
240
+ ## Metadata
241
+ Cov lus txib `metadata` rov qab metadata txog ib qho kev nkag mus rau hauv ib qho chaw.
242
+ Ib yam li ntawd, tus nqi xa rov qab los ntawm `list` daim ntawv' hais kom ua yog ib qho ntawm cov khoom metadata.
243
+
244
+ Cov khoom metadata zoo li no:
245
+
246
+ {
247
+ "name": "fully/qualified/path/to/file",
248
+ "type": "entry-type",
249
+ "size": size-in-bytes,
250
+ "ctime": creation-time-epoch-millis,
251
+ "mtime": modification-time-epoch-millis
252
+ }
253
+
254
+ Cov `type` cuab yeej tuaj yeem yog `file` , `dir` , `link` , lossis `special` .
255
+
256
+ Nyob ntawm seb hom tsav tsheb, `list` hais kom ua yuav tsis rov qab txhua qhov chaw. Cov `name` thiab `type` cov khoom
257
+ yuav tsum muaj nyob. Cov lus txib `metadata` tom ntej yuav rov qab tag nrho cov khoom muaj.
258
+
259
+ ## Hloov ntshuam style
260
+ Ntshuam lub module tag nrho-scoped thiab siv `connect` muaj nuj nqi:
261
+
262
+ const storage = require('mobiletto')
263
+ const opts = {bucket: 'bk', region: 'us-east-1'}
264
+ const s3 = await storage.connect('s3', aws_key, aws_secret, opts)
265
+ const objectData = await s3.readFile('some/path')
266
+
267
+ ## Caching
268
+ Mobiletto ua haujlwm zoo tshaj plaws nrog <a href="https://redis.io">redis</a> cache.
269
+
270
+ Mobiletto yuav sim txuas mus rau qhov piv txwv redis ntawm 127.0.0.1:6379
271
+
272
+ Koj tuaj yeem override ib qho ntawm cov no:
273
+ * Teem lub `MOBILETTO_REDIS_HOST` env var, mobiletto txuas ntawm no es tsis txhob localhost
274
+ * Teem lub `MOBILETTO_REDIS_PORT` env var, qhov chaw nres nkoj no yuav raug siv
275
+
276
+ Mobiletto yuav khaws tag nrho nws cov yuam sij redis nrog lub `_mobiletto__` . Koj tuaj yeem hloov qhov no
277
+ los ntawm kev teeb tsa `MOBILETTO_REDIS_PREFIX` env var.
278
+
279
+ Koj tuaj yeem teeb tsa ib qho kev sib txuas caching nrog `opts.redisConfig` khoom:
280
+
281
+ const redisConfig = {
282
+ enabled: true, // optional, default is true. if false other props are ignored
283
+ host: '127.0.0.1',
284
+ port: 6379,
285
+ prefix: '_mobiletto__'
286
+ }
287
+ const opts = { redisConfig, bucket: 'bk', region: 'us-east-1' }
288
+ const s3 = await storage.connect('s3', aws_key, aws_secret, opts)
289
+
290
+ ### Tsis xav redis caching?
291
+ Txhawm rau lov tes taw: hla `enabled: false` hauv koj qhov khoom `opts.redisConfig` thaum koj tsim koj qhov kev sib txuas.
292
+
293
+ Raws li tau tham hauv qab no, kev tsis ua haujlwm caching yuav muaj kev cuam tshuam tsis zoo rau kev ua haujlwm thiab ua rau muaj kev thov ntau dua
294
+ khaws cia uas koj xav tau tiag tiag.
295
+
296
+ ### Caching kev taw qhia
297
+ **Encrypted cia **: nyeem / sau ntawv encrypted cia tsuas yog me ntsis qeeb dua li qub,
298
+ tab sis navigating ncig cov npe (uas qee yam ua) yog qhov kim heev. Siv lub redis cache
299
+ yuav ua rau koj muaj kev txhawb nqa tseem ceeb.
300
+
301
+ Lub neej ntawd cache muaj kev nyab xeeb, tab sis tsis ua haujlwm zoo yog tias koj muaj ntau qhov kev sau / tshem tawm haujlwm.
302
+ Ib qho kev sau lossis tshem tawm kev ua haujlwm tsis raug cai tag nrho cov cache, kom ntseeg tau tias cov ntawv nyeem tom ntej yuav pom qhov
303
+ kev hloov tshiab kawg.
304
+
305
+ ### CLI cov cuab yeej
306
+ Yog tias koj siv CLI cov cuab yeej xws li [mobiletto-cli](https://www.npmjs.com/package/mobiletto-cli),
307
+ koj yuav xav tau lub redis cache enabled, raws li nws kav hla invocations ntawm `mo` hais kom ua.
308
+
309
+ ## Daim iav
310
+
311
+ // Copy a local filesystem mobiletto to S3
312
+ s3.mirror(local)
313
+
314
+ // Mirror a local subdirectory from one mobiletto to an S3 mobiletto, with it's own subdirectory
315
+ local.mirror(s3, 'some/local-folder', 'some/s3-folder')
316
+
317
+ Cov lus txib `mirror` ua ib daim ntawv luam ib zaug ntawm tag nrho cov ntaub ntawv los ntawm ib qho mobiletto mus rau lwm qhov.
318
+ Nws tsis khiav ib qho txheej txheem los tswj daim iav hla lub sijhawm. Khiav qhov `mirror` hais kom ua dua
319
+ synchronize tej ntaub ntawv uas ploj lawm.
320
+
321
+ Tus nqi rov qab los ntawm `mirror` yog ib yam khoom yooj yim nrog cov txee rau pes tsawg cov ntaub ntawv tau ua tiav
322
+ mirrored thiab pes tsawg cov ntaub ntawv muaj qhov yuam kev:
323
+
324
+ {
325
+ success: count-of-files-mirrored,
326
+ errors: count-of-files-with-errors
327
+ }
328
+
329
+ CEEB TOOM: Mirroring loj cov ntaub ntawv teev yuav siv sij hawm heev thiab bandwidth-intensive
330
+
331
+ Nrog rau `mirror` hu semantics nws tuaj yeem qee zaum tsis meej pem kom nkag siab tias leej twg yog tus
332
+ nyeem ntawv thiab leej twg yog tus sau. Xav txog nws zoo li cov lus qhia: "sab laug-tes mobiletto"
333
+ yog qhov uas tau muab rau (mirrored cov ntaub ntawv sau), thiab "sab tes mobiletto" (the
334
+ kev sib cav rau `mirror` txoj kev) yog tus nqi raug muab (cov ntaub ntawv iav tau nyeem).
335
+
336
+ ## Transparent encryption
337
+ Pab kom pob tshab neeg-sab encryption:
338
+
339
+ // Pass encryption parameters
340
+ const encryption = {
341
+ // key is required, must be >= 16 chars
342
+ key: randomstring.generate(128),
343
+
344
+ // optional, the default is to derive IV from key
345
+ // when set, IV must be >= 16 chars
346
+ iv: randomstring.generate(128),
347
+
348
+ // optional, the default is aes-256-cbc
349
+ algo: 'aes-256-cbc'
350
+ }
351
+ const api = await mobiletto(driverName, key, secret, opts, encryption)
352
+
353
+ // Subsequent write operations will encrypt data (client side) when writing
354
+ // Subsequent read operations will decrypt data (client side) when reading
355
+
356
+ Yuav ua li cas? Ib qho "directory entry" (dirent) directory (encrypted) track what files are in that
357
+ directory (aka lub dirent directory).
358
+ * Cov lus txib `list` nyeem cov ntaub ntawv sau npe nkag, decrypts txhua txoj hauv kev teev tseg; ces rov metadata rau txhua cov ntaub ntawv
359
+ * `list` cov lus txib tsis muaj txiaj ntsig, tshwj xeeb tshaj yog rau cov npe nrog cov ntaub ntawv ntau
360
+ * Cov lus txib `write` sau' sau cov ntaub ntawv sib txawv hauv txhua tus niam txiv phau ntawv qhia, recursively; ces sau cov ntaub ntawv
361
+ * `write` cov lus txib yuav ua rau O(N) sau, nrog N = qhov tob hauv cov npe hierarchy
362
+ * Cov lus txib `remove` tshem tawm" tshem tawm cov ntaub ntawv sib thooj, thiab nws niam nws txiv yog khoob, rov ua dua; ces tshem tawm cov ntaub ntawv
363
+ * Tsis-recursive `remove` cov lus txib yuav ua rau O (N) nyeem thiab muaj peev xwm ntau li tshem tawm, nrog N = qhov tob hauv cov npe hierarchy
364
+ * Recursive `remove` cov lus txib ntawm cov ntaub ntawv loj thiab sib sib zog nqus tuaj yeem kim
365
+
366
+ Nco ntsoov tias txawm tias tus neeg siv-sab encryption tau qhib, tus yeeb ncuab nrog kev pom tag nrho rau hauv koj lub server-sab encrypted
367
+ cia, txawm tias tsis muaj tus yuam sij, tseem tuaj yeem pom tag nrho cov npe ntawm cov npe thiab pes tsawg cov ntaub ntawv nyob hauv txhua, thiab nrog
368
+ qee qhov kev siv zog, nrhiav qee qhov lossis tag nrho cov qauv ntawm cov npe hierarchy.
369
+ * Ceeb toom: Siv cov qauv tiaj tus kom muaj kev ruaj ntseg zoo dua.*
370
+ Tus yeeb ncuab yuav tsis paub cov npe ntawm cov npe / cov ntaub ntawv tshwj tsis yog lawv kuj paub koj qhov encryption
371
+ tus yuam sij los yog muaj lwm yam ua tau zoo tawg qhov encryption. Tag nrho cov bets yog tawm thaum ntawd!
372
+
373
+ ### Kev ua tau zoo thiab caching
374
+ Kev ua haujlwm ntawm encrypted cia yuav qeeb. Recursive cov npe thiab tshem tawm tuaj yeem qeeb heev.
375
+ Caching ntawm redis pab tau zoo heev, tab sis nco ntsoov tias lub cache yog flushed thaum sau lossis tshem tawm.
376
+
377
+ ## Kev hloov pauv hloov pauv
378
+ Tsim ib lub mobiletto nrog koj tus yuam sij tshiab, tom qab ntawd tsom iav cov ntaub ntawv qub rau hauv nws:
379
+
380
+ const storage = require('mobiletto')
381
+
382
+ const oldEncryption = { key: .... }
383
+ const oldStorage = await storage.connect('s3', aws_key, aws_secret, {bucket: 'bk', region: 'us-east-1'}, oldEncryption)
384
+
385
+ const newEncryption = { key: .... }
386
+ const newStorage = await storage.connect('s3', aws_key, aws_secret, {bucket: 'zz', region: 'us-east-1'}, newEncryption)
387
+
388
+ newStorage.mirror(oldStorage) // if oldStorage is very large, this may take a looooooong time...
389
+
390
+ ## Tus tsav tsheb interface
391
+ Tus neeg tsav tsheb yog cov ntaub ntawv JS uas xa tawm 'storageClient' muaj nuj nqi nrog qhov kos npe no:
392
+
393
+ function storageClient (key, secret, opts)
394
+
395
+ * `key` : ib txoj hlua, koj tus yuam sij API (rau `local` tsav tsheb no yog lub hauv paus phau ntawv qhia)
396
+ * `secret` : txoj hlua, koj qhov API zais cia (tuaj yeem raug tshem tawm rau `local` tsav tsheb)
397
+ * `opts` : ib qho khoom, cov khoom yog ib tus tsav tsheb:
398
+ * Rau `local` hauv zos', `fileMode` thiab `dirMode` cov khoom txiav txim siab li cas cov ntaub ntawv tsim tshiab thiab cov npe raug tsim
399
+ * Rau `s3` , yuav tsum muaj `bucket` khoom. Cov khoom xaiv tau yog:
400
+ * `region`: the S3 region, default is us-east-1
401
+ * `prefix`: a prefix to prepend to all S3 paths, default is the empty string
402
+ * `delimiter`: the directory delimiter, default is '/'
403
+
404
+ Cov khoom uas lub storageClient muaj nuj nqi xa rov qab yuav tsum txhais cov haujlwm no:
405
+
406
+ // Test the driver before using, ensure proper configuration
407
+ async testConfig ()
408
+
409
+ // List files in path (or from base-directory)
410
+ // If recursive is true, list recursively
411
+ // If visitor is defined, it will be an async function. await the visitor function on each file found
412
+ // Otherwise, perform the listing and return an array of objects
413
+ async list (path, recursive = false, visitor = null) // path may be omitted
414
+
415
+ // Read metadata for a path
416
+ async metadata (path)
417
+
418
+ // Read a file
419
+ // callback receives a chunk of data. endCallback is called at end-of-stream
420
+ async read (path, callback, endCallback = null)
421
+
422
+ // Write a file
423
+ // driver must be able to handle a generator or a stream
424
+ async write (path, generatorOrReadableStream)
425
+
426
+ // Remove a file, or recursively delete a directory
427
+ // returns a string of a single path removed, or an array of multiple paths removed
428
+ async remove (path, recursive = false, quiet = false)
429
+
430
+ ## Kev sau npe
431
+ Mobiletto siv lub [winston](https://www.npmjs.com/package/winston) kaw lub tsev qiv ntawv.
432
+
433
+ Logs **yuav ** muaj cov ntaub ntawv txoj hauv kev thiab cov lus yuam kev, tab sis yuav ** yeej tsis ** muaj cov yuam sij, zais cia,
434
+ los yog lwm yam kev sib txuas lus configuration.
435
+
436
+ ### Log theem
437
+ Siv `MOBILETTO_LOG_LEVEL` ib puag ncig hloov pauv los teeb tsa theem cav, siv ib qho
438
+ ntawm cov qib `npm` txhais hauv [https://www.npmjs.com/package/winston#logging-levels](https://www.npmjs.com/package/winston#logging-levels)
439
+
440
+ Cov theem pib yog `error` . Qhov feem ntau verbose theem yog `silly` , txawm hais tias tam sim no mobiletto
441
+ tsis teev nyob rau theem hauv qab `debug`
442
+
443
+ MOBILETTO_LOG_LEVEL=silly # maximum logs!
444
+
445
+ ### Log file
446
+ Los ntawm lub neej ntawd, tus logger sau rau lub console. Txhawm rau xa cov cav mus rau cov ntaub ntawv, teeb tsa `MOBILETTO_LOG_FILE`
447
+ ib puag ncig hloov pauv. Thaum nkag mus rau cov ntaub ntawv, cov cav yuav tsis raug sau rau lub console lawm.
448
+
449
+ MOBILETTO_LOG_FILE=/var/my_mobiletto_log
450
+
451
+ Txhawm rau kaw qhov kev kaw tseg:
452
+
453
+ MOBILETTO_LOG_FILE=/dev/null
454
+
455
+ </pre>