mobiletto 1.2.1 → 2.0.0
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/zh/README.md
DELETED
|
@@ -1,481 +0,0 @@
|
|
|
1
|
-
手机
|
|
2
|
-
=========
|
|
3
|
-
|
|
4
|
-
Mobiletto 是一个 JavaScript 存储抽象层,具有可选的透明客户端加密。
|
|
5
|
-
|
|
6
|
-
# 内容
|
|
7
|
-
* [为什么选择Mobiletto?](#Why-Mobiletto?)
|
|
8
|
-
* [快速启动](#快速启动)
|
|
9
|
-
* [Mobiletto CLI](#mobiletto-cli)
|
|
10
|
-
* [来源](#来源)
|
|
11
|
-
* [安装](#安装)
|
|
12
|
-
* [支持和资助](#Support-and-Funding)
|
|
13
|
-
* [基本用法](#Basic-usage)
|
|
14
|
-
* [元数据](#元数据)
|
|
15
|
-
* [替代导入样式](#Alternate-import-style)
|
|
16
|
-
* [缓存](#缓存)
|
|
17
|
-
* [镜像](#镜像)
|
|
18
|
-
* [透明加密](#Transparent-encryption)
|
|
19
|
-
* [键旋转](#Key-rotation)
|
|
20
|
-
* [驱动接口](#Driver-interface)
|
|
21
|
-
* [记录](#记录)
|
|
22
|
-
|
|
23
|
-
# 用另一种语言阅读
|
|
24
|
-
此 README.md 文档已通过 [hokeylization](https://github.com/cobbzilla/hokeylization) 翻译成
|
|
25
|
-
**[谷歌翻译支持的所有语言](https://cloud.google.com/translate/docs/languages)!**
|
|
26
|
-
|
|
27
|
-
我敢肯定它并不完美,但我希望它总比没有好!
|
|
28
|
-
|
|
29
|
-
[🇸🇦 阿拉伯语](../ar/README.md)
|
|
30
|
-
[🇧🇩 孟加拉语](../bn/README.md)
|
|
31
|
-
[🇩🇪 德语](../de/README.md)
|
|
32
|
-
[🇺🇸 英文](../en/README.md)
|
|
33
|
-
[🇪🇸 西班牙语](../es/README.md)
|
|
34
|
-
[🇫🇷 法语](../fr/README.md)
|
|
35
|
-
[🇹🇩豪萨语](../ha/README.md)
|
|
36
|
-
[🇮🇳印地语](../hi/README.md)
|
|
37
|
-
[🇮🇩 印尼语](../id/README.md)
|
|
38
|
-
[🇮🇹 意大利语](../it/README.md)
|
|
39
|
-
[🇯🇵 日语](../ja/README.md)
|
|
40
|
-
[🇰🇷韩语](../ko/README.md)
|
|
41
|
-
[🇮🇳 马兰地语](../mr/README.md)
|
|
42
|
-
[🇵🇱波兰语](../pl/README.md)
|
|
43
|
-
[🇧🇷 葡萄牙语](../pt/README.md)
|
|
44
|
-
[🇷🇺 俄语](../ru/README.md)
|
|
45
|
-
[🇰🇪 斯瓦希里语](../sw/README.md)
|
|
46
|
-
[🇵🇭 他加禄语](../tl/README.md)
|
|
47
|
-
[🇹🇷 土耳其语](../tr/README.md)
|
|
48
|
-
[🇵🇰乌尔都语](../ur/README.md)
|
|
49
|
-
[🇻🇳 越南语](../vi/README.md)
|
|
50
|
-
[🇨🇳 中文](../zh/README.md)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
**[📚 ...所有语言 ...](../README.md)**
|
|
54
|
-
----
|
|
55
|
-
|
|
56
|
-
### README 的这个翻译有问题吗?
|
|
57
|
-
原文 [README](https://github.com/cobbzilla/mobiletto/blob/master/README.md) 的特殊翻译
|
|
58
|
-
可能有缺陷——*非常欢迎更正!*请发送 [GitHub 上的拉取请求](https://github.com/cobbzilla/mobiletto/pulls),
|
|
59
|
-
或者如果你不习惯这样做,[打开一个问题](https://github.com/cobbzilla/mobiletto/issues)
|
|
60
|
-
|
|
61
|
-
当您创建有关翻译的新 GitHub 问题时,请执行以下操作:
|
|
62
|
-
* 包括页面 URL(从浏览器地址栏复制/粘贴)
|
|
63
|
-
*包括错误的确切文本(从浏览器复制/粘贴)
|
|
64
|
-
* 请描述问题所在——翻译不正确吗?格式是否以某种方式损坏?
|
|
65
|
-
* 请提供更好的翻译建议,或文本应如何正确格式化
|
|
66
|
-
* **谢谢!**
|
|
67
|
-
|
|
68
|
-
## 为什么选择 Mobiletto?
|
|
69
|
-
|
|
70
|
-
### 再见供应商锁定!
|
|
71
|
-
各种云存储提供商都有不兼容的 API。即使是那些追求“S3兼容性”的人
|
|
72
|
-
有特殊的行为。
|
|
73
|
-
|
|
74
|
-
当您为您的应用选择特定的存储供应商时,如果您直接向他们的 API 编码,您的应用
|
|
75
|
-
现在依赖于该服务。随着时间的推移和代码的积累,不断变化的供应商成为
|
|
76
|
-
越来越站不住脚。欢迎来到供应商锁定的有趣世界!
|
|
77
|
-
|
|
78
|
-
Mobiletto 旨在解决这个问题。通过将您的应用程序编码为 mobiletto 的 API,您可以轻松地
|
|
79
|
-
更改存储提供程序并知道您的应用程序的存储层将表现相同。
|
|
80
|
-
|
|
81
|
-
### 广泛的测试
|
|
82
|
-
所有驱动程序都针对相同的行为进行了测试,每个驱动程序都进行了 60 多次测试。
|
|
83
|
-
我们使用以下各项组合测试所有驱动程序:
|
|
84
|
-
*加密:启用和禁用
|
|
85
|
-
* Redis 缓存:启用和禁用
|
|
86
|
-
|
|
87
|
-
这种方法让我们高枕无忧,无论您使用哪个驱动程序,mobiletto 的行为都相同,
|
|
88
|
-
并且无论您是否启用缓存和/或加密。
|
|
89
|
-
|
|
90
|
-
### 驱动支持
|
|
91
|
-
当前 Mobiletto 存储驱动程序:
|
|
92
|
-
* `s3` : 亚马逊 S3
|
|
93
|
-
* `b2` : 逆光 B2
|
|
94
|
-
* `local` : 本地文件系统
|
|
95
|
-
|
|
96
|
-
*非常欢迎为支持更多云存储提供商做出贡献!*
|
|
97
|
-
|
|
98
|
-
## mobiletto-cli
|
|
99
|
-
Mobiletto 旨在被其他 JavaScript 代码用作库。
|
|
100
|
-
|
|
101
|
-
要在命令行中使用 mobiletto,请使用 [mobiletto-cli](https://www.npmjs.com/package/mobiletto-cli)
|
|
102
|
-
|
|
103
|
-
## 资源
|
|
104
|
-
* [github上的mobiletto](https://github.com/cobbzilla/mobiletto)
|
|
105
|
-
* [npm 上的 mobiletto](https://www.npmjs.com/package/mobiletto)
|
|
106
|
-
|
|
107
|
-
## 支持和资金
|
|
108
|
-
我正在努力成为一名专业的开源软件开发人员。我一直在工作
|
|
109
|
-
从事软件行业多年,我创办了成功的公司,并把它们卖给了上市公司。
|
|
110
|
-
最近我失业了,我真的没有其他工作要做
|
|
111
|
-
|
|
112
|
-
所以我将尝试编写有用的软件,看看是否可行
|
|
113
|
-
|
|
114
|
-
如果您喜欢使用此软件,我将非常感谢
|
|
115
|
-
最小的 [通过 Patreon 的每月贡献](https://www.patreon.com/cobbzilla)
|
|
116
|
-
|
|
117
|
-
*谢谢!*
|
|
118
|
-
|
|
119
|
-
## 安装
|
|
120
|
-
使用`npm`或`yarn`安装。您可能`lite`不包含所有
|
|
121
|
-
翻译自述文件:
|
|
122
|
-
|
|
123
|
-
npm install mobiletto-lite
|
|
124
|
-
yarn add mobiletto-lite
|
|
125
|
-
|
|
126
|
-
如果您真的想要每种语言的 README 文件,请安装完整版:
|
|
127
|
-
|
|
128
|
-
npm install mobiletto
|
|
129
|
-
yarn add mobiletto
|
|
130
|
-
|
|
131
|
-
## 快速开始
|
|
132
|
-
使用 mobiletto `s3`驱动程序的简短示例。
|
|
133
|
-
|
|
134
|
-
如果驱动程序是`b2`或`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
|
-
##基本用法
|
|
165
|
-
一个更广泛的示例,显示了提供的大部分功能:
|
|
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
|
-
## 元数据
|
|
267
|
-
`metadata`命令返回有关单个文件系统条目的元数据。
|
|
268
|
-
同样, `list`命令的返回值是一个元数据对象数组。
|
|
269
|
-
|
|
270
|
-
元数据对象如下所示:
|
|
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
|
-
`type`属性可以是`file` 、 `dir` 、 `link`或`special` 。
|
|
281
|
-
|
|
282
|
-
根据驱动程序的类型, `list`命令可能不会返回所有字段。 `name`和`type`属性
|
|
283
|
-
应始终存在。随后的`metadata`命令将返回所有可用属性。
|
|
284
|
-
|
|
285
|
-
## 替代导入样式
|
|
286
|
-
导入全域模块并使用`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
|
-
## 缓存
|
|
294
|
-
Mobiletto 最适合使用<a href="https://redis.io">redis</a>缓存。
|
|
295
|
-
|
|
296
|
-
Mobiletto 将尝试连接到 127.0.0.1:6379 上的 redis 实例
|
|
297
|
-
|
|
298
|
-
您可以覆盖其中任何一个:
|
|
299
|
-
* 设置`MOBILETTO_REDIS_HOST` env var,mobiletto 连接这里而不是 localhost
|
|
300
|
-
* 设置`MOBILETTO_REDIS_PORT` ,这个端口将被使用
|
|
301
|
-
|
|
302
|
-
Mobiletto 将使用前缀`_mobiletto__`存储其所有 redis 键。你可以改变这个
|
|
303
|
-
通过设置`MOBILETTO_REDIS_PREFIX` 。
|
|
304
|
-
|
|
305
|
-
您还可以使用`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
|
-
### 不想redis缓存?
|
|
317
|
-
要禁用:在建立连接时在`opts.redisConfig`对象中传递`enabled: false` 。
|
|
318
|
-
|
|
319
|
-
如下所述,禁用缓存将对性能产生不利影响并引发更多请求
|
|
320
|
-
到您真正需要的存储空间。
|
|
321
|
-
|
|
322
|
-
### 缓存指导
|
|
323
|
-
**加密存储**:读/写加密存储只比正常慢一点,
|
|
324
|
-
但是在目录中导航(有些事情会这样做)相当昂贵。使用 redis 缓存
|
|
325
|
-
会给你显着的性能提升。
|
|
326
|
-
|
|
327
|
-
默认缓存是安全的,但如果您有很多写入/删除操作,则性能不佳。
|
|
328
|
-
任何写入或删除操作都会使整个缓存失效,确保后续读取将看到
|
|
329
|
-
最新的变化。
|
|
330
|
-
|
|
331
|
-
### CLI 工具
|
|
332
|
-
如果您使用 [mobiletto-cli](https://www.npmjs.com/package/mobiletto-cli) 之类的 CLI 工具,
|
|
333
|
-
你肯定会希望启用 redis 缓存,因为它会持续调用`mo`命令。
|
|
334
|
-
|
|
335
|
-
## 镜像
|
|
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`命令将所有文件从一个手机复制到另一个手机。
|
|
344
|
-
随着时间的推移,它不会运行任何进程来维护镜像。再次运行`mirror`命令
|
|
345
|
-
同步任何丢失的文件。
|
|
346
|
-
|
|
347
|
-
`mirror`的返回值是一个简单的对象,带有多少个文件成功的计数器
|
|
348
|
-
镜像和有多少文件有错误:
|
|
349
|
-
|
|
350
|
-
{
|
|
351
|
-
success: count-of-files-mirrored,
|
|
352
|
-
errors: count-of-files-with-errors
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
警告:镜像大型数据集可能非常耗时且占用大量带宽
|
|
356
|
-
|
|
357
|
-
使用`mirror`调用语义有时会让人难以理解谁是
|
|
358
|
-
读者和作者是谁。把它想象成一个赋值语句:“左手手机”
|
|
359
|
-
是分配给的东西(写入的镜像数据),以及“右手的移动设备”(
|
|
360
|
-
`mirror`方法的参数)是分配的值(读取镜像数据)。
|
|
361
|
-
|
|
362
|
-
## 透明加密
|
|
363
|
-
启用透明客户端加密:
|
|
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
|
-
发生了什么?一个单独的“目录条目”(dirent)目录(加密)跟踪其中的文件
|
|
383
|
-
目录(又名dirent目录)。
|
|
384
|
-
* `list`命令读取目录入口文件,解密列出的每个路径;然后返回每个文件的元数据
|
|
385
|
-
* `list`命令效率较低,尤其是对于文件数量较多的目录
|
|
386
|
-
* `write`命令递归地在每个父目录的dirent 目录中写入dirent 文件;然后写入文件
|
|
387
|
-
* `write`命令将导致 O(N) 次写入,其中 N = 目录层次结构中的深度
|
|
388
|
-
* `remove`命令递归地删除相应的dirent文件及其父文件;然后删除文件
|
|
389
|
-
* 非递归的`remove`命令将导致 O(N) 次读取和可能的多次删除,其中 N = 目录层次结构中的深度
|
|
390
|
-
* 大型和深度文件系统上的递归`remove`命令可能很昂贵
|
|
391
|
-
|
|
392
|
-
请注意,即使启用了客户端加密,对手也可以完全了解您的加密服务器端
|
|
393
|
-
存储,即使没有密钥,仍然可以看到目录的总数以及每个目录中有多少文件,并且与
|
|
394
|
-
一些努力,发现部分或全部目录层次结构的整体结构。
|
|
395
|
-
*注意:使用相对扁平的结构以获得更好的安全性。*
|
|
396
|
-
对手不会知道目录/文件的名称,除非他们也知道您的加密
|
|
397
|
-
密钥或以其他方式成功破解了加密。那么所有的赌注都取消了!
|
|
398
|
-
|
|
399
|
-
### 性能和缓存
|
|
400
|
-
加密存储上的操作可能很慢。递归列表和删除可能非常缓慢。
|
|
401
|
-
通过 redis 进行缓存有很大帮助,但请注意缓存会在任何写入或删除时刷新。
|
|
402
|
-
|
|
403
|
-
## 密钥轮换
|
|
404
|
-
使用您的新密钥创建一个 mobiletto,然后将旧数据镜像到其中:
|
|
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
|
-
##驱动接口
|
|
417
|
-
驱动程序是任何使用此签名导出“storageClient”函数的 JS 文件:
|
|
418
|
-
|
|
419
|
-
function storageClient (key, secret, opts)
|
|
420
|
-
|
|
421
|
-
* `key` : 一个字符串,您的 API 密钥(对于`local`驱动程序,这是基本目录)
|
|
422
|
-
* `secret` : 一个字符串,您的 API 密码(对于`local`驱动程序可以省略)
|
|
423
|
-
* `opts` : 一个对象,属性是每个驱动程序:
|
|
424
|
-
* 对于`local` , `fileMode`和`dirMode`属性决定了如何创建新的创建文件和目录
|
|
425
|
-
* 对于`s3` ,需要`bucket`属性。可选属性是:
|
|
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
|
-
storageClient 函数返回的对象必须定义这些函数:
|
|
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
|
-
## 日志记录
|
|
457
|
-
Mobiletto 使用 [winston](https://www.npmjs.com/package/winston) 日志库。
|
|
458
|
-
|
|
459
|
-
日志**将**包含文件路径和错误消息,但**绝不**包含密钥、秘密、
|
|
460
|
-
或任何其他连接配置信息。
|
|
461
|
-
|
|
462
|
-
### 日志级别
|
|
463
|
-
使用`MOBILETTO_LOG_LEVEL`环境变量来设置日志级别,使用一个
|
|
464
|
-
在 [https://www.npmjs.com/package/winston#logging-levels](https://www.npmjs.com/package/winston#logging-levels) 中定义的`npm`级别
|
|
465
|
-
|
|
466
|
-
默认级别是`error` 。最详细的级别是`silly` ,虽然目前是 mobiletto
|
|
467
|
-
不在`debug`以下级别登录
|
|
468
|
-
|
|
469
|
-
MOBILETTO_LOG_LEVEL=silly # maximum logs!
|
|
470
|
-
|
|
471
|
-
### 日志文件
|
|
472
|
-
默认情况下,记录器写入控制台。要将日志发送到文件,请设置`MOBILETTO_LOG_FILE`
|
|
473
|
-
环境变量。记录到文件时,日志将不再写入控制台。
|
|
474
|
-
|
|
475
|
-
MOBILETTO_LOG_FILE=/var/my_mobiletto_log
|
|
476
|
-
|
|
477
|
-
要关闭日志记录:
|
|
478
|
-
|
|
479
|
-
MOBILETTO_LOG_FILE=/dev/null
|
|
480
|
-
|
|
481
|
-
</pre>
|