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.
Files changed (117) hide show
  1. package/README.md +56 -4
  2. package/docs/README.md +113 -0
  3. package/docs/af/README.md +455 -0
  4. package/docs/am/README.md +455 -0
  5. package/docs/ar/README.md +455 -0
  6. package/docs/az/README.md +455 -0
  7. package/docs/be/README.md +455 -0
  8. package/docs/bg/README.md +455 -0
  9. package/docs/bn/README.md +455 -0
  10. package/docs/bs/README.md +455 -0
  11. package/docs/ca/README.md +455 -0
  12. package/docs/ceb/README.md +455 -0
  13. package/docs/co/README.md +455 -0
  14. package/docs/cs/README.md +455 -0
  15. package/docs/cy/README.md +455 -0
  16. package/docs/da/README.md +455 -0
  17. package/docs/de/README.md +455 -0
  18. package/docs/el/README.md +455 -0
  19. package/docs/eo/README.md +455 -0
  20. package/docs/es/README.md +455 -0
  21. package/docs/et/README.md +455 -0
  22. package/docs/eu/README.md +455 -0
  23. package/docs/fa/README.md +455 -0
  24. package/docs/fi/README.md +455 -0
  25. package/docs/fr/README.md +455 -0
  26. package/docs/fy/README.md +455 -0
  27. package/docs/ga/README.md +455 -0
  28. package/docs/gd/README.md +455 -0
  29. package/docs/gl/README.md +455 -0
  30. package/docs/gu/README.md +455 -0
  31. package/docs/ha/README.md +455 -0
  32. package/docs/haw/README.md +455 -0
  33. package/docs/he/README.md +455 -0
  34. package/docs/hi/README.md +455 -0
  35. package/docs/hmn/README.md +455 -0
  36. package/docs/hr/README.md +455 -0
  37. package/docs/ht/README.md +455 -0
  38. package/docs/hu/README.md +455 -0
  39. package/docs/hy/README.md +455 -0
  40. package/docs/id/README.md +455 -0
  41. package/docs/ig/README.md +455 -0
  42. package/docs/is/README.md +455 -0
  43. package/docs/it/README.md +455 -0
  44. package/docs/iw/README.md +455 -0
  45. package/docs/ja/README.md +455 -0
  46. package/docs/jv/README.md +455 -0
  47. package/docs/ka/README.md +455 -0
  48. package/docs/kk/README.md +455 -0
  49. package/docs/km/README.md +455 -0
  50. package/docs/kn/README.md +455 -0
  51. package/docs/ko/README.md +455 -0
  52. package/docs/ku/README.md +455 -0
  53. package/docs/ky/README.md +455 -0
  54. package/docs/la/README.md +455 -0
  55. package/docs/lb/README.md +455 -0
  56. package/docs/lo/README.md +455 -0
  57. package/docs/lt/README.md +455 -0
  58. package/docs/lv/README.md +455 -0
  59. package/docs/mg/README.md +455 -0
  60. package/docs/mi/README.md +455 -0
  61. package/docs/mk/README.md +455 -0
  62. package/docs/ml/README.md +455 -0
  63. package/docs/mn/README.md +455 -0
  64. package/docs/mr/README.md +455 -0
  65. package/docs/ms/README.md +455 -0
  66. package/docs/mt/README.md +455 -0
  67. package/docs/my/README.md +455 -0
  68. package/docs/ne/README.md +455 -0
  69. package/docs/nl/README.md +455 -0
  70. package/docs/no/README.md +455 -0
  71. package/docs/ny/README.md +455 -0
  72. package/docs/or/README.md +455 -0
  73. package/docs/pa/README.md +455 -0
  74. package/docs/pl/README.md +455 -0
  75. package/docs/ps/README.md +455 -0
  76. package/docs/pt/README.md +455 -0
  77. package/docs/ro/README.md +455 -0
  78. package/docs/ru/README.md +455 -0
  79. package/docs/rw/README.md +455 -0
  80. package/docs/sd/README.md +455 -0
  81. package/docs/si/README.md +455 -0
  82. package/docs/sk/README.md +455 -0
  83. package/docs/sl/README.md +455 -0
  84. package/docs/sm/README.md +455 -0
  85. package/docs/sn/README.md +455 -0
  86. package/docs/so/README.md +455 -0
  87. package/docs/sq/README.md +455 -0
  88. package/docs/sr/README.md +455 -0
  89. package/docs/st/README.md +455 -0
  90. package/docs/su/README.md +455 -0
  91. package/docs/sv/README.md +455 -0
  92. package/docs/sw/README.md +455 -0
  93. package/docs/ta/README.md +455 -0
  94. package/docs/te/README.md +455 -0
  95. package/docs/tg/README.md +455 -0
  96. package/docs/th/README.md +455 -0
  97. package/docs/tk/README.md +455 -0
  98. package/docs/tl/README.md +455 -0
  99. package/docs/tr/README.md +455 -0
  100. package/docs/tt/README.md +455 -0
  101. package/docs/ug/README.md +455 -0
  102. package/docs/uk/README.md +455 -0
  103. package/docs/ur/README.md +455 -0
  104. package/docs/uz/README.md +455 -0
  105. package/docs/vi/README.md +455 -0
  106. package/docs/xh/README.md +455 -0
  107. package/docs/yi/README.md +455 -0
  108. package/docs/yo/README.md +455 -0
  109. package/docs/zh/README.md +455 -0
  110. package/docs/zu/README.md +455 -0
  111. package/drivers/b2/index.js +24 -6
  112. package/hokey.json +16 -0
  113. package/index.js +33 -17
  114. package/package.json +3 -2
  115. package/test/api.spec.js +319 -306
  116. package/util/logger.js +1 -1
  117. package/util/redis.js +1 -1
