mobiletto 1.1.10 → 1.1.13

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 (116) hide show
  1. package/README.md +74 -0
  2. package/docs/README.md +113 -0
  3. package/docs/af/README.md +481 -0
  4. package/docs/am/README.md +481 -0
  5. package/docs/ar/README.md +481 -0
  6. package/docs/az/README.md +481 -0
  7. package/docs/be/README.md +481 -0
  8. package/docs/bg/README.md +481 -0
  9. package/docs/bn/README.md +481 -0
  10. package/docs/bs/README.md +481 -0
  11. package/docs/ca/README.md +481 -0
  12. package/docs/ceb/README.md +481 -0
  13. package/docs/co/README.md +481 -0
  14. package/docs/cs/README.md +481 -0
  15. package/docs/cy/README.md +481 -0
  16. package/docs/da/README.md +481 -0
  17. package/docs/de/README.md +481 -0
  18. package/docs/el/README.md +481 -0
  19. package/docs/eo/README.md +481 -0
  20. package/docs/es/README.md +481 -0
  21. package/docs/et/README.md +481 -0
  22. package/docs/eu/README.md +481 -0
  23. package/docs/fa/README.md +481 -0
  24. package/docs/fi/README.md +481 -0
  25. package/docs/fr/README.md +481 -0
  26. package/docs/fy/README.md +481 -0
  27. package/docs/ga/README.md +481 -0
  28. package/docs/gd/README.md +481 -0
  29. package/docs/gl/README.md +481 -0
  30. package/docs/gu/README.md +481 -0
  31. package/docs/ha/README.md +481 -0
  32. package/docs/haw/README.md +481 -0
  33. package/docs/he/README.md +481 -0
  34. package/docs/hi/README.md +481 -0
  35. package/docs/hmn/README.md +481 -0
  36. package/docs/hr/README.md +481 -0
  37. package/docs/ht/README.md +481 -0
  38. package/docs/hu/README.md +481 -0
  39. package/docs/hy/README.md +481 -0
  40. package/docs/id/README.md +481 -0
  41. package/docs/ig/README.md +481 -0
  42. package/docs/is/README.md +481 -0
  43. package/docs/it/README.md +481 -0
  44. package/docs/iw/README.md +481 -0
  45. package/docs/ja/README.md +481 -0
  46. package/docs/jv/README.md +481 -0
  47. package/docs/ka/README.md +481 -0
  48. package/docs/kk/README.md +481 -0
  49. package/docs/km/README.md +481 -0
  50. package/docs/kn/README.md +481 -0
  51. package/docs/ko/README.md +481 -0
  52. package/docs/ku/README.md +481 -0
  53. package/docs/ky/README.md +481 -0
  54. package/docs/la/README.md +481 -0
  55. package/docs/lb/README.md +481 -0
  56. package/docs/lo/README.md +481 -0
  57. package/docs/lt/README.md +481 -0
  58. package/docs/lv/README.md +481 -0
  59. package/docs/mg/README.md +481 -0
  60. package/docs/mi/README.md +481 -0
  61. package/docs/mk/README.md +481 -0
  62. package/docs/ml/README.md +481 -0
  63. package/docs/mn/README.md +481 -0
  64. package/docs/mr/README.md +481 -0
  65. package/docs/ms/README.md +481 -0
  66. package/docs/mt/README.md +481 -0
  67. package/docs/my/README.md +481 -0
  68. package/docs/ne/README.md +481 -0
  69. package/docs/nl/README.md +481 -0
  70. package/docs/no/README.md +481 -0
  71. package/docs/ny/README.md +481 -0
  72. package/docs/or/README.md +481 -0
  73. package/docs/pa/README.md +481 -0
  74. package/docs/pl/README.md +481 -0
  75. package/docs/ps/README.md +481 -0
  76. package/docs/pt/README.md +481 -0
  77. package/docs/ro/README.md +481 -0
  78. package/docs/ru/README.md +481 -0
  79. package/docs/rw/README.md +481 -0
  80. package/docs/sd/README.md +481 -0
  81. package/docs/si/README.md +481 -0
  82. package/docs/sk/README.md +481 -0
  83. package/docs/sl/README.md +481 -0
  84. package/docs/sm/README.md +481 -0
  85. package/docs/sn/README.md +481 -0
  86. package/docs/so/README.md +481 -0
  87. package/docs/sq/README.md +481 -0
  88. package/docs/sr/README.md +481 -0
  89. package/docs/st/README.md +481 -0
  90. package/docs/su/README.md +481 -0
  91. package/docs/sv/README.md +481 -0
  92. package/docs/sw/README.md +481 -0
  93. package/docs/ta/README.md +481 -0
  94. package/docs/te/README.md +481 -0
  95. package/docs/tg/README.md +481 -0
  96. package/docs/th/README.md +481 -0
  97. package/docs/tk/README.md +481 -0
  98. package/docs/tl/README.md +481 -0
  99. package/docs/tr/README.md +481 -0
  100. package/docs/tt/README.md +481 -0
  101. package/docs/ug/README.md +481 -0
  102. package/docs/uk/README.md +481 -0
  103. package/docs/ur/README.md +481 -0
  104. package/docs/uz/README.md +481 -0
  105. package/docs/vi/README.md +481 -0
  106. package/docs/xh/README.md +481 -0
  107. package/docs/yi/README.md +481 -0
  108. package/docs/yo/README.md +481 -0
  109. package/docs/zh/README.md +481 -0
  110. package/docs/zu/README.md +481 -0
  111. package/drivers/b2/index.js +25 -6
  112. package/hokey.json +16 -0
  113. package/index.js +7 -2
  114. package/package.json +1 -1
  115. package/test/api.spec.js +13 -9
  116. package/util/redis.js +2 -2
