mobiletto 1.2.1 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.d.ts +2 -0
- package/lib/cjs/index.js +30 -0
- package/lib/cjs/package.json +16 -0
- package/lib/esm/index.d.ts +2 -0
- package/lib/esm/index.js +12 -0
- package/package.json +27 -13
- package/.babelrc +0 -5
- package/.eslintrc.js +0 -14
- package/docs/README.md +0 -113
- package/docs/af/README.md +0 -481
- package/docs/am/README.md +0 -481
- package/docs/ar/README.md +0 -481
- package/docs/az/README.md +0 -481
- package/docs/be/README.md +0 -481
- package/docs/bg/README.md +0 -481
- package/docs/bn/README.md +0 -481
- package/docs/bs/README.md +0 -481
- package/docs/ca/README.md +0 -481
- package/docs/ceb/README.md +0 -481
- package/docs/co/README.md +0 -481
- package/docs/cs/README.md +0 -481
- package/docs/cy/README.md +0 -481
- package/docs/da/README.md +0 -481
- package/docs/de/README.md +0 -481
- package/docs/el/README.md +0 -481
- package/docs/eo/README.md +0 -481
- package/docs/es/README.md +0 -481
- package/docs/et/README.md +0 -481
- package/docs/eu/README.md +0 -481
- package/docs/fa/README.md +0 -481
- package/docs/fi/README.md +0 -481
- package/docs/fr/README.md +0 -481
- package/docs/fy/README.md +0 -481
- package/docs/ga/README.md +0 -481
- package/docs/gd/README.md +0 -481
- package/docs/gl/README.md +0 -481
- package/docs/gu/README.md +0 -481
- package/docs/ha/README.md +0 -481
- package/docs/haw/README.md +0 -481
- package/docs/he/README.md +0 -481
- package/docs/hi/README.md +0 -481
- package/docs/hmn/README.md +0 -481
- package/docs/hr/README.md +0 -481
- package/docs/ht/README.md +0 -481
- package/docs/hu/README.md +0 -481
- package/docs/hy/README.md +0 -481
- package/docs/id/README.md +0 -481
- package/docs/ig/README.md +0 -481
- package/docs/is/README.md +0 -481
- package/docs/it/README.md +0 -481
- package/docs/iw/README.md +0 -481
- package/docs/ja/README.md +0 -481
- package/docs/jv/README.md +0 -481
- package/docs/ka/README.md +0 -481
- package/docs/kk/README.md +0 -481
- package/docs/km/README.md +0 -481
- package/docs/kn/README.md +0 -481
- package/docs/ko/README.md +0 -481
- package/docs/ku/README.md +0 -481
- package/docs/ky/README.md +0 -481
- package/docs/la/README.md +0 -481
- package/docs/lb/README.md +0 -481
- package/docs/lo/README.md +0 -481
- package/docs/lt/README.md +0 -481
- package/docs/lv/README.md +0 -481
- package/docs/mg/README.md +0 -481
- package/docs/mi/README.md +0 -481
- package/docs/mk/README.md +0 -481
- package/docs/ml/README.md +0 -481
- package/docs/mn/README.md +0 -481
- package/docs/mr/README.md +0 -481
- package/docs/ms/README.md +0 -481
- package/docs/mt/README.md +0 -481
- package/docs/my/README.md +0 -481
- package/docs/ne/README.md +0 -481
- package/docs/nl/README.md +0 -481
- package/docs/no/README.md +0 -481
- package/docs/ny/README.md +0 -481
- package/docs/or/README.md +0 -481
- package/docs/pa/README.md +0 -481
- package/docs/pl/README.md +0 -481
- package/docs/ps/README.md +0 -481
- package/docs/pt/README.md +0 -481
- package/docs/ro/README.md +0 -481
- package/docs/ru/README.md +0 -481
- package/docs/rw/README.md +0 -481
- package/docs/sd/README.md +0 -481
- package/docs/si/README.md +0 -481
- package/docs/sk/README.md +0 -481
- package/docs/sl/README.md +0 -481
- package/docs/sm/README.md +0 -481
- package/docs/sn/README.md +0 -481
- package/docs/so/README.md +0 -481
- package/docs/sq/README.md +0 -481
- package/docs/sr/README.md +0 -481
- package/docs/st/README.md +0 -481
- package/docs/su/README.md +0 -481
- package/docs/sv/README.md +0 -481
- package/docs/sw/README.md +0 -481
- package/docs/ta/README.md +0 -481
- package/docs/te/README.md +0 -481
- package/docs/tg/README.md +0 -481
- package/docs/th/README.md +0 -481
- package/docs/tk/README.md +0 -481
- package/docs/tl/README.md +0 -481
- package/docs/tr/README.md +0 -481
- package/docs/tt/README.md +0 -481
- package/docs/ug/README.md +0 -481
- package/docs/uk/README.md +0 -481
- package/docs/ur/README.md +0 -481
- package/docs/uz/README.md +0 -481
- package/docs/vi/README.md +0 -481
- package/docs/xh/README.md +0 -481
- package/docs/yi/README.md +0 -481
- package/docs/yo/README.md +0 -481
- package/docs/zh/README.md +0 -481
- package/docs/zu/README.md +0 -481
- package/drivers/b2/index.js +0 -451
- package/drivers/local/index.js +0 -315
- package/drivers/s3/index.js +0 -316
- package/hokey.json +0 -16
- package/index.js +0 -29
- package/test/api.spec.js +0 -512
- package/test/crypt.spec.js +0 -67
package/docs/jv/README.md
DELETED
|
@@ -1,481 +0,0 @@
|
|
|
1
|
-
Mobiletto
|
|
2
|
-
=========
|
|
3
|
-
|
|
4
|
-
Mobiletto minangka lapisan abstraksi panyimpenan JavaScript, kanthi enkripsi sisih klien transparan opsional.
|
|
5
|
-
|
|
6
|
-
# Isi
|
|
7
|
-
* [Kenapa Mobiletto?](#Kenapa-Mobiletto?)
|
|
8
|
-
* [Wiwit cepet](#Wiwit cepet)
|
|
9
|
-
* [Mobiletto CLI](#mobiletto-cli)
|
|
10
|
-
* [Sumber](#Sumber)
|
|
11
|
-
* [Pasang](#Pasang)
|
|
12
|
-
* [Dhukungan lan Pendanaan](#Support-and-Funding)
|
|
13
|
-
* [Panggunaan dhasar](#Panggunaan dhasar)
|
|
14
|
-
* [Metadata](#Metadata)
|
|
15
|
-
* [Gaya impor alternatif](#Gaya-impor alternatif)
|
|
16
|
-
* [Caching](#Caching)
|
|
17
|
-
* [Mirroring](#Mirroring)
|
|
18
|
-
* [Enkripsi transparan](#Enkripsi-transparan)
|
|
19
|
-
* [Rotasi tombol](#Rotasi tombol)
|
|
20
|
-
* [Antarmuka driver](#Antarmuka driver)
|
|
21
|
-
* [Logging](#Logging)
|
|
22
|
-
|
|
23
|
-
# Waca iki ing basa liya
|
|
24
|
-
Dokumen README.md iki wis diterjemahake, liwat [hokeylization](https://github.com/cobbzilla/hokeylization), menyang
|
|
25
|
-
**[saben basa didhukung Google Terjemahan](https://cloud.google.com/translate/docs/languages)!**
|
|
26
|
-
|
|
27
|
-
Aku yakin ora sampurna, nanging muga-muga luwih apik tinimbang ora ana!
|
|
28
|
-
|
|
29
|
-
[🇸🇦 Arab](../ar/README.md)
|
|
30
|
-
[🇧🇩 Bengali](../bn/README.md)
|
|
31
|
-
[🇩🇪 Jerman](../de/README.md)
|
|
32
|
-
[🇺🇸 Inggris](../id/README.md)
|
|
33
|
-
[🇪🇸 Spanyol](../es/README.md)
|
|
34
|
-
[🇫🇷 Prancis](../fr/README.md)
|
|
35
|
-
[🇹🇩 Hausa](../ha/README.md)
|
|
36
|
-
[🇮🇳 Hindi](../hi/README.md)
|
|
37
|
-
[🇮🇩 Indonesia](../id/README.md)
|
|
38
|
-
[🇮🇹 Italia](../it/README.md)
|
|
39
|
-
[🇯🇵 Jepang](../ja/README.md)
|
|
40
|
-
[🇰🇷 Korea](../ko/README.md)
|
|
41
|
-
[🇮🇳 Marathi](../mr/README.md)
|
|
42
|
-
[🇵🇱 Polandia](../pl/README.md)
|
|
43
|
-
[🇧🇷 Portugis](../pt/README.md)
|
|
44
|
-
[🇷🇺 Rusia](../ru/README.md)
|
|
45
|
-
[🇰🇪 Swahili](../sw/README.md)
|
|
46
|
-
[🇵🇭 Tagalog](../tl/README.md)
|
|
47
|
-
[🇹🇷 Turki](../tr/README.md)
|
|
48
|
-
[🇵🇰 Urdu](../ur/README.md)
|
|
49
|
-
[🇻🇳 Vietnam](../vi/README.md)
|
|
50
|
-
[🇨🇳 Cina](../zh/README.md)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
**[📚 ... Kabeh Basa ...](../README.md)**
|
|
54
|
-
----
|
|
55
|
-
|
|
56
|
-
### Apa ana masalah karo terjemahan README iki?
|
|
57
|
-
Terjemahan khusus iki saka [README] asli (https://github.com/cobbzilla/mobiletto/blob/master/README.md)
|
|
58
|
-
bisa uga ana cacat -- *koreksi banget ditampa!* Mangga ngirim [panjalukan tarik ing GitHub](https://github.com/cobbzilla/mobiletto/pulls),
|
|
59
|
-
utawa yen sampeyan ora kepenak nglakoni, [mbukak masalah](https://github.com/cobbzilla/mobiletto/issues)
|
|
60
|
-
|
|
61
|
-
Nalika sampeyan nggawe masalah GitHub anyar babagan terjemahan, mangga tindakake:
|
|
62
|
-
* kalebu URL kaca (salinan / tempel saka bilah alamat browser)
|
|
63
|
-
* Lebokna teks pas sing salah (salin/tempel saka browser)
|
|
64
|
-
* monggo katrangan apa sing salah -- apa terjemahane salah? format rusak piye wae?
|
|
65
|
-
* nyuwun saran terjemahan sing luwih apik, utawa carane teks kudu diformat kanthi bener
|
|
66
|
-
**Matur nuwun!**
|
|
67
|
-
|
|
68
|
-
## Kenapa Mobiletto?
|
|
69
|
-
|
|
70
|
-
### Pamit vendor lock-in!
|
|
71
|
-
Maneka warna panyedhiya panyimpenan awan duwe API sing ora kompatibel. Malah sing ngupayakake "kompatibilitas S3"
|
|
72
|
-
duweni tingkah laku idiosinkratik.
|
|
73
|
-
|
|
74
|
-
Nalika sampeyan milih vendor panyimpenan tartamtu kanggo app, yen kode langsung menyang API, app sampeyan
|
|
75
|
-
saiki gumantung ing layanan kasebut. Minangka wektu liwat lan kode accumulates, ngganti vendor dadi
|
|
76
|
-
sansaya ora bisa ditindakake. Sugeng rawuh ing jagad sing nyenengake vendor lock-in!
|
|
77
|
-
|
|
78
|
-
Mobiletto dirancang kanggo ngatasi masalah iki. Kanthi ngodhe app menyang API mobiletto, sampeyan bisa kanthi gampang
|
|
79
|
-
ngganti panyedhiya panyimpenan lan ngerti yen lapisan panyimpenan app bakal tumindak identik.
|
|
80
|
-
|
|
81
|
-
### Pengujian ekstensif
|
|
82
|
-
Kabeh pembalap dites kanggo prilaku sing padha karo 60+ tes kanggo saben pembalap.
|
|
83
|
-
Kita nyoba kabeh pembalap kanthi saben kombinasi:
|
|
84
|
-
* Enkripsi: diaktifake lan dipateni
|
|
85
|
-
* Cache Redis: diaktifake lan dipateni
|
|
86
|
-
|
|
87
|
-
Pendekatan iki menehi kita tentrem-of-atine sing mobiletto bakal tumindak padha preduli saka driver sing sampeyan gunakake,
|
|
88
|
-
lan preduli saka apa sampeyan ngaktifake cache lan / utawa enkripsi.
|
|
89
|
-
|
|
90
|
-
### Dhukungan driver
|
|
91
|
-
Driver panyimpenan Mobiletto saiki:
|
|
92
|
-
* `s3` : Amazon S3
|
|
93
|
-
* `b2` : Backblaze B2
|
|
94
|
-
* `local` : sistem berkas lokal
|
|
95
|
-
|
|
96
|
-
*Kontribusi kanggo ndhukung panyedhiya panyimpenan awan luwih akeh ditampa!*
|
|
97
|
-
|
|
98
|
-
## mobiletto-cli
|
|
99
|
-
Mobiletto dimaksudake kanggo digunakake minangka perpustakaan dening kode JavaScript liyane.
|
|
100
|
-
|
|
101
|
-
Kanggo nggarap mobiletto ing baris perintah, gunakake [mobiletto-cli](https://www.npmjs.com/package/mobiletto-cli)
|
|
102
|
-
|
|
103
|
-
## Sumber
|
|
104
|
-
* [mobiletto ing GitHub](https://github.com/cobbzilla/mobiletto)
|
|
105
|
-
* [mobiletto ing npm](https://www.npmjs.com/package/mobiletto)
|
|
106
|
-
|
|
107
|
-
## Dhukungan lan Pendanaan
|
|
108
|
-
Aku nyoba dadi pangembang piranti lunak sumber terbuka profesional. Aku wis kerja ing
|
|
109
|
-
industri lunak kanggo akèh taun, Aku wis miwiti perusahaan sukses lan didol menyang perusahaan umum.
|
|
110
|
-
Bubar iki aku kelangan pegaweyan, lan aku ora duwe gaweyan liyane
|
|
111
|
-
|
|
112
|
-
Dadi aku bakal nyoba nulis piranti lunak sing migunani lan ndeleng manawa bisa digunakake
|
|
113
|
-
|
|
114
|
-
Yen sampeyan seneng nggunakake piranti lunak iki, aku bakal matur nuwun banget kanggo
|
|
115
|
-
paling cilik [kontribusi saben wulan liwat Patreon](https://www.patreon.com/cobbzilla)
|
|
116
|
-
|
|
117
|
-
*Matur nuwun!*
|
|
118
|
-
|
|
119
|
-
## Instalasi
|
|
120
|
-
Instal nggunakake `npm` utawa `yarn` . Sampeyan mbokmenawa pengin versi `lite` sing ora kalebu kabeh
|
|
121
|
-
file README sing diterjemahake:
|
|
122
|
-
|
|
123
|
-
npm install mobiletto-lite
|
|
124
|
-
yarn add mobiletto-lite
|
|
125
|
-
|
|
126
|
-
Yen sampeyan pengin file README ing saben basa, instal versi lengkap:
|
|
127
|
-
|
|
128
|
-
npm install mobiletto
|
|
129
|
-
yarn add mobiletto
|
|
130
|
-
|
|
131
|
-
## Mulai cepet
|
|
132
|
-
Conto singkat nggunakake driver mobiletto `s3` .
|
|
133
|
-
|
|
134
|
-
Kode iki bakal mlaku padha yen driver `b2` utawa `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
|
-
## Panggunaan dhasar
|
|
165
|
-
Conto sing luwih akeh, nuduhake umume fitur sing ditawakake:
|
|
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
|
-
## Metadata
|
|
267
|
-
Printah `metadata` ngasilake metadata babagan entri filesystem siji.
|
|
268
|
-
Kajaba iku, nilai bali saka printah `list` minangka susunan obyek metadata.
|
|
269
|
-
|
|
270
|
-
Objek metadata katon kaya iki:
|
|
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
|
-
Properti `type` bisa dadi `file` , `dir` , `link` , utawa `special` .
|
|
281
|
-
|
|
282
|
-
Gumantung saka jinis driver, printah `list` ora bisa ngasilake kabeh kolom. Properti `name` lan `type`
|
|
283
|
-
kudu tansah ana. Printah `metadata` sabanjure bakal ngasilake kabeh properti sing kasedhiya.
|
|
284
|
-
|
|
285
|
-
## Gaya impor alternatif
|
|
286
|
-
Impor modul lengkap lan gunakake fungsi `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
|
-
## Caching
|
|
294
|
-
Mobiletto paling apik karo cache <a href="https://redis.io">redis</a> .
|
|
295
|
-
|
|
296
|
-
Mobiletto bakal nyoba nyambung menyang conto redis ing 127.0.0.1:6379
|
|
297
|
-
|
|
298
|
-
Sampeyan bisa ngganti salah siji saka iki:
|
|
299
|
-
* Setel `MOBILETTO_REDIS_HOST` env var, mobiletto sambung ing kene tinimbang localhost
|
|
300
|
-
* Setel env var `MOBILETTO_REDIS_PORT` , port iki bakal digunakake
|
|
301
|
-
|
|
302
|
-
Mobiletto bakal nyimpen kabeh tombol redis kanthi awalan `_mobiletto__` . Sampeyan bisa ngganti iki
|
|
303
|
-
kanthi nyetel `MOBILETTO_REDIS_PREFIX` env var.
|
|
304
|
-
|
|
305
|
-
Sampeyan uga bisa nyetel caching saben sambungan nganggo obyek `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
|
-
### Ora pengin redis caching?
|
|
317
|
-
Kanggo mateni: pass `enabled: false` ing obyek `opts.redisConfig` nalika sampeyan nggawe sambungan.
|
|
318
|
-
|
|
319
|
-
Kaya sing wis dibahas ing ngisor iki, mateni caching bakal duwe pengaruh sing ora becik kanggo kinerja lan entuk panjaluk liyane
|
|
320
|
-
kanggo panyimpenan sing pancene kudu.
|
|
321
|
-
|
|
322
|
-
### Panuntun cache
|
|
323
|
-
**Panyimpenan sing dienkripsi**: panyimpenan sing dienkripsi maca/nulis mung luwih alon tinimbang biasane,
|
|
324
|
-
nanging navigasi ing direktori (sing ditindakake sawetara perkara) cukup larang. Nggunakake cache redis
|
|
325
|
-
bakal menehi ngedongkrak kinerja pinunjul.
|
|
326
|
-
|
|
327
|
-
Cache standar aman, nanging ora nindakake kanthi apik yen sampeyan duwe akeh operasi nulis / mbusak.
|
|
328
|
-
Sembarang operasi nulis utawa mbusak invalidates kabeh cache, mesthekake maca sakteruse bakal weruh
|
|
329
|
-
owah-owahan paling anyar.
|
|
330
|
-
|
|
331
|
-
### Alat CLI
|
|
332
|
-
Yen sampeyan nggunakake alat CLI kaya [mobiletto-cli](https://www.npmjs.com/package/mobiletto-cli),
|
|
333
|
-
temtunipun sampeyan pengin cache redis diaktifake, amarga tetep ing invocations saka printah `mo` .
|
|
334
|
-
|
|
335
|
-
## Pangilon
|
|
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
|
-
`mirror` nindakake salinan siji-wektu kabeh file saka siji mobiletto menyang liyane.
|
|
344
|
-
Ora ana proses kanggo njaga pangilon saka wektu. `mirror` maneh
|
|
345
|
-
kanggo nyinkronake file sing ilang.
|
|
346
|
-
|
|
347
|
-
Nilai bali saka `mirror` iku obyek prasaja karo counters carane akeh file sing kasil
|
|
348
|
-
mirrored lan carane akeh file duwe kesalahan:
|
|
349
|
-
|
|
350
|
-
{
|
|
351
|
-
success: count-of-files-mirrored,
|
|
352
|
-
errors: count-of-files-with-errors
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
PÈNGET: Mirroring set data gedhe bisa banget wektu-akeh lan bandwidth-intensif
|
|
356
|
-
|
|
357
|
-
Kanthi semantik panggilan `mirror` kadhangkala bisa mbingungake kanggo mangerteni sapa sing
|
|
358
|
-
pamaca lan sapa panulise. Bayangake kaya pernyataan tugas: "mobiletto kiwa"
|
|
359
|
-
yaiku bab sing ditugasake (data cermin sing ditulis), lan "mobiletto tengen" (ing
|
|
360
|
-
argumen kanggo metode `mirror` ) yaiku nilai sing ditugasake (data cermin diwaca).
|
|
361
|
-
|
|
362
|
-
## Enkripsi transparan
|
|
363
|
-
Aktifake enkripsi sisih klien sing transparan:
|
|
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
|
-
Apa sing kedadeyan? Direktori "entri direktori" (dirent) sing kapisah (dienkripsi) nglacak file apa sing ana
|
|
383
|
-
direktori (alias direktori direktori).
|
|
384
|
-
* `list` maca file entri direktori, dekripsi saben path sing kadhaptar; banjur ngasilake metadata kanggo saben file
|
|
385
|
-
* `list` luwih ora efisien, utamane kanggo direktori kanthi jumlah file sing akeh
|
|
386
|
-
* `write` nulis file dirent ing direktori dirent saben wong tuwa, kanthi rekursif; banjur nulis file kasebut
|
|
387
|
-
* `write` bakal entuk O(N) nulis, kanthi N = ambane ing hirarki direktori
|
|
388
|
-
* `remove` mbusak file dirent sing cocog, lan induke yen kosong, rekursif; banjur mbusak file kasebut
|
|
389
|
-
* Printah `remove` non-rekursif bakal entuk O(N) diwaca lan bisa uga bisa dibusak, kanthi N = ambane ing hirarki direktori
|
|
390
|
-
* `remove` rekursif ing sistem file gedhe lan jero bisa uga larang
|
|
391
|
-
|
|
392
|
-
Elinga yen sanajan enkripsi sisih klien diaktifake, mungsuh kanthi visibilitas lengkap menyang sisih server sing dienkripsi.
|
|
393
|
-
panyimpenan, malah tanpa tombol, isih bisa ndeleng nomer total direktori lan carane akeh file ing saben, lan karo
|
|
394
|
-
sawetara efforts , nemokake sawetara utawa kabeh struktur sakabèhé saka hirarki direktori.
|
|
395
|
-
*Cathetan: Gunakake struktur sing rata kanggo keamanan sing luwih apik.*
|
|
396
|
-
Mungsuh ora bakal ngerti jeneng direktori / file kajaba dheweke uga ngerti enkripsi sampeyan
|
|
397
|
-
kunci utawa wis kasil retak enkripsi. Kabeh taruhan mati banjur!
|
|
398
|
-
|
|
399
|
-
### Kinerja lan cache
|
|
400
|
-
Operasi ing panyimpenan ndhelik bisa alon. Daftar rekursif lan penghapusan bisa dadi alon banget.
|
|
401
|
-
Caching liwat redis mbantu banget, nanging elinga yen cache disiram nalika nulis utawa mbusak.
|
|
402
|
-
|
|
403
|
-
## Rotasi tombol
|
|
404
|
-
Gawe mobiletto nganggo kunci anyar, banjur kaca data lawas menyang:
|
|
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
|
-
## Antarmuka driver
|
|
417
|
-
Driver yaiku file JS sing ngekspor fungsi 'storageClient' kanthi tandha iki:
|
|
418
|
-
|
|
419
|
-
function storageClient (key, secret, opts)
|
|
420
|
-
|
|
421
|
-
* `key` : string, kunci API sampeyan (kanggo driver `local` iki minangka direktori dhasar)
|
|
422
|
-
* `secret` : string, rahasia API sampeyan (bisa diilangi kanggo driver `local` )
|
|
423
|
-
* `opts` : obyek, properti kasebut saben driver:
|
|
424
|
-
* Kanggo `local` , `fileMode` lan `dirMode` nemtokake cara nggawe file lan direktori anyar.
|
|
425
|
-
* Kanggo `s3` , properti `bucket` dibutuhake. Properti opsional yaiku:
|
|
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
|
-
Obyek sing bali fungsi storageClient kudu nemtokake fungsi kasebut:
|
|
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
|
-
## Logging
|
|
457
|
-
Mobiletto nggunakake perpustakaan log [winston](https://www.npmjs.com/package/winston).
|
|
458
|
-
|
|
459
|
-
Log **bakal** ngemot path file lan pesen kesalahan, nanging bakal **ora tau** ngemot kunci, rahasia,
|
|
460
|
-
utawa informasi konfigurasi sambungan liyane.
|
|
461
|
-
|
|
462
|
-
### Tingkat log
|
|
463
|
-
Gunakake variabel lingkungan `MOBILETTO_LOG_LEVEL` kanggo nyetel level log, nggunakake siji
|
|
464
|
-
saka tingkat `npm` ditetepake ing [https://www.npmjs.com/package/winston#logging-levels](https://www.npmjs.com/package/winston#logging-levels)
|
|
465
|
-
|
|
466
|
-
Tingkat standar yaiku `error` . Tingkat paling verbose yaiku `silly` , sanajan saiki mobiletto
|
|
467
|
-
ora mlebu ing tingkat ngisor `debug`
|
|
468
|
-
|
|
469
|
-
MOBILETTO_LOG_LEVEL=silly # maximum logs!
|
|
470
|
-
|
|
471
|
-
### File log
|
|
472
|
-
Kanthi gawan, logger nulis menyang console. Kanggo ngirim log menyang file, setel `MOBILETTO_LOG_FILE`
|
|
473
|
-
variabel lingkungan. Nalika mlebu menyang file, log ora bakal ditulis maneh ing console.
|
|
474
|
-
|
|
475
|
-
MOBILETTO_LOG_FILE=/var/my_mobiletto_log
|
|
476
|
-
|
|
477
|
-
Kanggo mateni logging:
|
|
478
|
-
|
|
479
|
-
MOBILETTO_LOG_FILE=/dev/null
|
|
480
|
-
|
|
481
|
-
</pre>
|