@@ -0,0 +1,455 @@
1
+ โมบิลเล็ตโต
2
+ =========
3
+
4
+ Mobiletto เป็นเลเยอร์นามธรรมของการจัดเก็บ JavaScript พร้อมการเข้ารหัสฝั่งไคลเอ็นต์แบบโปร่งใสที่เป็นตัวเลือก
5
+
6
+ # เนื้อหา
7
+ * [ทำไมต้องโมบิลเล็ต](#ทำไม-โมบิลเล็ตโต?)
8
+ * [เริ่มด่วน](#เริ่มด่วน)
9
+ * [โมบิลเล็ตโต CLI](#mobiletto-cli)
10
+ * [ที่มา](#แหล่งที่มา)
11
+ * [การใช้งานพื้นฐาน](#Basic-usage)
12
+ * [ข้อมูลเมตา](#ข้อมูลเมตา)
13
+ * [รูปแบบการนำเข้าสำรอง](#Alternate-import-style)
14
+ * [แคช](#แคช)
15
+ * [มิเรอร์](#มิเรอร์)
16
+ * [การเข้ารหัสแบบโปร่งใส](#การเข้ารหัสแบบโปร่งใส)
17
+ * [การหมุนแป้น](#การหมุนแป้น)
18
+ * [ส่วนต่อประสานคนขับ](#ส่วนต่อประสานคนขับ)
19
+ * [การบันทึก](#การบันทึก)
20
+
21
+ #อ่านเป็นภาษาอื่น
22
+ เอกสาร README.md นี้ได้รับการแปลผ่าน [hokeylization](https://github.com/cobbzilla/hokeylization) ลงใน
23
+ **[ทุกภาษาที่ Google Translate รองรับ](https://cloud.google.com/translate/docs/languages)!**
24
+
25
+ ฉันแน่ใจว่ามันไม่สมบูรณ์แบบ แต่ฉันหวังว่าจะดีกว่าไม่ทำอะไรเลย!
26
+
27
+ [🇸🇦 ภาษาอาหรับ](../ar/README.md)
28
+ [🇧🇩 เบงกาลี](../bn/README.md)
29
+ [🇩🇪 ภาษาเยอรมัน](../de/README.md)
30
+ [🇺🇸 ภาษาอังกฤษ](../th/README.md)
31
+ [🇪🇸 ภาษาสเปน](../es/README.md)
32
+ [🇫🇷 ภาษาฝรั่งเศส](../fr/README.md)
33
+ [🇹🇩 เฮาซา](../ha/README.md)
34
+ [🇮🇳 ภาษาฮินดี](../hi/README.md)
35
+ [🇮🇩 ภาษาชาวอินโดนีเซีย](../id/README.md)
36
+ [🇮🇹 ภาษาอิตาลี](../it/README.md)
37
+ [🇯🇵 ภาษาญี่ปุ่น](../ja/README.md)
38
+ [🇰🇷 ภาษาเกาหลี](../ko/README.md)
39
+ [🇮🇳 มารันตี](../mr/README.md)
40
+ [🇵🇱 โปแลนด์](../pl/README.md)
41
+ [🇧🇷 ภาษาโปรตุเกส](../pt/README.md)
42
+ [🇷🇺 ภาษารัสเซีย](../ru/README.md)
43
+ [🇰🇪 สวาฮีลี](../sw/README.md)
44
+ [🇵🇭 ภาษาตากาล็อก](../tl/README.md)
45
+ [🇹🇷 ภาษาตุรกี](../tr/README.md)
46
+ [🇵🇰 ภาษาอูรดู](../ur/README.md)
47
+ [🇻🇳 ภาษาเวียดนาม](../vi/README.md)
48
+ [🇨🇳 ภาษาจีน](../zh/README.md)
49
+
50
+
51
+ **[📚 ...ทุกภาษา ...](../README.md)**
52
+ ----
53
+
54
+ ### มีปัญหากับการแปล README นี้หรือไม่?
55
+ การแปลเฉพาะของต้นฉบับ [README](https://github.com/cobbzilla/mobiletto/blob/master/README.md)
56
+ อาจมีข้อบกพร่อง -- *ยินดีเป็นอย่างยิ่งที่จะแก้ไข!* โปรดส่ง [pull request บน GitHub](https://github.com/cobbzilla/mobiletto/pulls)
57
+ หรือหากคุณไม่สะดวกใจที่จะทำเช่นนั้น [เปิดประเด็น](https://github.com/cobbzilla/mobiletto/issues)
58
+
59
+ เมื่อคุณสร้างปัญหา GitHub ใหม่เกี่ยวกับการแปล โปรดทำดังนี้
60
+ * รวม URL ของหน้า (คัดลอก/วางจากแถบที่อยู่ของเบราว์เซอร์)
61
+ * รวมข้อความที่ไม่ถูกต้อง (คัดลอก/วางจากเบราว์เซอร์)
62
+ * โปรดอธิบายสิ่งที่ผิด -- การแปลไม่ถูกต้องหรือไม่? การจัดรูปแบบเสียอย่างใด?
63
+ *กรุณาเสนอคำแนะนำในการแปลที่ดีขึ้น หรือควรจัดรูปแบบข้อความอย่างไรให้เหมาะสม
64
+ * **ขอขอบคุณ!**
65
+
66
+ ## ทำไมต้องโมบิลเล็ตโต?
67
+
68
+ ### ลาก่อนล็อคอินผู้ขาย!
69
+ ผู้ให้บริการพื้นที่เก็บข้อมูลบนคลาวด์หลายรายมี API ที่เข้ากันไม่ได้ แม้แต่ผู้ที่มุ่งมั่นเพื่อ "ความเข้ากันได้ของ S3"
70
+ มีพฤติกรรมแปลกแยก
71
+
72
+ เมื่อคุณเลือกผู้จำหน่ายพื้นที่จัดเก็บข้อมูลเฉพาะสำหรับแอปของคุณ หากคุณเขียนโค้ดไปยัง API ของพวกเขาโดยตรง แอปของคุณก็จะ
73
+ ตอนนี้ขึ้นอยู่กับบริการนั้น เมื่อเวลาผ่านไปและรหัสสะสม ผู้ขายที่เปลี่ยนแปลงจะกลายเป็น
74
+ ไม่สามารถป้องกันได้มากขึ้น ยินดีต้อนรับสู่โลกแห่งความสนุกของการล็อคอินผู้ขาย!
75
+
76
+ โมบิลเล็ตโตถูกออกแบบมาเพื่อแก้ปัญหานี้ โดยการเข้ารหัสแอปของคุณไปยัง API ของ mobiletto คุณสามารถได้อย่างง่ายดาย
77
+ เปลี่ยนผู้ให้บริการพื้นที่เก็บข้อมูลและรู้ว่าชั้นพื้นที่เก็บข้อมูลของแอปจะทำงานเหมือนกัน
78
+
79
+ ### การทดสอบอย่างละเอียด
80
+ ไดรเวอร์ทั้งหมดได้รับการทดสอบสำหรับพฤติกรรมที่เหมือนกันด้วยการทดสอบมากกว่า 60 รายการสำหรับไดรเวอร์แต่ละตัว
81
+ เราทดสอบไดรเวอร์ทั้งหมดด้วยการรวมกันของ:
82
+ * การเข้ารหัส: ทั้งเปิดใช้งานและปิดใช้งาน
83
+ * แคช Redis: ทั้งเปิดใช้งานและปิดใช้งาน
84
+
85
+ วิธีนี้ช่วยให้เราสบายใจได้ว่า mobiletto จะทำงานเหมือนกันไม่ว่าคุณจะใช้ไดรเวอร์ใด
86
+ และไม่ว่าคุณจะเปิดใช้งานการแคชและ/หรือการเข้ารหัสก็ตาม
87
+
88
+ ### การสนับสนุนไดรเวอร์
89
+ ไดรเวอร์การจัดเก็บข้อมูล Mobileetto ปัจจุบัน:
90
+ * `s3` : อเมซอน S3
91
+ * `b2` b2' : แบ็คเบลซ B2
92
+ * `local` : ระบบไฟล์ในเครื่อง
93
+
94
+ *ยินดีเป็นอย่างยิ่งที่ให้การสนับสนุนผู้ให้บริการพื้นที่เก็บข้อมูลบนคลาวด์มากขึ้น!*
95
+
96
+ ## mobiletto-คลิ
97
+ Mobiletto มีวัตถุประสงค์เพื่อใช้เป็นห้องสมุดโดยโค้ด JavaScript อื่น
98
+
99
+ หากต้องการทำงานกับ mobiletto ที่บรรทัดคำสั่ง ให้ใช้ [mobiletto-cli](https://www.npmjs.com/package/mobiletto-cli)
100
+
101
+ ## แหล่งที่มา
102
+ * [mobiletto บน GitHub](https://github.com/cobbzilla/mobiletto)
103
+ * [mobiletto บน npm](https://www.npmjs.com/package/mobiletto)
104
+
105
+ ## เริ่มต้นอย่างรวดเร็ว
106
+ ตัวอย่างสั้นๆ โดยใช้ไดรเวอร์ mobiletto `s3`
107
+
108
+ รหัสนี้จะทำงานเหมือนกันหากไดรเวอร์เป็น `b2` b2' หรือ `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
+ ## การใช้งานพื้นฐาน
139
+ ตัวอย่างที่กว้างกว่ามาก ซึ่งแสดงคุณสมบัติส่วนใหญ่ที่มีให้:
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
+ ## ข้อมูลเมตา
241
+ คำสั่ง `metadata` ส่งคืนข้อมูลเมตาเกี่ยวกับรายการระบบไฟล์เดียว
242
+ ค่าที่ส่งคืนจากคำสั่ง `list` ก็คืออาร์เรย์ของออบเจ็กต์ข้อมูลเมตา
243
+
244
+ ออบเจ็กต์ข้อมูลเมตามีลักษณะดังนี้:
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` สามารถเป็น `file` , `dir` , `link` หรือ `special`
255
+
256
+ ขึ้นอยู่กับประเภทของไดรเวอร์ คำสั่ง `list` อาจไม่ส่งคืนฟิลด์ทั้งหมด คุณสมบัติ `name` และ `type`
257
+ ควรมีอยู่เสมอ คำสั่ง `metadata` ที่ตามมาจะส่งคืนคุณสมบัติที่มีอยู่ทั้งหมด
258
+
259
+ ## รูปแบบการนำเข้าสำรอง
260
+ นำเข้าโมดูลที่มีขอบเขตครบถ้วนและใช้ฟังก์ชัน `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
+ ## เก็บเอาไว้
268
+ Mobiletto ทำงานได้ดีที่สุดกับแคช <a href="https://redis.io">redis</a>
269
+
270
+ Mobiletto จะพยายามเชื่อมต่อกับอินสแตนซ์ redis บน 127.0.0.1:6379
271
+
272
+ คุณสามารถลบล้างสิ่งเหล่านี้ได้:
273
+ * ตั้งค่า `MOBILETTO_REDIS_HOST` env var, mobiletto เชื่อมต่อที่นี่แทน localhost
274
+ * ตั้งค่า `MOBILETTO_REDIS_PORT` env var พอร์ตนี้จะถูกใช้
275
+
276
+ Mobiletto จะเก็บคีย์ Redis ทั้งหมดที่มีคำนำหน้า `_mobiletto__` เปลี่ยนได้
277
+ โดยการตั้งค่า `MOBILETTO_REDIS_PREFIX` env var
278
+
279
+ คุณยังสามารถตั้งค่าการแคชต่อการเชื่อมต่อด้วย `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
+ ### ไม่ต้องการแคช redis?
291
+ วิธีปิดการใช้งาน: ผ่าน `enabled: false` ' ในออบเจกต์ `opts.redisConfig` เมื่อคุณสร้างการเชื่อมต่อของคุณ
292
+
293
+ ตามที่กล่าวไว้ด้านล่าง การปิดใช้งานการแคชจะส่งผลเสียต่อประสิทธิภาพการทำงานและก่อให้เกิดคำขอมากขึ้น
294
+ เพื่อการจัดเก็บที่คุณต้องการจริงๆ
295
+
296
+ ### คำแนะนำในการแคช
297
+ **ที่เก็บข้อมูลที่เข้ารหัส**: การอ่าน/เขียนที่เก็บข้อมูลที่เข้ารหัสนั้นช้ากว่าปกติเพียงเล็กน้อย
298
+ แต่การนำทางไปรอบๆ ไดเร็กทอรี (ซึ่งบางอย่างทำ) นั้นค่อนข้างแพง การใช้แคช redis
299
+ จะช่วยเพิ่มประสิทธิภาพให้กับคุณอย่างมาก
300
+
301
+ แคชเริ่มต้นนั้นปลอดภัย แต่ทำงานได้ไม่ดีหากคุณมีการดำเนินการเขียน/ลบจำนวนมาก
302
+ การดำเนินการเขียนหรือลบจะทำให้แคชทั้งหมดใช้งานไม่ได้ เพื่อให้แน่ใจว่าการอ่านครั้งต่อๆ ไปจะเห็น
303
+ การเปลี่ยนแปลงล่าสุด
304
+
305
+ ### เครื่องมือ CLI
306
+ หากคุณกำลังใช้เครื่องมือ CLI เช่น [mobiletto-cli](https://www.npmjs.com/package/mobiletto-cli)
307
+ คุณจะต้องเปิดใช้งานแคช redis อย่างแน่นอน เนื่องจากจะคงอยู่ตลอดการเรียกใช้คำสั่ง `mo`
308
+
309
+ ## มิเรอร์
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
+ คำสั่ง `mirror` ทำสำเนาไฟล์ทั้งหมดจาก mobiletto หนึ่งไปยังอีกไฟล์หนึ่งเพียงครั้งเดียว
318
+ จะไม่เรียกใช้กระบวนการใดๆ เพื่อรักษามิเรอร์เมื่อเวลาผ่านไป เรียกใช้คำสั่ง `mirror` อีกครั้ง
319
+ เพื่อซิงโครไนซ์ไฟล์ที่ขาดหายไป
320
+
321
+ ค่าที่ส่งคืนจาก `mirror` เป็นอ็อบเจ็กต์ธรรมดาที่มีตัวนับจำนวนไฟล์ที่สำเร็จ
322
+ มิเรอร์และจำนวนไฟล์ที่มีข้อผิดพลาด:
323
+
324
+ {
325
+ success: count-of-files-mirrored,
326
+ errors: count-of-files-with-errors
327
+ }
328
+
329
+ คำเตือน: การทำมิเรอร์ชุดข้อมูลขนาดใหญ่อาจใช้เวลานานและใช้แบนด์วิดท์มาก
330
+
331
+ ด้วยความหมายของการเรียก `mirror` บางครั้งอาจสับสนที่จะเข้าใจว่าใครคือ
332
+ ผู้อ่านและใครเป็นนักเขียน ลองนึกภาพมันเหมือนคำสั่งมอบหมาย: "มือซ้าย mobiletto"
333
+ เป็นสิ่งที่ถูกกำหนดให้ (เขียนข้อมูลสะท้อน) และ "มือขวา mobiletto" (the
334
+ อาร์กิวเมนต์ของวิธี `mirror` ) คือค่าที่กำหนด (อ่านข้อมูลที่มิเรอร์)
335
+
336
+ ## การเข้ารหัสที่โปร่งใส
337
+ เปิดใช้งานการเข้ารหัสฝั่งไคลเอ็นต์แบบโปร่งใส:
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
+ เกิดอะไรขึ้น? ไดเร็กทอรี "รายการไดเร็กทอรี" (ไดเร็กทอรี) แยกต่างหาก (เข้ารหัส) ติดตามว่าไฟล์ใดบ้างที่อยู่ในนั้น
357
+ ไดเร็กทอรี (aka ไดเร็กทอรีไดเร็กทอรี)
358
+ * คำสั่ง `list` อ่านไฟล์รายการไดเร็กทอรี ถอดรหัสแต่ละพาธที่แสดง จากนั้นส่งคืนข้อมูลเมตาสำหรับแต่ละไฟล์
359
+ * คำสั่ง `list` นั้นไม่มีประสิทธิภาพมากกว่า โดยเฉพาะสำหรับไดเร็กทอรีที่มีไฟล์จำนวนมาก
360
+ * คำสั่ง `write` เขียนไฟล์ dirent ในไดเร็กทอรี dirent ของผู้ปกครองแต่ละรายซ้ำ ๆ แล้วเขียนไฟล์
361
+ * คำสั่ง `write` จะต้องเขียน O(N) โดยที่ N = ความลึกในลำดับชั้นของไดเร็กทอรี
362
+ * คำสั่ง `remove` จะลบไฟล์ dirent ที่เกี่ยวข้อง และพาเรนต์ของไฟล์นั้น ถ้าว่าง ให้เรียกซ้ำ แล้วลบไฟล์
363
+ * คำสั่ง `remove` แบบไม่เรียกซ้ำจะทำให้มีการอ่าน O(N) และอาจมีการลบได้มาก โดยที่ N = ความลึกในลำดับชั้นของไดเร็กทอรี
364
+ * คำสั่ง `remove` แบบเรียกซ้ำบนระบบไฟล์ขนาดใหญ่และลึกอาจมีราคาแพง
365
+
366
+ โปรดทราบว่าแม้จะเปิดใช้งานการเข้ารหัสฝั่งไคลเอ็นต์ ศัตรูที่มองเห็นได้อย่างสมบูรณ์ในฝั่งเซิร์ฟเวอร์ที่เข้ารหัสของคุณ
367
+ ที่เก็บข้อมูลแม้จะไม่มีคีย์ก็ยังสามารถดูจำนวนไดเร็กทอรีทั้งหมดและจำนวนไฟล์ในแต่ละไฟล์และด้วย
368
+ พยายามค้นหาโครงสร้างโดยรวมบางส่วนหรือทั้งหมดของลำดับชั้นของไดเร็กทอรี
369
+ *หมายเหตุ: ใช้โครงสร้างที่ค่อนข้างเรียบเพื่อความปลอดภัยที่ดีขึ้น*
370
+ ฝ่ายตรงข้ามจะไม่รู้จักชื่อไดเร็กทอรี/ไฟล์ เว้นแต่พวกเขาจะรู้การเข้ารหัสของคุณ
371
+ คีย์หรือถอดรหัสได้สำเร็จ เดิมพันทั้งหมดจะปิดแล้ว!
372
+
373
+ ### ประสิทธิภาพและการแคช
374
+ การดำเนินการกับที่เก็บข้อมูลที่เข้ารหัสอาจช้า รายชื่อและการลบแบบเรียกซ้ำอาจช้ามาก
375
+ การแคชผ่าน redis ช่วยได้มาก แต่โปรดทราบว่าแคชจะถูกล้างเมื่อเขียนหรือลบออก
376
+
377
+ ## การหมุนกุญแจ
378
+ สร้าง mobiletto ด้วยรหัสใหม่ของคุณ จากนั้นจำลองข้อมูลเก่าเข้าไป:
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
+ ## อินเทอร์เฟซไดรเวอร์
391
+ ไดรเวอร์คือไฟล์ JS ใดๆ ที่ส่งออกฟังก์ชัน 'storageClient' ด้วยลายเซ็นนี้:
392
+
393
+ function storageClient (key, secret, opts)
394
+
395
+ * `key` : สตริง คีย์ API ของคุณ (สำหรับไดรเวอร์ `local` ในเครื่อง' นี่คือไดเร็กทอรีฐาน)
396
+ * `secret` : สตริง, ความลับ API ของคุณ (สามารถละเว้นสำหรับไดรเวอร์ `local` )
397
+ * `opts` : วัตถุ คุณสมบัติเป็นต่อไดรเวอร์:
398
+ * สำหรับ `local` คุณสมบัติ `fileMode` และ `dirMode` จะกำหนดวิธีการสร้างไฟล์และไดเร็กทอรีใหม่
399
+ * สำหรับ `s3` ' จำเป็นต้องมีคุณสมบัติ `bucket` คุณสมบัติเสริมคือ:
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
+ ออบเจ็กต์ที่ฟังก์ชัน storageClient ส่งคืนต้องกำหนดฟังก์ชันเหล่านี้:
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
+ ## การบันทึก
431
+ Mobiletto ใช้ไลบรารีการบันทึก [winston](https://www.npmjs.com/package/winston)
432
+
433
+ บันทึก **จะ** มีเส้นทางของไฟล์และข้อความแสดงข้อผิดพลาด แต่จะ ** ไม่มี ** มีคีย์ ความลับ
434
+ หรือข้อมูลการกำหนดค่าการเชื่อมต่ออื่นๆ
435
+
436
+ ### ระดับบันทึก
437
+ ใช้ตัวแปรสภาพแวดล้อม `MOBILETTO_LOG_LEVEL` เพื่อตั้งค่าระดับการบันทึก โดยใช้ one
438
+ ของระดับ `npm` ที่กำหนดไว้ใน [https://www.npmjs.com/package/winston#logging-levels](https://www.npmjs.com/package/winston#logging-levels)
439
+
440
+ ระดับเริ่มต้นคือ `error` ระดับที่ละเอียดที่สุดคือ `silly` ถึงแม้ว่าขณะนี้ mobiletto
441
+ ไม่บันทึกที่ระดับต่ำกว่า `debug`
442
+
443
+ MOBILETTO_LOG_LEVEL=silly # maximum logs!
444
+
445
+ ### ไฟล์บันทึก
446
+ โดยค่าเริ่มต้น ตัวบันทึกจะเขียนไปยังคอนโซล ในการส่งบันทึกไปยังไฟล์ ให้ตั้งค่า `MOBILETTO_LOG_FILE`
447
+ ตัวแปรสภาพแวดล้อม เมื่อเข้าสู่ไฟล์ บันทึกจะไม่ถูกเขียนลงในคอนโซลอีกต่อไป
448
+
449
+ MOBILETTO_LOG_FILE=/var/my_mobiletto_log
450
+
451
+ ในการปิดการบันทึก:
452
+
453
+ MOBILETTO_LOG_FILE=/dev/null
454
+
455
+ </pre>