@@ -0,0 +1,481 @@
1
+ I-Mobiletto
2
+ ==========
3
+
4
+ I-Mobiletto isendlalelo esinqamulelayo sesitoreji se-JavaScript, esinombhalo wemfihlo ongaseceleni weklayenti ongakukhetha.
5
+
6
+ # Okuqukethwe
7
+ * [Kungani i-Mobiletto?](#Why-Mobiletto?)
8
+ * [Isiqalo esisheshayo](#Qala ngokushesha)
9
+ * [Mobiletto CLI](#mobiletto-cli)
10
+ * [Umthombo](#Umthombo)
11
+ * [Ukufakwa](#Ukufakwa)
12
+ * [Ukwesekwa Noxhaso](#Ukusekela-Noxhaso)
13
+ * [Ukusetshenziswa okuyisisekelo](#Ukusetshenziswa okuyisisekelo)
14
+ * [Imethadatha](#Imethadatha)
15
+ * [Esinye isitayela sokungenisa](#Esinye-isitayela sokungenisa)
16
+ * [Ukulondoloza isikhashana](#Ukulondoloza isikhashana)
17
+ * [Ukubukisa](#Ukubukisa)
18
+ * [Ukubethela okusobala](#Ukubethela-Ngaphandle)
19
+ * [Ukuzungezisa kokhiye](#Ukuzungezisa kokhiye)
20
+ * [Isixhumi esibonakalayo somshayeli](#I-Driver-interface)
21
+ * [Ukungena](#Ukungena)
22
+
23
+ # Funda lokhu ngolunye ulimi
24
+ Lo mbhalo we-README.md uhunyushwe ngokuthi [hokeylization](https://github.com/cobbzilla/hokeylization), ku-
25
+ **[zonke izilimi zisekelwa i-Google Translate](https://cloud.google.com/translate/docs/languages)!**
26
+
27
+ Ngiqinisekile ukuthi ayiphelele, kodwa ngethemba ukuthi ingcono kunalutho!
28
+
29
+ [🇸🇦 Arabic](../ar/README.md)
30
+ [🇧🇩 Bengali](../bn/README.md)
31
+ [🇩🇪 isiJalimane](../de/README.md)
32
+ [🇺🇸 IsiNgisi](../zu/README.md)
33
+ [🇪🇸 Spanish](../es/README.md)
34
+ [🇫🇷 French](../fr/README.md)
35
+ [🇹🇩 Hausa](../ha/README.md)
36
+ [🇮🇳 Hindi](../hi/README.md)
37
+ [🇮🇩 isi-Indonesian](../id/README.md)
38
+ [🇮🇹 isiNtaliyane](../it/README.md)
39
+ [🇯🇵 Japanese](../ja/README.md)
40
+ [🇰🇷 isi-Korean](../ko/README.md)
41
+ [🇮🇳 Maranthi](../mr/README.md)
42
+ [🇵🇱 Polish](../pl/README.md)
43
+ [🇧🇷 isi-Portuguese](../pt/README.md)
44
+ [🇷🇺 Russian](../ru/README.md)
45
+ [🇰🇪 Swahili](../sw/README.md)
46
+ [🇵🇭 Tagalog](../tl/README.md)
47
+ [🇹🇷 Isi-Turkish](../tr/README.md)
48
+ [🇵🇰 Urdu](../ur/README.md)
49
+ [🇻🇳 Vietnamese](../vi/README.md)
50
+ [🇨🇳 isiShayina](../zh/README.md)
51
+
52
+
53
+ **[📚 ... Zonke Izilimi ...](../README.md)**
54
+ ----
55
+
56
+ ### Ingabe kunenkinga ngalokhu kuhunyushwa kwe- README?
57
+ Lokhu kuhunyushwa koqobo [README](https://github.com/cobbzilla/mobiletto/blob/master/README.md)
58
+ ingase ibe namaphutha -- *izilungiso zamukelekile kakhulu!* Sicela uthumele [isicelo sokudonsa ku-GitHub](https://github.com/cobbzilla/mobiletto/pulls),
59
+ noma uma ungakhululekile ukwenza lokho, [vula inkinga](https://github.com/cobbzilla/mobiletto/issues)
60
+
61
+ Uma udala udaba olusha lwe-GitHub mayelana nokuhumusha, sicela wenze:
62
+ * faka i-URL yekhasi (kopisha/unamathisele kubha yekheli lesiphequluli)
63
+ * faka phakathi nombhalo ongalungile (kopisha/unamathisele esipheqululini)
64
+ * ngicela uchaze ukuthi yini engalungile -- ingabe ukuhumusha akulungile? ingabe ukufometha kwephukile ngandlela thile?
65
+ * ngomusa nikeza isiphakamiso senguqulo engcono kakhulu, noma indlela umbhalo okufanele ufomethwe kahle ngayo
66
+ * **Ngiyabonga!**
67
+
68
+ ## Kungani i-Mobiletto?
69
+
70
+ ### Sala kahle ukukhiya komthengisi!
71
+ Abahlinzeki abahlukahlukene besitoreji samafu banama-API angahambelani. Ngisho nalabo abalwela "ukuhambisana kwe-S3"
72
+ babe nokuziphatha okungaqondakali.
73
+
74
+ Uma ukhetha umdayisi othile wesitoreji wohlelo lwakho lokusebenza, uma ukhodi ngokuqondile ku-API yakhe, uhlelo lwakho lokusebenza
75
+ manje incike kuleyo sevisi. Njengoba isikhathi sihamba futhi ikhodi inqwabelana, ukushintsha abathengisi kuba
76
+ ngokungathembeki ngokwandayo. Uyemukelwa emhlabeni ojabulisayo wokukhiya ngaphakathi komthengisi!
77
+
78
+ I-Mobiletto yakhelwe ukuxazulula le nkinga. Ngokubhala ngekhodi uhlelo lwakho lokusebenza ku-mobiletto's API, ungakwazi kalula
79
+ shintsha abahlinzeki besitoreji futhi wazi ukuthi isendlalelo sesitoreji sohlelo lwakho lokusebenza sizoziphatha ngendlela efanayo.
80
+
81
+ ### Ukuhlola okubanzi
82
+ Bonke abashayeli bahlolelwa ukuziphatha okufanayo ngokuhlolwa okungu-60+ kumshayeli ngamunye.
83
+ Sihlola bonke abashayeli ngazo zonke inhlanganisela:
84
+ * Ukubethela: kokubili kunikwe amandla futhi kukhutshaziwe
85
+ * I-Cache ye-Redis: kokubili kunikwe amandla futhi kukhutshaziwe
86
+
87
+ Le ndlela isinika ukuthula kwengqondo ukuthi i-mobiletto izoziphatha ngendlela efanayo noma ngabe usebenzisa muphi umshayeli,
88
+ futhi kungakhathalekile ukuthi unika amandla ukulondoloza isikhashana kanye/noma ukubethela.
89
+
90
+ ### Ukwesekwa kwabashayeli
91
+ Abashayeli besitoreji bamanje be-Mobiletto:
92
+ * `s3` : Amazon S3
93
+ * `b2` : I-Backblaze B2
94
+ * `local` : uhlelo lwefayela lwasendaweni
95
+
96
+ *Iminikelo yokusekela abahlinzeki abengeziwe besitoreji samafu yamukelekile kakhulu!*
97
+
98
+ ## mobiletto-cli
99
+ I-Mobiletto ihloselwe ukusetshenziswa njengomtapo wolwazi ngenye ikhodi ye-JavaScript.
100
+
101
+ Ukuze usebenze ne-mobiletto kulayini womyalo, sebenzisa i-[mobiletto-cli](https://www.npmjs.com/package/mobiletto-cli)
102
+
103
+ ## Umthombo
104
+ * [i-mobiletto ku-GitHub](https://github.com/cobbzilla/mobiletto)
105
+ * [i-mobiletto ku-npm](https://www.npmjs.com/package/mobiletto)
106
+
107
+ ## Ukusekela Nokuxhaswa Ngezimali
108
+ Ngizama ukuba umthuthukisi wesofthiwe yomthombo ovulekile ochwepheshe. Bengisebenza e
109
+ imboni yesofthiwe iminyaka eminingi, ngiqale izinkampani eziphumelelayo futhi ngazithengisa ezinkampanini zomphakathi.
110
+ Muva nje ngilahlekelwe umsebenzi, futhi anginawo omunye umsebenzi engiwulandelayo
111
+
112
+ Ngakho-ke ngizozama ukubhala isoftware ewusizo futhi ngibone ukuthi lokho kuyasebenza
113
+
114
+ Uma uthanda ukusebenzisa le software, ngingabonga kakhulu ngisho nange
115
+ okuncane kakhulu [umnikelo wanyanga zonke nge-Patreon](https://www.patreon.com/cobbzilla)
116
+
117
+ *Ngiyabonga!*
118
+
119
+ ## Ukufakwa
120
+ Faka usebenzisa `npm` noma `yarn` . Cishe ufuna inguqulo `lite` zonke lezi
121
+ amafayela ahunyushwe e-README:
122
+
123
+ npm install mobiletto-lite
124
+ yarn add mobiletto-lite
125
+
126
+ Uma uwafuna ngempela amafayela e-README ngazo zonke izilimi, faka inguqulo egcwele:
127
+
128
+ npm install mobiletto
129
+ yarn add mobiletto
130
+
131
+ ## Ukuqala Ngokushesha
132
+ Isibonelo esifushane sisebenzisa umshayeli we-mobiletto `s3` .
133
+
134
+ Le khodi izosebenza ngendlela efanayo uma umshayeli `b2` noma `local` .
135
+
136
+ const storage = require('mobiletto')
137
+ const bucket = await storage.connect('s3', aws_key, aws_secret, {bucket: 'bk'})
138
+
139
+ // list objects: returns array of metadata objects
140
+ const listing = await bucket.list()
141
+ const dirList = await bucket.list('some/dir/')
142
+ const everything = await bucket.list('', {recursive: true})
143
+
144
+ // write an entire file
145
+ let bytesWritten = await bucket.writeFile('some/path', someBufferOfData)
146
+
147
+ // write a file from a stream/generator
148
+ bytesWritten = await bucket.write('some/path', streamOrGenerator)
149
+
150
+ // read an entire file
151
+ // returns null if an exception would otherwise be thrown
152
+ const bufferOrNull = await bucket.safeReadFile('some/path')
153
+
154
+ // stream-read a file, passing data to callback
155
+ const bytesRead = await bucket.read('some/path', (chunk) => { ...do something with chunk... } )
156
+
157
+ // remove a file, returns the path removed
158
+ let removed = await bucket.remove('some/path') // removed is a string
159
+
160
+ // remove a directory, returns array of paths removed
161
+ removed = await bucket.remove('some/directory', {recursive: true}) // removed is now an array!
162
+
163
+ ----
164
+ ## Ukusetshenziswa okuyisisekelo
165
+ Isibonelo esibanzi kakhulu, esibonisa izici eziningi ezinikezwayo:
166
+
167
+ const { mobiletto } = require('mobiletto')
168
+
169
+ // General usage
170
+ const api = await mobiletto(driverName, key, secret, opts)
171
+
172
+ // To use 'local' driver:
173
+ // * key: base directory
174
+ // * secret: ignored, can be null
175
+ // * opts object:
176
+ // * readOnly: optional, never change anything on the filesystem; default is false
177
+ // * fileMode: optional, permissions used when creating new files, default is 0600. can be string or integer
178
+ // * dirMode: optional, permissions used when creating new directories, default is 0700. can be string or integer
179
+ const local = await mobiletto('local', '/home/ubuntu/tmp', null, {fileMode: 0o0600, dirMode: '0700'})
180
+
181
+ // To use 's3' driver:
182
+ // * key: AWS Access Key ID
183
+ // * secret: AWS Secret Key
184
+ // * opts object:
185
+ // * readOnly: optional, never change anything on the bucket; default is false
186
+ // * bucket: required, name of the S3 bucket
187
+ // * region: optional, the AWS region to communicate with, default is us-east-1
188
+ // * prefix: optional, all read/writes within the S3 bucket will be under this prefix
189
+ // * delimiter: optional, directory delimiter, default is '/' (note: always '/' when encryption is enabled)
190
+ const s3 = await mobiletto('s3', aws_key, aws_secret, {bucket: 'bk', region: 'us-east-1'})
191
+
192
+ // To use 'b2' driver:
193
+ // * key: Backblaze Key ID
194
+ // * secret: Backblaze Application Key
195
+ // * opts object:
196
+ // * readOnly: optional, never change anything on the bucket; default is false
197
+ // * bucket: required, the ID (**not the name**) of the B2 bucket
198
+ // * prefix: optional, all read/writes within the B2 bucket will be under this prefix
199
+ // * delimiter: optional, directory delimiter, default is '/' (note: always '/' when encryption is enabled)
200
+ // * partSize: optional, large files will be split into chunks of this size when uploading
201
+ const b3 = await mobiletto('b2', b2_key_id, b2_app_key, {bucket: 'bk', partSize: 10000000})
202
+
203
+ // List files
204
+ api.list() // --> returns an array of metadata objects
205
+
206
+ // List files recursively
207
+ api.list({ recursive: true })
208
+
209
+ // List files in a directory
210
+ const path = 'some/path'
211
+ api.list(path)
212
+ api.list(path, { recursive: true }) // also supports recursive flag
213
+
214
+ // Visit files in a directory -- visitor function must be async
215
+ api.list(path, { visitor: myAsyncFunc })
216
+ api.list(path, { visitor: myAsyncFunc, recursive: true })
217
+
218
+ // The `list` method throws MobilettoNotFoundError if the path does not exist
219
+ // When you call `safeList` on a non-existent path, it returns an empty array
220
+ api.safeList('/path/that/does/not/exist') // returns []
221
+
222
+ // Read metadata for a file
223
+ api.metadata(path) // returns metadata object
224
+
225
+ // The `metadata` method throws MobilettoNotFoundError if the path does not exist
226
+ // When you call `safeMetadata` on a non-existent path, it returns null
227
+ api.safeMetadata('/tmp/does_not_exist') // returns null
228
+
229
+ // Read a file
230
+ // Provide a callback that writes the data someplace
231
+ const callback = (chunk) => { ... write chunk somewhere ... }
232
+ api.read(path, callback) // returns count of bytes read
233
+
234
+ // Read an entire file at once
235
+ const data = await api.readFile(path) // returns a byte Buffer of the file contents
236
+
237
+ // Read an entire file at once
238
+ // returns null if an exception would otherwise be thrown
239
+ const bufferOrNull = await bucket.safeReadFile('some/path')
240
+
241
+ // Write a file
242
+ // Provide a generator function that yields chunks of data
243
+ const generator = function* () {
244
+ while ( ... more-data-to-return ... ) {
245
+ data = ... load-data ...
246
+ yield data
247
+ }
248
+ }
249
+ local.api(path, generator) // returns count of bytes written
250
+
251
+ // Write an entire file at once (convenience method)
252
+ await api.writeFile(path, bufferOrString) // returns count of bytes written
253
+
254
+ // Delete a file
255
+ // Quiet param is optional (default false), when set errors will not be thrown if the path does not exist
256
+ // Always returns a value or throws an error.
257
+ // Return value may be a single string of the file removed, or an array of all files removed (driver-dependent)
258
+ const quiet = true
259
+ api.remove(path, {quiet}) // returns single path removed
260
+
261
+ // Recursively delete a directory and do it quietly (do not report errors)
262
+ const recursive = true
263
+ const quiet = true
264
+ api.remove(path, {recursive, quiet}) // returns array of paths removed
265
+
266
+ ## Imethadatha
267
+ Umyalo `metadata` ubuyisela imethadatha mayelana nokufakiwe kwesistimu eyodwa yefayela.
268
+ Ngokufanayo, inani elibuyayo elisuka kumyalo `list` lwezinto zemethadatha.
269
+
270
+ Into yemethadatha ibukeka kanje:
271
+
272
+ {
273
+ "name": "fully/qualified/path/to/file",
274
+ "type": "entry-type",
275
+ "size": size-in-bytes,
276
+ "ctime": creation-time-epoch-millis,
277
+ "mtime": modification-time-epoch-millis
278
+ }
279
+
280
+ Isici `type` singaba `file` , `dir` , `link` , noma `special` .
281
+
282
+ Kuye ngohlobo lomshayeli, umyalo `list` ungase ungabuyiseli zonke izinkambu. Izakhiwo `name` kanye `type`
283
+ kufanele ahlale ekhona. Umyalo `metadata` olandelayo uzobuyisela zonke izici ezitholakalayo.
284
+
285
+ ## Esinye isitayela sokungenisa
286
+ Ngenisa imojuli enescoped ngokugcwele futhi usebenzise umsebenzi `connect` :
287
+
288
+ const storage = require('mobiletto')
289
+ const opts = {bucket: 'bk', region: 'us-east-1'}
290
+ const s3 = await storage.connect('s3', aws_key, aws_secret, opts)
291
+ const objectData = await s3.readFile('some/path')
292
+
293
+ ## Ukulondoloza isikhashana
294
+ I-Mobiletto isebenza kahle kakhulu nge- <a href="https://redis.io">redis</a> cache.
295
+
296
+ I-Mobiletto izozama ukuxhuma kusibonelo se-redis kokuthi 127.0.0.1:6379
297
+
298
+ Ungakwazi ukukhipha okunye kwalokhu:
299
+ * Setha i- `MOBILETTO_REDIS_HOST` env var, i-mobiletto xhuma lapha esikhundleni se-localhost
300
+ * Setha i-env var ethi `MOBILETTO_REDIS_PORT` , le mbobo izosetshenziswa
301
+
302
+ I-Mobiletto izogcina bonke okhiye bayo be- `_mobiletto__` . Ungakushintsha lokhu
303
+ ngokusetha `MOBILETTO_REDIS_PREFIX` env var.
304
+
305
+ Ungakwazi futhi ukusetha i-caching yokuxhumana ngakunye ngento `opts.redisConfig` :
306
+
307
+ const redisConfig = {
308
+ enabled: true, // optional, default is true. if false other props are ignored
309
+ host: '127.0.0.1',
310
+ port: 6379,
311
+ prefix: '_mobiletto__'
312
+ }
313
+ const opts = { redisConfig, bucket: 'bk', region: 'us-east-1' }
314
+ const s3 = await storage.connect('s3', aws_key, aws_secret, opts)
315
+
316
+ ### Awufuni i-redis caching?
317
+ Ukukhubaza: dlula `enabled: false` amanga` entweni yakho `opts.redisConfig` uma usungula uxhumano lwakho.
318
+
319
+ Njengoba kuxoxiwe ngezansi, ukukhubaza ukugcinwa kwesikhashana kuzoba nomthelela omubi ekusebenzeni futhi kungenise izicelo eziningi
320
+ endaweni yokugcina oyidingayo ngempela.
321
+
322
+ ### Isiqondiso senqolobane
323
+ **Isitoreji esibethelwe**: isitoreji esibethelwe sokufunda/sokubhala sihamba kancane kunokujwayelekile,
324
+ kodwa ukuzulazula ezinhlwini zemibhalo (okwenziwa ezinye izinto) kubiza kakhulu. Ukusebenzisa inqolobane ye-redis
325
+ izokunikeza ukuthuthukiswa okubalulekile kokusebenza.
326
+
327
+ Inqolobane ezenzakalelayo iphephile, kodwa ayisebenzi kahle uma unemisebenzi eminingi yokubhala/ukususa.
328
+ Noma yikuphi ukubhala noma ukususa umsebenzi kwenza yonke inqolobane ingavumelekile, kuqinisekisa ukuthi ukufundwa okulandelayo kuzobona
329
+ izinguquko zakamuva.
330
+
331
+ ### CLI amathuluzi
332
+ Uma usebenzisa ithuluzi le-CLI elifana ne-[mobiletto-cli](https://www.npmjs.com/package/mobiletto-cli),
333
+ nakanjani uzofuna ukuthi inqolobane ye-redis inikwe amandla, njengoba ihlala kuzo zonke izinxushunxushu zomyalo othi `mo` .
334
+
335
+ ## Ukwenza isibuko
336
+
337
+ // Copy a local filesystem mobiletto to S3
338
+ s3.mirror(local)
339
+
340
+ // Mirror a local subdirectory from one mobiletto to an S3 mobiletto, with it's own subdirectory
341
+ local.mirror(s3, 'some/local-folder', 'some/s3-folder')
342
+
343
+ Umyalo `mirror` wenza ikhophi yesikhathi esisodwa yawo wonke amafayela ukusuka ku-mobiletto eyodwa ukuya kwenye.
344
+ Ayigijimi noma iyiphi inqubo yokugcina isibuko ngokuhamba kwesikhathi. Qalisa umyalo `mirror` futhi
345
+ ukuvumelanisa noma yimaphi amafayela angekho.
346
+
347
+ Inani lokubuyisela elisuka `mirror` liyinto elula enezinto zokubala zokuthi mangaki amafayela aphumelele
348
+ kufakwe isibuko nokuthi mangaki amafayela abe namaphutha:
349
+
350
+ {
351
+ success: count-of-files-mirrored,
352
+ errors: count-of-files-with-errors
353
+ }
354
+
355
+ ISEXWAYISO: Ukulingisa amasethi amakhulu edatha kungase kudle isikhathi futhi kudle umkhawulokudonsa
356
+
357
+ Nge- `mirror` call semantics kungase kudide ukuqonda ukuthi ubani
358
+ umfundi nokuthi ubani umbhali. Kucabange njengesitatimende somsebenzi: "i-mobiletto engakwesokunxele"
359
+ into eyabelwa yona (idatha efakwe esibukweni ebhaliwe), kanye "nesandla sokudla mobiletto" (the
360
+ i-agumenti `mirror` ) inani elinikezwayo (idatha efakwe esibukweni iyafundwa).
361
+
362
+ ## Ukubethela okusobala
363
+ Nika amandla ukubethela kohlangothi lweklayenti okusobala:
364
+
365
+ // Pass encryption parameters
366
+ const encryption = {
367
+ // key is required, must be >= 16 chars
368
+ key: randomstring.generate(128),
369
+
370
+ // optional, the default is to derive IV from key
371
+ // when set, IV must be >= 16 chars
372
+ iv: randomstring.generate(128),
373
+
374
+ // optional, the default is aes-256-cbc
375
+ algo: 'aes-256-cbc'
376
+ }
377
+ const api = await mobiletto(driverName, key, secret, opts, encryption)
378
+
379
+ // Subsequent write operations will encrypt data (client side) when writing
380
+ // Subsequent read operations will decrypt data (client side) when reading
381
+
382
+ Kwenzakalani? Uhla lwemibhalo oluhlukile "lwe-directory entry" (dirent) (olubethelwe) lulandelela ukuthi yimaphi amafayela akulokho
383
+ uhla lwemibhalo (oluyi-direct directory).
384
+ * Umyalo `list` ufunda amafayela okufaka uhla lwemibhalo, uhlukanise indlela ngayinye esohlwini; bese ibuyisela imethadatha yefayela ngalinye
385
+ * Imiyalo `list` kahle, ikakhulukazi kuzinkomba ezinenani elikhulu lamafayela
386
+ * Umyalo othi `write` ubhala amafayela aqondile kuhla lwemibhalo lomzali ngamunye, ngokuphindaphindiwe; bese ebhala ifayela
387
+ * `write` imiyalo izofaka u-O(N) ekubhaleni, ngo-N = ukujula ohlwini lwemibhalo
388
+ * Umyalo othi `remove` ususa ifayela elihambisanayo, futhi umzali walo uma engenalutho, ngokuphindaphindiwe; bese ikhipha ifayela
389
+ * Imiyalo `remove` -O(N) futhi okungenzeka kususwe okuningi, ngokujula kuka-N = ohlwini lwemibhalo
390
+ * Imiyalo `remove` ephindaphindayo ezinhlelweni zamafayela ezinkulu nezijulile ingabiza
391
+
392
+ Qaphela ukuthi noma ngabe ukubethela ohlangothini lweklayenti kunikwe amandla, isitha esibonakala ngokugcwele ohlangothini lwakho lweseva olubethelwe
393
+ isitoreji, ngisho nangaphandle kokhiye, singakwazi ukubona ingqikithi yenani lezinkomba nokuthi mangaki amafayela ekuyinye, kanye ne
394
+ umzamo othile, thola okunye noma sonke isakhiwo sohlu lwemibhalo.
395
+ *Qaphela: Sebenzisa isakhiwo esiyisicaba ukuze uthole ukuphepha okungcono.*
396
+ Isitha ngeke sazi amagama ezinkomba/amafayela ngaphandle uma sikwazi nokubethela kwakho
397
+ ukhiye noma uqhekeze ngempumelelo ukubethela. Konke ukubhejwa kuyacishwa ngaleso sikhathi!
398
+
399
+ ### Ukusebenza kanye nokugcinwa kwesikhashana
400
+ Ukusebenza kusitoreji esibethelwe kungase kuhambe kancane. Ukufakwa kuhlu okuphindaphindayo nokususwa kungahamba kancane kakhulu.
401
+ Ukulondoloza isikhashana nge-redis kusiza kakhulu, kodwa qaphela ukuthi inqolobane ithululwa kunoma yikuphi okulotshiweyo noma okukhishiwe.
402
+
403
+ ## Ukuzungezisa ukhiye
404
+ Dala i-mobiletto ngokhiye wakho omusha, bese ubonisa idatha endala kuyo:
405
+
406
+ const storage = require('mobiletto')
407
+
408
+ const oldEncryption = { key: .... }
409
+ const oldStorage = await storage.connect('s3', aws_key, aws_secret, {bucket: 'bk', region: 'us-east-1'}, oldEncryption)
410
+
411
+ const newEncryption = { key: .... }
412
+ const newStorage = await storage.connect('s3', aws_key, aws_secret, {bucket: 'zz', region: 'us-east-1'}, newEncryption)
413
+
414
+ newStorage.mirror(oldStorage) // if oldStorage is very large, this may take a looooooong time...
415
+
416
+ ## Isixhumi esibonakalayo somshayeli
417
+ Umshayeli yinoma yiliphi ifayela le-JS elithumela ngaphandle umsebenzi we-'storageClient' ngalesi siginesha:
418
+
419
+ function storageClient (key, secret, opts)
420
+
421
+ * `key` : iyunithi yezinhlamvu, ukhiye wakho we-API (komshayeli `local` lolu wuhlu lwemibhalo oluyisisekelo)
422
+ * `secret` : iyunithi yezinhlamvu, imfihlo ye-API yakho (ingashiywa kumshayeli `local` )
423
+ * `opts` ngamunye:
424
+ * `local` , izici `fileMode` kanye `dirMode` zinquma ukuthi kwakhiwe kanjani amafayela amasha nezinkomba.
425
+ * Ku `s3` , indawo `bucket` iyadingeka. Izakhiwo ozikhethela yilezi:
426
+ * `region`: the S3 region, default is us-east-1
427
+ * `prefix`: a prefix to prepend to all S3 paths, default is the empty string
428
+ * `delimiter`: the directory delimiter, default is '/'
429
+
430
+ Into ebuyiselwa umsebenzi we-StoreClient kumele ichaze le misebenzi:
431
+
432
+ // Test the driver before using, ensure proper configuration
433
+ async testConfig ()
434
+
435
+ // List files in path (or from base-directory)
436
+ // If recursive is true, list recursively
437
+ // If visitor is defined, it will be an async function. await the visitor function on each file found
438
+ // Otherwise, perform the listing and return an array of objects
439
+ async list (path, recursive = false, visitor = null) // path may be omitted
440
+
441
+ // Read metadata for a path
442
+ async metadata (path)
443
+
444
+ // Read a file
445
+ // callback receives a chunk of data. endCallback is called at end-of-stream
446
+ async read (path, callback, endCallback = null)
447
+
448
+ // Write a file
449
+ // driver must be able to handle a generator or a stream
450
+ async write (path, generatorOrReadableStream)
451
+
452
+ // Remove a file, or recursively delete a directory
453
+ // returns a string of a single path removed, or an array of multiple paths removed
454
+ async remove (path, recursive = false, quiet = false)
455
+
456
+ ## Ukugawula
457
+ I-Mobiletto isebenzisa [winston](https://www.npmjs.com/package/winston) ilabhulali yokugawula imithi.
458
+
459
+ Amalogi **azoqukatha izindlela zamafayela nemilayezo yephutha, kodwa **angeke** aqukathe okhiye, izimfihlo,
460
+ noma yiluphi olunye ulwazi lokucushwa kokuxhumana.
461
+
462
+ ### Ileveli yelogi
463
+ Sebenzisa `MOBILETTO_LOG_LEVEL` okuguquguqukayo kwemvelo ukuze usethe ileveli yelogi, usebenzisa eyodwa
464
+ `npm` achazwe kokuthi [https://www.npmjs.com/package/winston#logging-levels](https://www.npmjs.com/package/winston#logging-levels)
465
+
466
+ Izinga elizenzakalelayo lithi `error` . Izinga le-verbose kakhulu lithi `silly` , nakuba okwamanje mobiletto
467
+ ayingeni emazingeni angaphansi `debug`
468
+
469
+ MOBILETTO_LOG_LEVEL=silly # maximum logs!
470
+
471
+ ### Ifayela lokungena
472
+ Ngokuzenzakalelayo, logger ubhalela ikhonsoli. Ukuze uthumele amalogi efayeleni, setha `MOBILETTO_LOG_FILE`
473
+ imvelo variable. Uma ungena kufayela, amalogi ngeke esabhalwa kukhonsoli.
474
+
475
+ MOBILETTO_LOG_FILE=/var/my_mobiletto_log
476
+
477
+ Ukuze uvale ukugawula:
478
+
479
+ MOBILETTO_LOG_FILE=/dev/null
480
+
481
+ </pre>
@@ -94,6 +94,7 @@ class StorageClient {
94
94
  return {
95
95
  name: this.denormalizePath(f.fileName),
96
96
  size: f.contentLength,
97
+ mtime: f.uploadTimestamp,
97
98
  type: this.b2type(f),
98
99
  b2id: f.fileId
99
100
  }
@@ -125,7 +126,7 @@ class StorageClient {
125
126
  const files = []
126
127
  await this.auth()
127
128
  const hasMax = opts && opts.max
128
- const maxFileCount = hasMax ? opts.max : 100
129
+ const maxFileCount = hasMax ? opts.max : 1000
129
130
  const pfx = (this.prefix.length === 0 || this.prefix.endsWith(this.delimiter) ? this.prefix : this.prefix + this.delimiter) +
130
131
  (pth.startsWith(this.delimiter) ? pth.substring(0) : pth)
131
132
 
@@ -137,13 +138,31 @@ class StorageClient {
137
138
  })
138
139
  const handleResponse = async (files, pth, response, visitor) => {
139
140
  const list = await this.processList(pth, response, visitor)
141
+ if (list.length === 0) {
142
+ return true
143
+ }
140
144
  if (!optsDir && !firstResult && list.length > 0) {
141
145
  firstResult = list[0]
142
- if (list[0].name.endsWith(this.delimiter)) {
143
- dirDiscovered = true
144
- } else if (!dirDiscovered && list.length > 1 && list[1].name.startsWith(list[0].name)) {
145
- files.push(list[0])
146
- return true
146
+ const exact = firstResult.name === pth || firstResult.name === pth + this.delimiter
147
+ if (exact) {
148
+ // we found exactly what we were looking for
149
+ // if the next thing in the list starts with it plus delimiter,
150
+ // it is a directory, return the contents as long as they match
151
+ if (list.length > 1 && list[1].name.startsWith(pth + this.delimiter)) {
152
+ const dirEntries = list.filter(o => o.name.startsWith(pth));
153
+ files.push(...dirEntries)
154
+ return false
155
+ } else if (firstResult.name.endsWith(this.delimiter)) {
156
+ const dirEntries = list.filter(o => o.name.startsWith(pth));
157
+ files.push(...dirEntries)
158
+ dirDiscovered = true
159
+ return true
160
+
161
+ } else {
162
+ // it's an exact file-match, return it
163
+ files.push(list[0])
164
+ return true
165
+ }
147
166
  }
148
167
  }
149
168
  if (hasMax && files.length + list.length >= maxFileCount) {
package/hokey.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "inputLanguage": "en",
3
+ "languages": "all",
4
+ "hokey": [
5
+ {
6
+ "name": "README",
7
+ "infile": "README.md",
8
+ "outfile": "docs/LANG/",
9
+ "excludes": ["docs/", "node_modules/", "\\.git/", "tmp/"],
10
+ "filter": "relativizeMarkdownLinks docs",
11
+ "force": true,
12
+ "markdown": true,
13
+ "index": "docs/README.md"
14
+ }
15
+ ]
16
+ }
package/index.js CHANGED
@@ -539,8 +539,13 @@ async function mobiletto (driverPath, key, secret, opts, encryption = null) {
539
539
  try {
540
540
  entries = await _loadMeta(dirent, await client.list(dirent))
541
541
  } catch (e) {
542
- if (e instanceof MobilettoNotFoundError && p.includes('/')) {
543
- return await tryParentDirForSingleFile(p, visitor, e)
542
+ if (e instanceof MobilettoNotFoundError) {
543
+ if (p.includes('/')) {
544
+ return await tryParentDirForSingleFile(p, visitor, e)
545
+ }
546
+ throw e
547
+ } else {
548
+ throw new MobilettoError(`encClient.list(${p}): ${e}`, e)
544
549
  }
545
550
  }
546
551
  if (recursive) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mobiletto",
3
- "version": "1.1.10",
3
+ "version": "1.1.13",
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": [
package/test/api.spec.js CHANGED
@@ -62,6 +62,7 @@ async function assertMeta (api, name, expectedSize) {
62
62
  should().exist(meta, 'expected return value from metadata call')
63
63
  expect(meta.name).equals(name, 'expected name of written file to be correct')
64
64
  expect(meta.size).equals(expectedSize, 'expected size of written file to equal size of randomData')
65
+ expect(meta.mtime).is.greaterThan(0, 'expected mtime of written file to be > 0')
65
66
  }
66
67
 
67
68
  async function assertMetaFail (api, name) {
@@ -129,7 +130,7 @@ if (!redisSetup.enabled) continue
129
130
 
130
131
  for (const driverName of DRIVER_NAMES) {
131
132
  // For testing single drivers
132
- // if (driverName !== 'local') continue
133
+ // if (driverName !== 'b2') continue
133
134
 
134
135
  const driverTest = `${driverName} [${redisSetup.name}]`
135
136
  const config = redisSetup.config(DRIVER_CONFIG[driverName])
@@ -373,8 +374,9 @@ describe(`${driverTest} test`, () => {
373
374
  })
374
375
  it("should successfully recursively list files and see all correct subdirectories and files", async () => {
375
376
  const allFiles = await fixture.api.list(randomParent, { recursive: true })
376
- expect(allFiles).to.have.lengthOf(fileCount + 1)
377
- expect(allFiles.find(f => f.name === fullSubdirPath && f.type === M_DIR)).to.not.be.null
377
+ expect(allFiles).to.have.lengthOf.greaterThanOrEqual(fileCount)
378
+ // Not all drivers return "dir" entries when recursively listing. We should see all the files though
379
+ // expect(allFiles.find(f => f.name === fullSubdirPath && f.type === M_DIR)).to.not.be.null
378
380
  expect(allFiles.find(f => f.name === fixture.name && f.type === M_FILE)).to.not.be.null
379
381
  for (let i = 0; i < fileCount; i++) {
380
382
  expect(allFiles.find(f => f.name === tempFilename(fixture.name, i) && f.type === M_FILE)).to.not.be.null
@@ -389,7 +391,7 @@ describe(`${driverTest} test`, () => {
389
391
  expect(objects[0]).to.have.property('type', M_DIR, `subdir should have type ${M_DIR}`)
390
392
  })
391
393
  it("should see correct types on objects returned from a listing of the subdirectory", async () => {
392
- const objects = await fixture.api.list(`${randomParent}/${subdirName}`)
394
+ const objects = await fixture.api.list(`${randomParent}/${subdirName}/`)
393
395
  expect(objects).to.have.lengthOf(fileCount)
394
396
  for (let i = 0; i < fileCount; i++) {
395
397
  // we should find all the files, and they should all have the correct type
@@ -404,15 +406,17 @@ describe(`${driverTest} test`, () => {
404
406
  expect(results).to.have.property('success').greaterThan(0, 'expected some successes in mirroring')
405
407
  })
406
408
  it("should see the same files mirrored both places", async () => {
407
- const originalThings = await fixture.api.list(fullSubdirPath)
409
+ const originalThings = await fixture.api.list(fullSubdirPath, { recursive: true })
408
410
  const mirrorPath = `${mirrorDest}${subdirName}`
409
- const mirrorThings = await fixture.mirrorApi.list(mirrorPath)
411
+ const mirrorThings = await fixture.mirrorApi.list(mirrorPath, { recursive: true })
410
412
  expect(originalThings.length === mirrorThings.length).to.be.true
411
413
 
412
- const intersection = originalThings
413
- .filter(orig => mirrorThings
414
+ const originalFiles = originalThings.filter(o => o.type === M_FILE)
415
+ const mirrorFiles = mirrorThings.filter(o => o.type === M_FILE)
416
+ const intersection = originalFiles
417
+ .filter(orig => mirrorFiles
414
418
  .find(m => basename(m.name) === basename(orig.name)))
415
- expect(intersection.length === originalThings.length).to.be.true
419
+ expect(intersection.length === originalFiles.length).to.be.true
416
420
  })
417
421
  it("loading metadata on a mirrored file succeeds", async () => {
418
422
  const destPath = mirrorDest + subdirName + '/' + basename(fixture.name)
package/util/redis.js CHANGED
@@ -1,7 +1,7 @@
1
1
  const Redis = require('ioredis')
2
2
  const generators = require('redis-async-gen')
3
3
  const { logger } = require('./logger')
4
- const LRU = require("lru-cache")
4
+ const LRU = require('lru-cache')
5
5
 
6
6
  const { DEFAULT_REDIS_OPTIONS } = require('ioredis/built/redis/RedisOptions')
7
7
 
@@ -54,7 +54,7 @@ class MobilettoCache {
54
54
  this.flush().then(
55
55
  () => { logger.debug(`redis(${name}): successfully flushed`) },
56
56
  (e) => {
57
- logger.error(`redis(${name}): error flushing: ${e}, not using redis!`)
57
+ logger.warn(`redis(${name}): error flushing: ${e}, disabling redis`)
58
58
  this.redis = null
59
59
  }
60
60
  )