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.
- package/README.md +56 -4
- package/docs/README.md +113 -0
- package/docs/af/README.md +455 -0
- package/docs/am/README.md +455 -0
- package/docs/ar/README.md +455 -0
- package/docs/az/README.md +455 -0
- package/docs/be/README.md +455 -0
- package/docs/bg/README.md +455 -0
- package/docs/bn/README.md +455 -0
- package/docs/bs/README.md +455 -0
- package/docs/ca/README.md +455 -0
- package/docs/ceb/README.md +455 -0
- package/docs/co/README.md +455 -0
- package/docs/cs/README.md +455 -0
- package/docs/cy/README.md +455 -0
- package/docs/da/README.md +455 -0
- package/docs/de/README.md +455 -0
- package/docs/el/README.md +455 -0
- package/docs/eo/README.md +455 -0
- package/docs/es/README.md +455 -0
- package/docs/et/README.md +455 -0
- package/docs/eu/README.md +455 -0
- package/docs/fa/README.md +455 -0
- package/docs/fi/README.md +455 -0
- package/docs/fr/README.md +455 -0
- package/docs/fy/README.md +455 -0
- package/docs/ga/README.md +455 -0
- package/docs/gd/README.md +455 -0
- package/docs/gl/README.md +455 -0
- package/docs/gu/README.md +455 -0
- package/docs/ha/README.md +455 -0
- package/docs/haw/README.md +455 -0
- package/docs/he/README.md +455 -0
- package/docs/hi/README.md +455 -0
- package/docs/hmn/README.md +455 -0
- package/docs/hr/README.md +455 -0
- package/docs/ht/README.md +455 -0
- package/docs/hu/README.md +455 -0
- package/docs/hy/README.md +455 -0
- package/docs/id/README.md +455 -0
- package/docs/ig/README.md +455 -0
- package/docs/is/README.md +455 -0
- package/docs/it/README.md +455 -0
- package/docs/iw/README.md +455 -0
- package/docs/ja/README.md +455 -0
- package/docs/jv/README.md +455 -0
- package/docs/ka/README.md +455 -0
- package/docs/kk/README.md +455 -0
- package/docs/km/README.md +455 -0
- package/docs/kn/README.md +455 -0
- package/docs/ko/README.md +455 -0
- package/docs/ku/README.md +455 -0
- package/docs/ky/README.md +455 -0
- package/docs/la/README.md +455 -0
- package/docs/lb/README.md +455 -0
- package/docs/lo/README.md +455 -0
- package/docs/lt/README.md +455 -0
- package/docs/lv/README.md +455 -0
- package/docs/mg/README.md +455 -0
- package/docs/mi/README.md +455 -0
- package/docs/mk/README.md +455 -0
- package/docs/ml/README.md +455 -0
- package/docs/mn/README.md +455 -0
- package/docs/mr/README.md +455 -0
- package/docs/ms/README.md +455 -0
- package/docs/mt/README.md +455 -0
- package/docs/my/README.md +455 -0
- package/docs/ne/README.md +455 -0
- package/docs/nl/README.md +455 -0
- package/docs/no/README.md +455 -0
- package/docs/ny/README.md +455 -0
- package/docs/or/README.md +455 -0
- package/docs/pa/README.md +455 -0
- package/docs/pl/README.md +455 -0
- package/docs/ps/README.md +455 -0
- package/docs/pt/README.md +455 -0
- package/docs/ro/README.md +455 -0
- package/docs/ru/README.md +455 -0
- package/docs/rw/README.md +455 -0
- package/docs/sd/README.md +455 -0
- package/docs/si/README.md +455 -0
- package/docs/sk/README.md +455 -0
- package/docs/sl/README.md +455 -0
- package/docs/sm/README.md +455 -0
- package/docs/sn/README.md +455 -0
- package/docs/so/README.md +455 -0
- package/docs/sq/README.md +455 -0
- package/docs/sr/README.md +455 -0
- package/docs/st/README.md +455 -0
- package/docs/su/README.md +455 -0
- package/docs/sv/README.md +455 -0
- package/docs/sw/README.md +455 -0
- package/docs/ta/README.md +455 -0
- package/docs/te/README.md +455 -0
- package/docs/tg/README.md +455 -0
- package/docs/th/README.md +455 -0
- package/docs/tk/README.md +455 -0
- package/docs/tl/README.md +455 -0
- package/docs/tr/README.md +455 -0
- package/docs/tt/README.md +455 -0
- package/docs/ug/README.md +455 -0
- package/docs/uk/README.md +455 -0
- package/docs/ur/README.md +455 -0
- package/docs/uz/README.md +455 -0
- package/docs/vi/README.md +455 -0
- package/docs/xh/README.md +455 -0
- package/docs/yi/README.md +455 -0
- package/docs/yo/README.md +455 -0
- package/docs/zh/README.md +455 -0
- package/docs/zu/README.md +455 -0
- package/drivers/b2/index.js +24 -6
- package/hokey.json +16 -0
- package/index.js +33 -17
- package/package.json +3 -2
- package/test/api.spec.js +319 -306
- package/util/logger.js +1 -1
- package/util/redis.js +1 -1
|
@@ -0,0 +1,455 @@
|
|
|
1
|
+
Mobiletto
|
|
2
|
+
==========
|
|
3
|
+
|
|
4
|
+
Mobiletto ni safu ya uondoaji ya hifadhi ya JavaScript, iliyo na usimbaji fiche wa hiari wa uwazi wa upande wa mteja.
|
|
5
|
+
|
|
6
|
+
# Yaliyomo
|
|
7
|
+
* [Kwa nini Mobiletto?](#Kwa nini-Mobiletto?)
|
|
8
|
+
* [Kuanza kwa haraka](#Kuanza kwa haraka)
|
|
9
|
+
* [Mobiletto CLI](#mobiletto-cli)
|
|
10
|
+
* [Chanzo](#Chanzo)
|
|
11
|
+
* [Matumizi ya kimsingi](#Matumizi-msingi)
|
|
12
|
+
* [Metadata](#Metadata)
|
|
13
|
+
* [Mtindo mbadala wa uingizaji](#Mtindo-Mbadala-kuagiza)
|
|
14
|
+
* [Ukihifadhi](#Uhifadhi)
|
|
15
|
+
* [Kuakisi](#Kuakisi)
|
|
16
|
+
* [Usimbaji fiche wa Uwazi](#Usimbaji fiche kwa Uwazi)
|
|
17
|
+
* [Mzunguko muhimu](#Mzunguko wa ufunguo)
|
|
18
|
+
* [Kiolesura cha dereva](#Kiolesura cha kiendeshi)
|
|
19
|
+
* [Kuweka kumbukumbu](#Kuweka kumbukumbu)
|
|
20
|
+
|
|
21
|
+
# Soma hii kwa lugha nyingine
|
|
22
|
+
Hati hii ya README.md imetafsiriwa, kupitia [hokeylization](https://github.com/cobbzilla/hokeylization), hadi
|
|
23
|
+
**[kila lugha inayotumika na Google Tafsiri](https://cloud.google.com/translate/docs/languages)!**
|
|
24
|
+
|
|
25
|
+
Nina hakika sio kamili, lakini natumai ni bora kuliko chochote!
|
|
26
|
+
|
|
27
|
+
[🇸🇦 Kiarabu](hati/ar/README.md)
|
|
28
|
+
[🇧🇩 Kibengali](hati/bn/README.md)
|
|
29
|
+
[🇩🇪 Kijerumani](../de/README.md)
|
|
30
|
+
[🇺🇸 Kiingereza]( hati/sw/README.md)
|
|
31
|
+
[🇪🇸 Kihispania](hati/es/README.md)
|
|
32
|
+
[🇫🇷 Kifaransa](../fr/README.md)
|
|
33
|
+
[🇹🇩 Kihausa](hati/ha/README.md)
|
|
34
|
+
[🇮🇳 Kihindi](hati/hi/README.md)
|
|
35
|
+
[🇮🇩 Kiindonesia](hati/id/README.md)
|
|
36
|
+
[🇮🇹 Kiitaliano](hati/it/README.md)
|
|
37
|
+
[🇯🇵 Kijapani](hati/ja/README.md)
|
|
38
|
+
[🇰🇷 Kikorea](hati/ko/README.md)
|
|
39
|
+
[🇮🇳 Maranthi](hati/mr/README.md)
|
|
40
|
+
[🇵🇱 Kipolandi](hati/pl/README.md)
|
|
41
|
+
[🇧🇷 Kireno](hati/pt/README.md)
|
|
42
|
+
[🇷🇺 Kirusi](hati/ru/README.md)
|
|
43
|
+
[🇰🇪 Kiswahili](hati/sw/README.md)
|
|
44
|
+
[🇵🇭 Tagalog](../tl/README.md)
|
|
45
|
+
[🇹🇷 Kituruki](hati/tr/README.md)
|
|
46
|
+
[🇵🇰 Kiurdu](hati/ur/README.md)
|
|
47
|
+
[🇻🇳 Kivietinamu](hati/vi/README.md)
|
|
48
|
+
[🇨🇳 Kichina](hati/zh/README.md)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
**[📚 ... Lugha Zote ...](hati/README.md)**
|
|
52
|
+
----
|
|
53
|
+
|
|
54
|
+
### Je, kuna tatizo katika tafsiri hii ya README?
|
|
55
|
+
Tafsiri hii mahususi ya [README](https://github.com/cobbzilla/mobiletto/blob/master/README.md)
|
|
56
|
+
inaweza kuwa na dosari -- *marekebisho yanakaribishwa sana!* Tafadhali tuma [ombi la kuvuta kwenye GitHub](https://github.com/cobbzilla/mobiletto/pulls),
|
|
57
|
+
au ikiwa huna raha kufanya hivyo, [fungua toleo](https://github.com/cobbzilla/mobiletto/issues)
|
|
58
|
+
|
|
59
|
+
Unapounda toleo jipya la GitHub kuhusu tafsiri, tafadhali fanya:
|
|
60
|
+
* jumuisha URL ya ukurasa (nakili/bandika kutoka kwa upau wa anwani ya kivinjari)
|
|
61
|
+
* jumuisha maandishi kamili ambayo sio sahihi (nakili/bandika kutoka kwa kivinjari)
|
|
62
|
+
* tafadhali eleza kilicho kibaya -- je tafsiri si sahihi? umbizo limevunjika kwa namna fulani?
|
|
63
|
+
* tafadhali toa pendekezo la tafsiri bora zaidi, au jinsi maandishi yanapaswa kupangwa vizuri
|
|
64
|
+
* **Asante!**
|
|
65
|
+
|
|
66
|
+
## Kwa nini Mobiletto?
|
|
67
|
+
|
|
68
|
+
### Kwaheri kufuli kwa muuzaji!
|
|
69
|
+
Watoa huduma mbalimbali wa hifadhi ya wingu wana API zisizooana. Hata wale wanaojitahidi "utangamano wa S3"
|
|
70
|
+
kuwa na tabia za kijinga.
|
|
71
|
+
|
|
72
|
+
Unapochagua mchuuzi mahususi wa hifadhi ya programu yako, ukiweka nambari moja kwa moja kwenye API yake, programu yako
|
|
73
|
+
sasa inategemea huduma hiyo. Kadiri muda unavyosonga na msimbo hujilimbikiza, kubadilisha wachuuzi huwa
|
|
74
|
+
inazidi kutokubalika. Karibu katika ulimwengu wa kufurahisha wa kufuli kwa muuzaji!
|
|
75
|
+
|
|
76
|
+
Mobiletto iliundwa kutatua tatizo hili. Kwa kusimba programu yako kwa API ya mobiletto, unaweza kwa urahisi
|
|
77
|
+
badilisha watoa huduma za hifadhi na ujue kuwa safu ya hifadhi ya programu yako itafanya kazi sawa.
|
|
78
|
+
|
|
79
|
+
### Jaribio la kina
|
|
80
|
+
Viendeshaji vyote hujaribiwa kwa tabia inayofanana na vipimo 60+ kwa kila dereva.
|
|
81
|
+
Tunajaribu madereva wote na kila mchanganyiko wa:
|
|
82
|
+
* Usimbaji fiche: umewezeshwa na umezimwa
|
|
83
|
+
* Redis cache: zote mbili zimewashwa na zimezimwa
|
|
84
|
+
|
|
85
|
+
Mbinu hii inatupa amani ya akili kwamba mobiletto itafanya vivyo hivyo bila kujali unatumia dereva gani,
|
|
86
|
+
na bila kujali kama unawezesha uakibishaji na/au usimbaji fiche.
|
|
87
|
+
|
|
88
|
+
### Usaidizi wa madereva
|
|
89
|
+
Viendeshi vya sasa vya uhifadhi wa Mobiletto:
|
|
90
|
+
* `s3` : Amazon S3
|
|
91
|
+
* `b2` : Backblaze B2
|
|
92
|
+
* `local` : mfumo wa faili wa ndani
|
|
93
|
+
|
|
94
|
+
*Michango ya kusaidia watoa huduma zaidi wa hifadhi ya wingu inakaribishwa sana!*
|
|
95
|
+
|
|
96
|
+
## mobiletto-cli
|
|
97
|
+
Mobiletto imekusudiwa kutumiwa kama maktaba na msimbo mwingine wa JavaScript.
|
|
98
|
+
|
|
99
|
+
Ili kufanya kazi na mobiletto kwenye safu ya amri, tumia [mobiletto-cli](https://www.npmjs.com/package/mobiletto-cli)
|
|
100
|
+
|
|
101
|
+
## Chanzo
|
|
102
|
+
* [mobiletto kwenye GitHub](https://github.com/cobbzilla/mobiletto)
|
|
103
|
+
* [mobiletto kwenye npm](https://www.npmjs.com/package/mobiletto)
|
|
104
|
+
|
|
105
|
+
## Anza Haraka
|
|
106
|
+
Mfano mfupi unaotumia kiendeshi cha mobiletto `s3` .
|
|
107
|
+
|
|
108
|
+
Msimbo huu ungefanya kazi sawa ikiwa dereva angekuwa `b2` au `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
|
+
## Matumizi ya kimsingi
|
|
139
|
+
Mfano mpana zaidi, unaoonyesha vipengele vingi vinavyotolewa:
|
|
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
|
+
Amri ya `metadata` hurejesha metadata kuhusu ingizo moja la mfumo wa faili.
|
|
242
|
+
Vile vile, thamani ya kurudi kutoka kwa amri `list` ni safu ya vipengee vya metadata.
|
|
243
|
+
|
|
244
|
+
Kitu cha metadata kinaonekana kama hii:
|
|
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
|
+
Sifa ya `type` inaweza kuwa `file` , `dir` , `link` , au `special` .
|
|
255
|
+
|
|
256
|
+
Kulingana na aina ya kiendeshi, amri `list` inaweza isirejeshe sehemu zote. Sifa `name` na `type` aina`
|
|
257
|
+
inapaswa kuwapo kila wakati. Amri ya `metadata` ifuatayo itarudisha sifa zote zinazopatikana.
|
|
258
|
+
|
|
259
|
+
## Mtindo mbadala wa kuingiza
|
|
260
|
+
Ingiza moduli iliyo na upeo kamili na utumie kitendakazi cha `connect` :
|
|
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
|
+
##Kuhifadhi
|
|
268
|
+
Mobiletto hufanya kazi vyema ikiwa na akiba ya <a href="https://redis.io">redis</a> .
|
|
269
|
+
|
|
270
|
+
Mobiletto itajaribu kuunganisha kwa mfano wa redis mnamo 127.0.0.1:6379
|
|
271
|
+
|
|
272
|
+
Unaweza kubatilisha mojawapo ya haya:
|
|
273
|
+
* Weka `MOBILETTO_REDIS_HOST` env var, mobiletto unganisha hapa badala ya localhost
|
|
274
|
+
* Weka `MOBILETTO_REDIS_PORT` env var, mlango huu utatumika
|
|
275
|
+
|
|
276
|
+
Mobiletto itahifadhi funguo zake zote za redis kwa kiambishi awali `_mobiletto__` . Unaweza kubadilisha hii
|
|
277
|
+
kwa kuweka `MOBILETTO_REDIS_PREFIX` env var.
|
|
278
|
+
|
|
279
|
+
Unaweza pia kuweka akiba kwa kila muunganisho kwa kitu `opts.redisConfig` :
|
|
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
|
+
### Je, hutaki kuweka akiba upya?
|
|
291
|
+
Ili kuzima: kupitisha `enabled: false` katika kitu chako cha `opts.redisConfig` muunganisho wako.
|
|
292
|
+
|
|
293
|
+
Kama ilivyojadiliwa hapa chini, kuzima akiba kutakuwa na athari mbaya kwa utendakazi na kuleta maombi zaidi
|
|
294
|
+
kwa uhifadhi ambao unahitaji kweli.
|
|
295
|
+
|
|
296
|
+
### Mwongozo wa kuweka akiba
|
|
297
|
+
**Hifadhi iliyosimbwa kwa njia fiche**: kusoma/kuandika hifadhi iliyosimbwa ni polepole kidogo kuliko kawaida,
|
|
298
|
+
lakini kuzunguka saraka (ambazo vitu vingine hufanya) ni ghali sana. Kutumia akiba ya redis
|
|
299
|
+
itakupa uboreshaji mkubwa wa utendaji.
|
|
300
|
+
|
|
301
|
+
Akiba chaguo-msingi ni salama, lakini haifanyi kazi vizuri ikiwa una shughuli nyingi za kuandika/kuondoa.
|
|
302
|
+
Uendeshaji wowote wa kuandika au kuondoa hubatilisha akiba nzima, kuhakikisha usomaji unaofuata utaona
|
|
303
|
+
mabadiliko ya hivi karibuni.
|
|
304
|
+
|
|
305
|
+
### Zana za CLI
|
|
306
|
+
Ikiwa unatumia zana ya CLI kama [mobiletto-cli](https://www.npmjs.com/package/mobiletto-cli),
|
|
307
|
+
hakika utataka akiba ya redis iwezeshwe, kwani inadumu katika maombi ya amri ya `mo` .
|
|
308
|
+
|
|
309
|
+
##Kuakisi
|
|
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
|
+
Amri ya `mirror` hufanya nakala ya mara moja ya faili zote kutoka simu moja hadi nyingine.
|
|
318
|
+
Haiendeshi mchakato wowote wa kudumisha kioo kwa wakati. Endesha amri ya `mirror` tena
|
|
319
|
+
kusawazisha faili zozote zinazokosekana.
|
|
320
|
+
|
|
321
|
+
Thamani ya kurejesha kutoka `mirror` ni kitu rahisi chenye vihesabio vya ni faili ngapi zilifanikiwa
|
|
322
|
+
iliyoangaziwa na ni faili ngapi zilikuwa na makosa:
|
|
323
|
+
|
|
324
|
+
{
|
|
325
|
+
success: count-of-files-mirrored,
|
|
326
|
+
errors: count-of-files-with-errors
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
ONYO: Kuakisi seti kubwa za data kunaweza kuchukua muda mwingi na kutumia kipimo data
|
|
330
|
+
|
|
331
|
+
Kwa semantiki ya simu ya `mirror` inaweza wakati mwingine kuwa na utata kuelewa ni nani
|
|
332
|
+
msomaji na mwandishi ni nani. Hebu fikiria kama taarifa ya mgawo: "mobiletto ya mkono wa kushoto"
|
|
333
|
+
ni kitu kinachopewa (data iliyoakisiwa iliyoandikwa), na "mobiletto ya mkono wa kulia" (the
|
|
334
|
+
hoja ya mbinu ya `mirror` ) ni thamani inayotolewa (data iliyoakisiwa inasomwa).
|
|
335
|
+
|
|
336
|
+
## Usimbaji fiche kwa uwazi
|
|
337
|
+
Washa usimbaji fiche wa upande wa mteja wenye uwazi:
|
|
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
|
+
Nini kinaendelea? Saraka tofauti ya "saraka" (dirent) (iliyosimbwa) hufuatilia ni faili gani zilizomo
|
|
357
|
+
saraka (aka saraka ya mwelekeo).
|
|
358
|
+
* Amri ya `list` inasoma faili za ingizo la saraka, inaondoa kila njia iliyoorodheshwa; kisha inarudisha metadata kwa kila faili
|
|
359
|
+
* `list` zaidi, haswa kwa saraka zilizo na idadi kubwa ya faili
|
|
360
|
+
* Amri ya `write` huandika faili dirent katika saraka ya kila mzazi, kwa kujirudia; kisha anaandika faili
|
|
361
|
+
* amri za `write` ya O(N), na N = kina katika safu ya saraka.
|
|
362
|
+
* Amri ya `remove` huondoa faili inayolingana ya dirent, na mzazi wake ikiwa tupu, kwa kujirudia; kisha huondoa faili
|
|
363
|
+
* Amri zisizorudiwa za `remove` wa O(N) na uwezekano wa kufuta nyingi, na N = kina katika safu ya saraka.
|
|
364
|
+
* Amri za `remove` kwenye mifumo mikubwa na ya kina ya faili zinaweza kuwa ghali
|
|
365
|
+
|
|
366
|
+
Kumbuka kuwa hata usimbaji fiche wa upande wa mteja umewezeshwa, adui anayeonekana kikamilifu kwenye upande wako wa seva uliosimbwa.
|
|
367
|
+
hifadhi, hata bila ufunguo, bado inaweza kuona jumla ya idadi ya saraka na faili ngapi ziko katika kila moja, na pamoja
|
|
368
|
+
juhudi fulani, gundua baadhi au muundo wote wa jumla wa safu ya saraka.
|
|
369
|
+
*Kumbuka: Tumia muundo tambarare kwa usalama bora.*
|
|
370
|
+
Adui hangejua majina ya saraka/faili isipokuwa pia angejua usimbaji fiche wako
|
|
371
|
+
ufunguo au amefaulu kuvunja usimbaji fiche. Dau zote zimezimwa basi!
|
|
372
|
+
|
|
373
|
+
### Utendaji na uakibishaji
|
|
374
|
+
Uendeshaji kwenye hifadhi iliyosimbwa unaweza kuwa polepole. Uorodheshaji unaojirudia na uondoaji unaweza kuwa wa polepole sana.
|
|
375
|
+
Uakibishaji kupitia redis husaidia sana, lakini kumbuka kuwa akiba huwekwa kwenye maandishi yoyote au kuondolewa.
|
|
376
|
+
|
|
377
|
+
## Mzunguko muhimu
|
|
378
|
+
Unda mobiletto na ufunguo wako mpya, kisha uakisi data ya zamani ndani yake:
|
|
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
|
+
## Kiolesura cha dereva
|
|
391
|
+
Dereva ni faili yoyote ya JS inayosafirisha kazi ya 'storageClient' na saini hii:
|
|
392
|
+
|
|
393
|
+
function storageClient (key, secret, opts)
|
|
394
|
+
|
|
395
|
+
* `key` : kamba, ufunguo wako wa API (kwa kiendeshi cha `local` hii ndio saraka ya msingi)
|
|
396
|
+
* `secret` : kamba, siri yako ya API (inaweza kuachwa kwa kiendeshi cha `local` )
|
|
397
|
+
* `opts` : kitu, mali ni kwa kila dereva:
|
|
398
|
+
* Kwa `local` , sifa za `fileMode` na `dirMode` huamua jinsi faili na saraka mpya zinavyoundwa.
|
|
399
|
+
* Kwa `s3` , mali ya `bucket` inahitajika. Sifa za hiari ni:
|
|
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
|
+
Kitu ambacho kitendakazi cha kuhifadhiMteja kinarejesha lazima kifafanue vitendaji hivi:
|
|
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
|
+
## Uwekaji miti
|
|
431
|
+
Mobiletto hutumia maktaba ya ukataji miti ya [winston](https://www.npmjs.com/package/winston).
|
|
432
|
+
|
|
433
|
+
Kumbukumbu **itakuwa** na njia za faili na ujumbe wa makosa, lakini **haitawahi** kuwa na funguo, siri,
|
|
434
|
+
au habari nyingine yoyote ya usanidi wa muunganisho.
|
|
435
|
+
|
|
436
|
+
### Kiwango cha kumbukumbu
|
|
437
|
+
Tumia mabadiliko ya mazingira ya `MOBILETTO_LOG_LEVEL` ili kuweka kiwango cha kumbukumbu, ukitumia moja
|
|
438
|
+
ya viwango vya `npm` vilivyofafanuliwa katika [https://www.npmjs.com/package/winston#logging-levels](https://www.npmjs.com/package/winston#logging-levels)
|
|
439
|
+
|
|
440
|
+
Kiwango chaguo-msingi ni `error` . Kiwango cha kitenzi zaidi ni `silly` , ingawa kwa sasa mobiletto
|
|
441
|
+
haiingii katika viwango chini `debug`
|
|
442
|
+
|
|
443
|
+
MOBILETTO_LOG_LEVEL=silly # maximum logs!
|
|
444
|
+
|
|
445
|
+
### Faili ya kumbukumbu
|
|
446
|
+
Kwa chaguo-msingi, logger anaandika kwa console. Ili kutuma kumbukumbu kwa faili, weka `MOBILETTO_LOG_FILE`
|
|
447
|
+
kutofautiana kwa mazingira. Wakati wa kuingia kwenye faili, kumbukumbu hazitaandikwa tena kwa koni.
|
|
448
|
+
|
|
449
|
+
MOBILETTO_LOG_FILE=/var/my_mobiletto_log
|
|
450
|
+
|
|
451
|
+
Ili kuzima ukataji miti:
|
|
452
|
+
|
|
453
|
+
MOBILETTO_LOG_FILE=/dev/null
|
|
454
|
+
|
|
455
|
+
</pre>
|