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 mangrupikeun lapisan abstraksi neundeun JavaScript, kalayan énkripsi sisi klien transparan pilihan.
|
|
5
|
+
|
|
6
|
+
# Eusi
|
|
7
|
+
* [Naha Mobiletto?](#Naha-Mobiletto?)
|
|
8
|
+
* [Mimitian Gancang](#Mimitian Gancang)
|
|
9
|
+
* [Mobiletto CLI](#mobiletto-cli)
|
|
10
|
+
* [Sumber](#Sumber)
|
|
11
|
+
* [Pamakéan Dasar](#Pamakéan Dasar)
|
|
12
|
+
* [Metadata](#Metadata)
|
|
13
|
+
* [Gaya impor alternatip](#gaya-impor alternatif)
|
|
14
|
+
* [Caching](#Caching)
|
|
15
|
+
* [Mirroring](#Mirroring)
|
|
16
|
+
* [Enkripsi Transparan](#Enkripsi Transparan)
|
|
17
|
+
* [Rotasi konci](#Rotasi konci)
|
|
18
|
+
* [Antarmuka Supir](#Supir-antarmuka)
|
|
19
|
+
* [Logging](#Logging)
|
|
20
|
+
|
|
21
|
+
# Baca ieu dina basa sanés
|
|
22
|
+
Dokumén README.md ieu parantos ditarjamahkeun, ngalangkungan [hokeylization](https://github.com/cobbzilla/hokeylization), kana
|
|
23
|
+
**[sagala basa dirojong ku Google Tarjamah](https://cloud.google.com/translate/docs/languages)!**
|
|
24
|
+
|
|
25
|
+
Kuring yakin éta teu sampurna, tapi kuring miharep éta leuwih hade tinimbang nanaon!
|
|
26
|
+
|
|
27
|
+
[🇸🇦 Arab](../ar/README.md)
|
|
28
|
+
[🇧🇩 Bengali](../bn/README.md)
|
|
29
|
+
[🇩🇪 Jerman](../de/README.md)
|
|
30
|
+
[🇺🇸 Basa Sunda](../en/README.md)
|
|
31
|
+
[🇪🇸 Spanyol](../es/README.md)
|
|
32
|
+
[🇫🇷 Perancis](../fr/README.md)
|
|
33
|
+
[🇹🇩 Hausa](../ha/README.md)
|
|
34
|
+
[🇮🇳 Hindi](../hi/README.md)
|
|
35
|
+
[🇮🇩 Indonésia](../id/README.md)
|
|
36
|
+
[🇮🇹 Italia](../it/README.md)
|
|
37
|
+
[🇯🇵 Basa Jepang](../ja/README.md)
|
|
38
|
+
[🇰🇷 Koréa](../ko/README.md)
|
|
39
|
+
[🇮🇳 Maranthi](../mr/README.md)
|
|
40
|
+
[🇵🇱 Polandia](../pl/README.md)
|
|
41
|
+
[🇧🇷 Portugis](../pt/README.md)
|
|
42
|
+
[🇷🇺 Rusia](../ru/README.md)
|
|
43
|
+
[🇰🇪 Swahili](../sw/README.md)
|
|
44
|
+
[🇵🇭 Tagalog](../tl/README.md)
|
|
45
|
+
[🇹🇷 Turki](../tr/README.md)
|
|
46
|
+
[🇵🇰 Urdu](../ur/README.md)
|
|
47
|
+
[🇻🇳 Vietnam](../vi/README.md)
|
|
48
|
+
[🇨🇳 Cina](../zh/README.md)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
**[📚 ... Sadaya Basa ...](../README.md)**
|
|
52
|
+
----
|
|
53
|
+
|
|
54
|
+
### Naha aya masalah sareng tarjamahan README ieu?
|
|
55
|
+
Tarjamahan khusus ieu tina [README] asli (https://github.com/cobbzilla/mobiletto/blob/master/README.md)
|
|
56
|
+
meureun cacad -- *koreksi pisan wilujeng sumping!* Punten kirimkeun [permintaan tarik dina GitHub](https://github.com/cobbzilla/mobiletto/pulls),
|
|
57
|
+
atanapi upami anjeun teu nyaman ngalakukeun éta, [buka masalah](https://github.com/cobbzilla/mobiletto/issues)
|
|
58
|
+
|
|
59
|
+
Lamun anjeun nyieun masalah GitHub anyar ngeunaan tarjamahan, mangga ngalakukeun:
|
|
60
|
+
* kalebet URL halaman (salinan/témpél tina bar alamat browser)
|
|
61
|
+
* kalebet téks anu leres anu salah (salin/témpél tina browser)
|
|
62
|
+
* Punten terangkeun naon anu lepat -- naha tarjamahanna lepat? formatna rusak kumaha bae?
|
|
63
|
+
* punten nawiskeun usulan tarjamahan anu langkung saé, atanapi kumaha téks kedah diformat leres
|
|
64
|
+
* **Hatur nuhun!**
|
|
65
|
+
|
|
66
|
+
## Naha Mobiletto?
|
|
67
|
+
|
|
68
|
+
### Wilujeung seller lock-in!
|
|
69
|
+
Rupa-rupa panyadia panyimpen awan gaduh API anu teu cocog. Malah anu narékahan pikeun "kasaluyuan S3"
|
|
70
|
+
boga paripolah idiosinkratis.
|
|
71
|
+
|
|
72
|
+
Lamun anjeun milih ngajual gudang husus pikeun aplikasi Anjeun, lamun kode langsung ka API maranéhna, aplikasi Anjeun
|
|
73
|
+
ayeuna gumantung kana jasa éta. Salaku waktu ngalir jeung kode accumulates, ngarobah ngical paralatan janten
|
|
74
|
+
beuki teu bisa dipertahankeun. Wilujeng sumping di dunya anu pikaresepeun tina vendor lock-in!
|
|
75
|
+
|
|
76
|
+
Mobiletto dirancang pikeun ngajawab masalah ieu. Ku coding aplikasi anjeun ka mobiletto urang API, anjeun bisa kalayan gampang
|
|
77
|
+
robih panyadia panyimpen sareng terang yén lapisan panyimpen aplikasi anjeun bakal kalakuanana idéntik.
|
|
78
|
+
|
|
79
|
+
### Tés éksténsif
|
|
80
|
+
Sadaya supir diuji pikeun paripolah anu sami sareng 60+ tés pikeun tiap supir.
|
|
81
|
+
Kami nguji sadaya supir kalayan unggal kombinasi:
|
|
82
|
+
* Énkripsi: duanana diaktipkeun sareng ditumpurkeun
|
|
83
|
+
* Redis cache: duanana diaktipkeun jeung ditumpurkeun
|
|
84
|
+
|
|
85
|
+
Pendekatan ieu masihan urang katenangan yén mobiletto bakal kalakuanana sami henteu paduli supir anu anjeun anggo,
|
|
86
|
+
sareng henteu paduli naha anjeun ngaktipkeun cache sareng / atanapi énkripsi.
|
|
87
|
+
|
|
88
|
+
### Pangrojong supir
|
|
89
|
+
Panggerak panyimpen Mobiletto ayeuna:
|
|
90
|
+
* `s3` : Amazon S3
|
|
91
|
+
* `b2` : Backblaze B2
|
|
92
|
+
* `local` : sistem file lokal
|
|
93
|
+
|
|
94
|
+
*Kontribusi pikeun ngadukung langkung seueur panyadia panyimpen awan ditampi pisan!*
|
|
95
|
+
|
|
96
|
+
## mobiletto-cli
|
|
97
|
+
Mobiletto dimaksudkeun pikeun dipaké salaku perpustakaan ku kode JavaScript séjén.
|
|
98
|
+
|
|
99
|
+
Pikeun damel sareng mobiletto dina garis paréntah, paké [mobiletto-cli](https://www.npmjs.com/package/mobiletto-cli)
|
|
100
|
+
|
|
101
|
+
## Sumber
|
|
102
|
+
* [mobiletto on GitHub](https://github.com/cobbzilla/mobiletto)
|
|
103
|
+
* [mobiletto on npm](https://www.npmjs.com/package/mobiletto)
|
|
104
|
+
|
|
105
|
+
## Mimitian Gancang
|
|
106
|
+
Conto pondok nganggo supir `s3` .
|
|
107
|
+
|
|
108
|
+
Kode ieu bakal dijalankeun sami upami supirna `b2` atanapi `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
|
+
## Pamakéan dasar
|
|
139
|
+
Conto anu langkung ageung, nunjukkeun seueur fitur anu ditawarkeun:
|
|
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
|
+
## Métadata
|
|
241
|
+
Paréntah `metadata` mulangkeun metadata ngeunaan éntri sistem file tunggal.
|
|
242
|
+
Kitu ogé, nilai mulang tina paréntah `list` mangrupa susunan objék metadata.
|
|
243
|
+
|
|
244
|
+
Obyék metadata sapertos kieu:
|
|
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
|
+
`type` bisa jadi `file` , `dir` , `link` , atawa `special` .
|
|
255
|
+
|
|
256
|
+
Gumantung kana jinis supir, paréntah `list` moal tiasa mulangkeun sadaya widang. The `name` jeung `type` sipat
|
|
257
|
+
kudu salawasna hadir. Paréntah `metadata` salajengna bakal mulangkeun sadaya sipat anu sayogi.
|
|
258
|
+
|
|
259
|
+
## Gaya impor alternatip
|
|
260
|
+
Impor modul pinuh-scoped tur nganggo fungsi `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
|
+
## Cache
|
|
268
|
+
Mobiletto jalan pangalusna kalawan cache <a href="https://redis.io">redis</a> .
|
|
269
|
+
|
|
270
|
+
Mobiletto bakal nyobian nyambung ka instansi redis on 127.0.0.1:6379
|
|
271
|
+
|
|
272
|
+
Anjeun tiasa nimpa salah sahiji ieu:
|
|
273
|
+
* Setel `MOBILETTO_REDIS_HOST` env var, mobiletto nyambung ka dieu tinimbang localhost
|
|
274
|
+
* Setel env var `MOBILETTO_REDIS_PORT` , port ieu bakal dianggo
|
|
275
|
+
|
|
276
|
+
Mobiletto bakal nyimpen sadaya konci redis na nganggo awalan `_mobiletto__` . Anjeun tiasa ngarobah ieu
|
|
277
|
+
ku nyetel `MOBILETTO_REDIS_PREFIX` env var.
|
|
278
|
+
|
|
279
|
+
Anjeun ogé tiasa nyetél cache per-konéksi sareng obyék `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
|
+
### Henteu hoyong redis cache?
|
|
291
|
+
Pikeun nganonaktipkeun: `enabled: false` dina obyék `opts.redisConfig` anjeun nalika anjeun netepkeun sambungan anjeun.
|
|
292
|
+
|
|
293
|
+
Sapertos anu dibahas di handap, nganonaktipkeun cache bakal gaduh pangaruh anu ngabahayakeun kana kinerja sareng nyababkeun langkung seueur pamundut
|
|
294
|
+
ka gudang nu bener kudu.
|
|
295
|
+
|
|
296
|
+
### Pitunjuk cache
|
|
297
|
+
**Panyimpenan énkripsi**: Panyimpenan énkripsi maca/nulis ngan ukur langkung laun tibatan biasana,
|
|
298
|
+
tapi nganapigasi sabudeureun directories (anu sababaraha hal ngalakukeun) cukup mahal. Ngagunakeun cache redis
|
|
299
|
+
bakal masihan anjeun dorongan kinerja anu signifikan.
|
|
300
|
+
|
|
301
|
+
The cache standar geus aman, tapi teu nedunan ogé lamun geus loba nulis / miceun operasi.
|
|
302
|
+
Sagala operasi nulis atawa cabut invalidates sakabéh cache, mastikeun maca saterusna bakal ningali
|
|
303
|
+
parobahan panganyarna.
|
|
304
|
+
|
|
305
|
+
### parabot CLI
|
|
306
|
+
Upami anjeun nganggo alat CLI sapertos [mobiletto-cli](https://www.npmjs.com/package/mobiletto-cli),
|
|
307
|
+
Anjeun pasti bakal hoyong cache redis diaktipkeun, sabab lumangsung dina invocations tina paréntah `mo` .
|
|
308
|
+
|
|
309
|
+
## Ngeunteung
|
|
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
|
+
Paréntah `mirror` ngalakukeun salinan hiji-waktos sadaya file tina hiji mobiletto ka anu sanés.
|
|
318
|
+
Éta henteu ngajalankeun prosés naon waé pikeun ngajaga eunteung kana waktosna. Jalankeun paréntah `mirror` deui
|
|
319
|
+
pikeun nyingkronkeun file anu leungit.
|
|
320
|
+
|
|
321
|
+
Nilai balik ti `mirror` mangrupakeun obyék basajan kalawan counters pikeun sabaraha file anu hasil
|
|
322
|
+
mirrored sareng sabaraha file anu ngagaduhan kasalahan:
|
|
323
|
+
|
|
324
|
+
{
|
|
325
|
+
success: count-of-files-mirrored,
|
|
326
|
+
errors: count-of-files-with-errors
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
PERHATOSAN: Mirroring set data badag bisa jadi pisan consuming waktu jeung rubakpita-intensif
|
|
330
|
+
|
|
331
|
+
Ku `mirror` semantik panggero kadang bisa jadi bingung ngartos saha teh
|
|
332
|
+
pamaca jeung saha nu nulisna. Bayangkeun éta sapertos pernyataan tugas: "mobiletto kénca"
|
|
333
|
+
nyaeta hal anu ditugaskeun ka (data mirrored ditulis), sarta "mobiletto-leungeun katuhu" (the
|
|
334
|
+
argumen kana métode `mirror` ) nyaéta nilai anu ditugaskeun (data mirrored dibaca).
|
|
335
|
+
|
|
336
|
+
## Énkripsi transparan
|
|
337
|
+
Aktipkeun énkripsi sisi klien transparan:
|
|
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
|
+
Aya naon? Diréktori "Éntri diréktori" (dirent) anu misah (énkripsi) ngalacak file naon anu aya dina éta
|
|
357
|
+
diréktori (alias diréktori langsung).
|
|
358
|
+
* Paréntah `list` maca file éntri diréktori, ngadekrip unggal jalur anu didaptarkeun; lajeng mulih metadata pikeun tiap file
|
|
359
|
+
* Paréntah `list` langkung teu éfisién, khususna pikeun diréktori anu seueur file
|
|
360
|
+
* Paréntah `write` nyerat file dirent dina diréktori dirent unggal indungna, sacara rekursif; teras nyerat file
|
|
361
|
+
* Paréntah `write` bakal ditanggung O(N) nyerat, kalayan N = jerona dina hirarki diréktori
|
|
362
|
+
* Paréntah `remove` ngahapus file dirent anu saluyu, sareng indungna upami kosong, sacara rekursif; lajeng miceun file
|
|
363
|
+
* Paréntah `remove` non-rekursif bakal ngahasilkeun O(N) maca sareng berpotensi ngahapus, kalayan N = jerona dina hirarki diréktori
|
|
364
|
+
* Paréntah `remove` dina sistem file anu ageung sareng jero tiasa mahal
|
|
365
|
+
|
|
366
|
+
Catet yén sanajan énkripsi sisi klien diaktipkeun, musuh anu gaduh visibilitas pinuh kana sisi server énkripsi anjeun.
|
|
367
|
+
gudang, sanajan tanpa konci, masih bisa ningali jumlah total directories na sabaraha file dina unggal, tur kalawan
|
|
368
|
+
sababaraha usaha , manggihan sababaraha atawa sakabéh struktur sakabéh hirarki diréktori.
|
|
369
|
+
*Catetan: Anggo struktur anu kawilang datar pikeun kaamanan anu langkung saé.*
|
|
370
|
+
Musuh moal terang nami diréktori / file kecuali aranjeunna ogé terang énkripsi anjeun
|
|
371
|
+
konci atawa geus disebutkeun hasil retakan enkripsi. Kabéh bets pareum lajeng!
|
|
372
|
+
|
|
373
|
+
### Kinerja sareng cache
|
|
374
|
+
Operasi dina neundeun énkripsi tiasa laun. Listing rekursif sareng panyabutan tiasa lambat pisan.
|
|
375
|
+
Caching via redis mantuan tremendously, tapi perhatikeun yén cache ieu flushed kana sagala nyerat atanapi ngahapus.
|
|
376
|
+
|
|
377
|
+
## Rotasi konci
|
|
378
|
+
Jieun mobiletto kalawan konci anyar anjeun, lajeng eunteung data heubeul kana eta:
|
|
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
|
+
## Antarmuka supir
|
|
391
|
+
Supir mangrupikeun file JS anu ngékspor fungsi 'storageClient' kalayan tanda tangan ieu:
|
|
392
|
+
|
|
393
|
+
function storageClient (key, secret, opts)
|
|
394
|
+
|
|
395
|
+
* `key` : string, konci API anjeun (pikeun supir `local` ieu diréktori dasar)
|
|
396
|
+
* `secret` : string, rusiah API anjeun (tiasa dileungitkeun pikeun supir `local` )
|
|
397
|
+
* `opts` : hiji obyék, sipatna per-driver:
|
|
398
|
+
* Pikeun `local` , `fileMode` jeung `dirMode` nangtukeun kumaha nyieun file jeung diréktori anyar dijieun.
|
|
399
|
+
* Pikeun `s3` , sipat `bucket` diperlukeun. Sipat opsional nyaéta:
|
|
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
|
+
Obyék anu dipulangkeun ku fungsi storageClient kedah nangtukeun fungsi ieu:
|
|
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
|
+
## logging
|
|
431
|
+
Mobiletto ngagunakeun perpustakaan logging [winston](https://www.npmjs.com/package/winston).
|
|
432
|
+
|
|
433
|
+
Log ** bakal ** ngandung jalur file sareng pesen kasalahan, tapi bakal ** moal pernah ** ngandung konci, rahasia,
|
|
434
|
+
atanapi inpormasi konfigurasi sambungan anu sanés.
|
|
435
|
+
|
|
436
|
+
### Tingkat log
|
|
437
|
+
Anggo variabel lingkungan `MOBILETTO_LOG_LEVEL` pikeun nyetél tingkat log, nganggo hiji
|
|
438
|
+
tina tingkat `npm` didefinisikeun dina [https://www.npmjs.com/package/winston#logging-levels](https://www.npmjs.com/package/winston#logging-levels)
|
|
439
|
+
|
|
440
|
+
Tingkat standar nyaéta `error` . Tingkat paling verbose nyaéta `silly` , sanajan ayeuna mobiletto
|
|
441
|
+
teu asup dina tingkat handap `debug`
|
|
442
|
+
|
|
443
|
+
MOBILETTO_LOG_LEVEL=silly # maximum logs!
|
|
444
|
+
|
|
445
|
+
### Berkas log
|
|
446
|
+
Sacara standar, logger nyerat kana konsol. Pikeun ngirim log ka file, setel `MOBILETTO_LOG_FILE`
|
|
447
|
+
variabel lingkungan. Nalika asup kana file, log moal ditulis deui kana konsol.
|
|
448
|
+
|
|
449
|
+
MOBILETTO_LOG_FILE=/var/my_mobiletto_log
|
|
450
|
+
|
|
451
|
+
Pikeun mareuman logging:
|
|
452
|
+
|
|
453
|
+
MOBILETTO_LOG_FILE=/dev/null
|
|
454
|
+
|
|
455
|
+
</pre>
|