@spcsn/taro 0.1.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.
Files changed (140) hide show
  1. package/README.md +12 -0
  2. package/dist/index.js +147 -0
  3. package/dist/index.js.map +1 -0
  4. package/index.js +9 -0
  5. package/package.json +86 -0
  6. package/types/api/ad/index.d.ts +197 -0
  7. package/types/api/ai/face.d.ts +133 -0
  8. package/types/api/ai/inference.d.ts +129 -0
  9. package/types/api/ai/visionkit.d.ts +874 -0
  10. package/types/api/alipay/index.d.ts +69 -0
  11. package/types/api/base/crypto.d.ts +104 -0
  12. package/types/api/base/debug.d.ts +329 -0
  13. package/types/api/base/env.d.ts +19 -0
  14. package/types/api/base/index.d.ts +102 -0
  15. package/types/api/base/performance.d.ts +258 -0
  16. package/types/api/base/system.d.ts +742 -0
  17. package/types/api/base/update.d.ts +130 -0
  18. package/types/api/base/weapp/app-event.d.ts +265 -0
  19. package/types/api/base/weapp/life-cycle.d.ts +155 -0
  20. package/types/api/canvas/index.d.ts +2162 -0
  21. package/types/api/cloud/index.d.ts +2622 -0
  22. package/types/api/data-analysis/index.d.ts +122 -0
  23. package/types/api/device/accelerometer.d.ts +102 -0
  24. package/types/api/device/accessibility.d.ts +26 -0
  25. package/types/api/device/battery.d.ts +46 -0
  26. package/types/api/device/bluetooth-ble.d.ts +601 -0
  27. package/types/api/device/bluetooth-peripheral.d.ts +430 -0
  28. package/types/api/device/bluetooth.d.ts +463 -0
  29. package/types/api/device/calendar.d.ts +98 -0
  30. package/types/api/device/clipboard.d.ts +81 -0
  31. package/types/api/device/compass.d.ts +105 -0
  32. package/types/api/device/contact.d.ts +110 -0
  33. package/types/api/device/gyroscope.d.ts +85 -0
  34. package/types/api/device/iBeacon.d.ts +168 -0
  35. package/types/api/device/keyboard.d.ts +97 -0
  36. package/types/api/device/memory.d.ts +52 -0
  37. package/types/api/device/motion.d.ts +88 -0
  38. package/types/api/device/network.d.ts +172 -0
  39. package/types/api/device/nfc.d.ts +1238 -0
  40. package/types/api/device/phone.d.ts +30 -0
  41. package/types/api/device/scan.d.ts +111 -0
  42. package/types/api/device/screen.d.ts +217 -0
  43. package/types/api/device/sms.d.ts +26 -0
  44. package/types/api/device/vibrate.d.ts +51 -0
  45. package/types/api/device/wifi.d.ts +301 -0
  46. package/types/api/ext/index.d.ts +64 -0
  47. package/types/api/files/index.d.ts +1472 -0
  48. package/types/api/framework/index.d.ts +51 -0
  49. package/types/api/location/index.d.ts +517 -0
  50. package/types/api/media/audio.d.ts +1013 -0
  51. package/types/api/media/background-audio.d.ts +291 -0
  52. package/types/api/media/camera.d.ts +207 -0
  53. package/types/api/media/editor.d.ts +239 -0
  54. package/types/api/media/image.d.ts +469 -0
  55. package/types/api/media/live.d.ts +461 -0
  56. package/types/api/media/map.d.ts +638 -0
  57. package/types/api/media/media-recorder.d.ts +117 -0
  58. package/types/api/media/recorder.d.ts +317 -0
  59. package/types/api/media/video-decoder.d.ts +117 -0
  60. package/types/api/media/video-processing.d.ts +84 -0
  61. package/types/api/media/video.d.ts +527 -0
  62. package/types/api/media/voip.d.ts +393 -0
  63. package/types/api/navigate/index.d.ts +327 -0
  64. package/types/api/network/download.d.ts +173 -0
  65. package/types/api/network/mdns.d.ts +191 -0
  66. package/types/api/network/request.d.ts +480 -0
  67. package/types/api/network/tcp.d.ts +181 -0
  68. package/types/api/network/udp.d.ts +218 -0
  69. package/types/api/network/upload.d.ts +201 -0
  70. package/types/api/network/websocket.d.ts +383 -0
  71. package/types/api/open-api/account.d.ts +51 -0
  72. package/types/api/open-api/address.d.ts +68 -0
  73. package/types/api/open-api/authorize.d.ts +80 -0
  74. package/types/api/open-api/card.d.ts +110 -0
  75. package/types/api/open-api/channels.d.ts +225 -0
  76. package/types/api/open-api/customer-service.d.ts +45 -0
  77. package/types/api/open-api/device-voip.d.ts +103 -0
  78. package/types/api/open-api/facial.d.ts +98 -0
  79. package/types/api/open-api/favorites.d.ts +101 -0
  80. package/types/api/open-api/group.d.ts +59 -0
  81. package/types/api/open-api/invoice.d.ts +87 -0
  82. package/types/api/open-api/license-plate.d.ts +27 -0
  83. package/types/api/open-api/login.d.ts +115 -0
  84. package/types/api/open-api/my-miniprogram.d.ts +28 -0
  85. package/types/api/open-api/privacy.d.ts +107 -0
  86. package/types/api/open-api/redpackage.d.ts +24 -0
  87. package/types/api/open-api/settings.d.ts +174 -0
  88. package/types/api/open-api/soter.d.ts +184 -0
  89. package/types/api/open-api/sticker.d.ts +83 -0
  90. package/types/api/open-api/subscribe-message.d.ts +305 -0
  91. package/types/api/open-api/user-info.d.ts +182 -0
  92. package/types/api/open-api/werun.d.ts +101 -0
  93. package/types/api/payment/index.d.ts +119 -0
  94. package/types/api/qq/index.d.ts +354 -0
  95. package/types/api/route/index.d.ts +324 -0
  96. package/types/api/share/index.d.ts +354 -0
  97. package/types/api/skyline/index.d.ts +345 -0
  98. package/types/api/storage/background-fetch.d.ts +131 -0
  99. package/types/api/storage/cache-manager.d.ts +249 -0
  100. package/types/api/storage/index.d.ts +405 -0
  101. package/types/api/swan/bookshelf.d.ts +307 -0
  102. package/types/api/swan/download-package.d.ts +80 -0
  103. package/types/api/swan/index.d.ts +251 -0
  104. package/types/api/swan/pay.d.ts +139 -0
  105. package/types/api/taro.extend.d.ts +233 -0
  106. package/types/api/taro.hooks.d.ts +148 -0
  107. package/types/api/ui/animation.d.ts +427 -0
  108. package/types/api/ui/background.d.ts +69 -0
  109. package/types/api/ui/custom-component.d.ts +23 -0
  110. package/types/api/ui/fonts.d.ts +77 -0
  111. package/types/api/ui/interaction.d.ts +281 -0
  112. package/types/api/ui/menu.d.ts +29 -0
  113. package/types/api/ui/navigation-bar.d.ts +130 -0
  114. package/types/api/ui/pull-down-refresh.d.ts +50 -0
  115. package/types/api/ui/scroll.d.ts +114 -0
  116. package/types/api/ui/sticky.d.ts +32 -0
  117. package/types/api/ui/tab-bar.d.ts +196 -0
  118. package/types/api/ui/window.d.ts +71 -0
  119. package/types/api/worker/index.d.ts +83 -0
  120. package/types/api/wxml/index.d.ts +540 -0
  121. package/types/compile/compiler.d.ts +32 -0
  122. package/types/compile/config/h5.d.ts +134 -0
  123. package/types/compile/config/harmony.d.ts +118 -0
  124. package/types/compile/config/index.d.ts +8 -0
  125. package/types/compile/config/manifest.d.ts +155 -0
  126. package/types/compile/config/mini.d.ts +118 -0
  127. package/types/compile/config/plugin.d.ts +34 -0
  128. package/types/compile/config/project.d.ts +338 -0
  129. package/types/compile/config/rn.d.ts +85 -0
  130. package/types/compile/config/util.d.ts +179 -0
  131. package/types/compile/hooks.d.ts +13 -0
  132. package/types/compile/index.d.ts +11 -0
  133. package/types/compile/viteCompilerContext.d.ts +167 -0
  134. package/types/global.d.ts +428 -0
  135. package/types/index.d.ts +190 -0
  136. package/types/taro.api.d.ts +130 -0
  137. package/types/taro.component.d.ts +168 -0
  138. package/types/taro.config.d.ts +712 -0
  139. package/types/taro.lifecycle.d.ts +220 -0
  140. package/types/taro.runtime.d.ts +9 -0
@@ -0,0 +1,1472 @@
1
+ import Taro from '../../index'
2
+
3
+ declare module '../../index' {
4
+ namespace saveFileToDisk {
5
+ interface Option {
6
+ /** 待保存文件路径 */
7
+ filePath: string
8
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
9
+ complete?: (res: TaroGeneral.CallbackResult) => void
10
+ /** 接口调用失败的回调函数 */
11
+ fail?: (result: TaroGeneral.CallbackResult) => void
12
+ /** 接口调用成功的回调函数 */
13
+ success?: (result: TaroGeneral.CallbackResult) => void
14
+ }
15
+ }
16
+
17
+ namespace saveFile {
18
+ interface Option {
19
+ /** 临时存储文件路径 */
20
+ tempFilePath: string
21
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
22
+ complete?: (res: TaroGeneral.CallbackResult) => void
23
+ /** 接口调用失败的回调函数 */
24
+ fail?: (result: FailCallbackResult) => void
25
+ /** 要存储的文件路径 */
26
+ filePath?: string
27
+ /** 要保存的本地临时文件路径
28
+ * @supported alipay
29
+ */
30
+ apFilePath?: string
31
+ /** 接口调用成功的回调函数 */
32
+ success?: (result: SuccessCallbackResult) => void
33
+ }
34
+ interface FailCallbackResult extends TaroGeneral.CallbackResult {
35
+ /** 错误信息
36
+ *
37
+ * 可选值:
38
+ * - 'fail tempFilePath file not exist': 指定的 tempFilePath 找不到文件;
39
+ * - 'fail permission denied, open "${filePath}"': 指定的 filePath 路径没有写权限;
40
+ * - 'fail no such file or directory "${dirPath}"': 上级目录不存在;
41
+ * - 'fail the maximum size of the file storage limit is exceeded': 存储空间不足; */
42
+ errMsg: string
43
+ }
44
+ interface SuccessCallbackResult extends TaroGeneral.CallbackResult {
45
+ /** 存储后的文件路径 */
46
+ savedFilePath: string
47
+ /** 调用结果 */
48
+ errMsg: string
49
+ }
50
+ }
51
+
52
+ namespace removeSavedFile {
53
+ interface Option {
54
+ /** 需要删除的文件路径 */
55
+ filePath: string
56
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
57
+ complete?: (res: TaroGeneral.CallbackResult) => void
58
+ /** 接口调用失败的回调函数 */
59
+ fail?: (res: TaroGeneral.CallbackResult) => void
60
+ /** 接口调用成功的回调函数 */
61
+ success?: (res: TaroGeneral.CallbackResult) => void
62
+ }
63
+ interface RemoveSavedFileFailCallbackResult extends TaroGeneral.CallbackResult {
64
+ /** 错误信息
65
+ *
66
+ * 可选值:
67
+ * - 'fail file not exist': 指定的 tempFilePath 找不到文件; */
68
+ errMsg: string
69
+ }
70
+ }
71
+
72
+ namespace openDocument {
73
+ interface Option {
74
+ /** 文件路径,可通过 downloadFile 获得 */
75
+ filePath: string
76
+ /** 是否显示右上角菜单 */
77
+ showMenu?: boolean
78
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
79
+ complete?: (res: TaroGeneral.CallbackResult) => void
80
+ /** 接口调用失败的回调函数 */
81
+ fail?: (res: TaroGeneral.CallbackResult) => void
82
+ /** 文件类型,指定文件类型打开文件 */
83
+ fileType?: keyof FileType
84
+ /** 接口调用成功的回调函数 */
85
+ success?: (res: TaroGeneral.CallbackResult) => void
86
+ }
87
+ /** 文件类型 */
88
+ interface FileType {
89
+ /** doc 格式 */
90
+ doc
91
+ /** docx 格式 */
92
+ docx
93
+ /** xls 格式 */
94
+ xls
95
+ /** xlsx 格式 */
96
+ xlsx
97
+ /** ppt 格式 */
98
+ ppt
99
+ /** pptx 格式 */
100
+ pptx
101
+ /** pdf 格式 */
102
+ pdf
103
+ }
104
+ }
105
+
106
+ namespace getSavedFileList {
107
+ interface Option {
108
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
109
+ complete?: (res: TaroGeneral.CallbackResult) => void
110
+ /** 接口调用失败的回调函数 */
111
+ fail?: (res: TaroGeneral.CallbackResult) => void
112
+ /** 接口调用成功的回调函数 */
113
+ success?: (result: SuccessCallbackResult) => void
114
+ }
115
+ interface SuccessCallbackResult extends TaroGeneral.CallbackResult {
116
+ /** 文件数组 */
117
+ fileList: FileItem[]
118
+ /** 调用结果 */
119
+ errMsg: string
120
+ }
121
+ /** 文件数组 */
122
+ interface FileItem {
123
+ /** 文件保存时的时间戳,从1970/01/01 08:00:00 到当前时间的秒数 */
124
+ createTime: number
125
+ /** 本地路径 */
126
+ filePath: string
127
+ /** 文件路径
128
+ * @supported alipay
129
+ */
130
+ apFilePath?: string
131
+ /** 本地文件大小,以字节为单位 */
132
+ size: number
133
+ }
134
+ }
135
+
136
+ namespace getSavedFileInfo {
137
+ interface Option {
138
+ /** 文件路径 */
139
+ filePath: string
140
+ /** 文件路径
141
+ * @supported alipay
142
+ */
143
+ apFilePath?: string
144
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
145
+ complete?: (res: TaroGeneral.CallbackResult) => void
146
+ /** 接口调用失败的回调函数 */
147
+ fail?: (res: TaroGeneral.CallbackResult) => void
148
+ /** 接口调用成功的回调函数 */
149
+ success?: (result: SuccessCallbackResult) => void
150
+ }
151
+ interface SuccessCallbackResult extends TaroGeneral.CallbackResult {
152
+ /** 文件保存时的时间戳,从1970/01/01 08:00:00 到该时刻的秒数 */
153
+ createTime: number
154
+ /** 文件大小,单位 B */
155
+ size: number
156
+ /** 调用结果 */
157
+ errMsg: string
158
+ }
159
+ }
160
+
161
+ namespace getFileInfo {
162
+ interface Option {
163
+ /** 要读取的文件路径 */
164
+ filePath: string
165
+ /** 本地文件路径
166
+ * @supported alipay
167
+ */
168
+ apFilePath?: string
169
+ /**
170
+ * 计算文件摘要的算法
171
+ * @default 'md5'
172
+ */
173
+ digestAlgorithm?: 'md5' | 'sha1'
174
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
175
+ complete?: (res: TaroGeneral.CallbackResult) => void
176
+ /** 接口调用失败的回调函数 */
177
+ fail?: (result: FailCallbackResult) => void
178
+ /** 接口调用成功的回调函数 */
179
+ success?: (result: SuccessCallbackResult) => void
180
+ }
181
+ interface FailCallbackResult extends TaroGeneral.CallbackResult {
182
+ /** 错误信息
183
+ *
184
+ * 可选值:
185
+ * - 'fail file not exist': 指定的 filePath 找不到文件; */
186
+ errMsg: string
187
+ }
188
+ interface SuccessCallbackResult extends TaroGeneral.CallbackResult {
189
+ /** 文件大小,以字节为单位 */
190
+ size: number
191
+ /** 按照传入的 digestAlgorithm 计算得出的的文件摘要 */
192
+ digest: string
193
+ /** 调用结果 */
194
+ errMsg: string
195
+ }
196
+ }
197
+
198
+ /** 文件管理器,可通过 [Taro.getFileSystemManager](./getFileSystemManager) 获取。
199
+ * @supported weapp, tt, harmony_hybrid
200
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.html
201
+ */
202
+ interface FileSystemManager {
203
+ /** 判断文件/目录是否存在
204
+ * @supported weapp, alipay, swan, jd, qq, tt, harmony_hybrid
205
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.access.html
206
+ */
207
+ access(option: FileSystemManager.AccessOption): void
208
+ /** [FileSystemManager.access](#access) 的同步版本
209
+ * @supported weapp, alipay, swan, jd, qq, tt
210
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.accessSync.html
211
+ */
212
+ accessSync(
213
+ /** 要判断是否存在的文件/目录路径 */
214
+ path: string,
215
+ ): void
216
+ /** 在文件结尾追加内容
217
+ * @supported weapp, alipay, swan, jd, qq, tt
218
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.appendFile.html
219
+ */
220
+ appendFile(option: FileSystemManager.AppendFileOption): void
221
+ /** [FileSystemManager.appendFile](#appendfile) 的同步版本
222
+ * @supported weapp, alipay, swan, jd, qq, tt
223
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.appendFileSync.html
224
+ */
225
+ appendFileSync(
226
+ /** 要追加内容的文件路径 */
227
+ filePath: string,
228
+ /** 要追加的文本或二进制数据 */
229
+ data: string | ArrayBuffer,
230
+ /** 指定写入文件的字符编码 */
231
+ encoding?: keyof FileSystemManager.Encoding,
232
+ ): void
233
+ /** 关闭文件
234
+ * @supported weapp
235
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.close.html
236
+ */
237
+ close(option: FileSystemManager.CloseOption): void
238
+ /** [FileSystemManager.close](#close) 的同步版本
239
+ * @supported weapp
240
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.closeSync.html
241
+ */
242
+ closeSync(option: FileSystemManager.CloseSyncOption): void
243
+ /** 复制文件
244
+ * @supported weapp, alipay, swan, jd, qq, tt
245
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.copyFile.html
246
+ */
247
+ copyFile(option: FileSystemManager.CopyFileOption): void
248
+ /** [FileSystemManager.copyFile](#copyfile) 的同步版本
249
+ * @supported weapp, alipay, swan, jd, qq, tt
250
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.copyFileSync.html
251
+ */
252
+ copyFileSync(
253
+ /** 源文件路径,只可以是普通文件 */
254
+ srcPath: string,
255
+ /** 目标文件路径 */
256
+ destPath: string,
257
+ ): void
258
+ /** 获取文件的状态信息
259
+ * @supported weapp
260
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.fstat.html
261
+ */
262
+ fstat(option: FileSystemManager.FstatOption): void
263
+ /** [FileSystemManager.fstat](#fstat) 的同步版本
264
+ * @supported weapp
265
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.fstatSync.html
266
+ */
267
+ fstatSync(option: FileSystemManager.FstatSyncOption): Stats
268
+ /** 对文件内容进行截断操作
269
+ * @supported weapp
270
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.ftruncate.html
271
+ */
272
+ ftruncate(option: FileSystemManager.FtruncateOption): void
273
+ /** [FileSystemManager.ftruncate](#ftruncate) 的同步版本
274
+ * @supported weapp
275
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.ftruncateSync.html
276
+ */
277
+ ftruncateSync(option: FileSystemManager.FtruncateSyncOption): void
278
+ /** 获取该小程序下的 `本地临时文件` 或 `本地缓存文件` 信息
279
+ * @supported weapp, alipay, swan, jd, qq, tt, harmony_hybrid
280
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.getFileInfo.html
281
+ */
282
+ getFileInfo(option: FileSystemManager.getFileInfoOption): void
283
+ /** 获取该小程序下已保存的本地缓存文件列表
284
+ * @supported weapp, alipay, swan, jd, qq, tt
285
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.getSavedFileList.html
286
+ */
287
+ getSavedFileList(option?: FileSystemManager.getSavedFileListOption): void
288
+ /** 创建目录
289
+ * @supported weapp, alipay, swan, jd, qq, tt
290
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.mkdir.html
291
+ */
292
+ mkdir(option: FileSystemManager.MkdirOption): void
293
+ /** [FileSystemManager.mkdir](#mkdir) 的同步版本
294
+ * @supported weapp, alipay, swan, jd, qq, tt
295
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.mkdirSync.html
296
+ */
297
+ mkdirSync(
298
+ /** 创建的目录路径 */
299
+ dirPath: string,
300
+ /** 是否在递归创建该目录的上级目录后再创建该目录。如果对应的上级目录已经存在,则不创建该上级目录。如 dirPath 为 a/b/c/d 且 recursive 为 true,将创建 a 目录,再在 a 目录下创建 b 目录,以此类推直至创建 a/b/c 目录下的 d 目录。 */
301
+ recursive?: boolean,
302
+ ): void
303
+ /**打开文件,返回文件描述符
304
+ * @supported weapp
305
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.open.html
306
+ */
307
+ open(option: FileSystemManager.OpenOption): void
308
+ /** [FileSystemManager.openSync](#opensync) 的同步版本
309
+ * @supported weapp
310
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.ftruncateSync.html
311
+ */
312
+ openSync(option: FileSystemManager.OpenSyncOption): string /** 文件描述符 */
313
+ /** 读文件
314
+ * @supported weapp
315
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.read.html
316
+ */
317
+ read(option: FileSystemManager.ReadOption): void
318
+ /** 读取指定压缩类型的本地文件内容
319
+ * @supported weapp
320
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.readCompressedFile.html
321
+ */
322
+ readCompressedFile(option: FileSystemManager.readCompressedFile.Option): Promise<FileSystemManager.readCompressedFile.Promised>
323
+ /** 同步读取指定压缩类型的本地文件内容
324
+ * @supported weapp
325
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.readCompressedFileSync.html
326
+ */
327
+ readCompressedFileSync(option: FileSystemManager.readCompressedFileSync.Option): ArrayBuffer /** 文件读取结果 */
328
+ /** 读取目录内文件列表
329
+ * @supported weapp, alipay, swan, jd, qq, tt
330
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.readdir.html
331
+ */
332
+ readdir(option: FileSystemManager.ReaddirOption): void
333
+ /** [FileSystemManager.readdir](#readdir) 的同步版本
334
+ * @supported weapp, alipay, swan, jd, qq, tt
335
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.readdirSync.html
336
+ */
337
+ readdirSync(
338
+ /** 要读取的目录路径 */
339
+ dirPath: string,
340
+ ): string[]
341
+ /** 读取本地文件内容
342
+ * @supported weapp, alipay, swan, jd, qq, tt, harmony_hybrid
343
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.readFile.html
344
+ */
345
+ readFile(option: FileSystemManager.ReadFileOption): void
346
+ /** [FileSystemManager.readFile](#readfile) 的同步版本
347
+ * @supported weapp, alipay, swan, jd, qq, tt, harmony_hybrid
348
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.readFileSync.html
349
+ */
350
+ readFileSync(
351
+ /** 要读取的文件的路径 */
352
+ filePath: string,
353
+ /** 指定读取文件的字符编码,如果不传 encoding,则以 ArrayBuffer 格式读取文件的二进制内容 */
354
+ encoding?: keyof FileSystemManager.Encoding,
355
+ /**从文件指定位置开始读,如果不指定,则从文件头开始读。读取的范围应该是左闭右开区间 [position, position+length)。有效范围:[0, fileLength - 1]。单位:byte */
356
+ position?: number,
357
+ /**指定文件的长度,如果不指定,则读到文件末尾。有效范围:[1, fileLength]。单位:byte */
358
+ length?: number,
359
+ ): string | ArrayBuffer
360
+ /** [FileSystemManager.read](#read) 的同步版本
361
+ * @supported weapp
362
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.readSync.html
363
+ */
364
+ readSync(
365
+ option: FileSystemManager.ReadSyncOption
366
+ ): {
367
+ /** 实际读取的字节数 */
368
+ bytesRead: number
369
+ /** 被写入的缓存区的对象,即接口入参的 arrayBuffer */
370
+ arrayBuffer: ArrayBuffer
371
+ }
372
+ /** 读取压缩包内的文件
373
+ * @supported weapp
374
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.readZipEntry.html
375
+ */
376
+ readZipEntry(option: FileSystemManager.readZipEntry.Option): Promise<FileSystemManager.readZipEntry.Promised>
377
+ /** 删除该小程序下已保存的本地缓存文件
378
+ * @supported weapp, alipay, swan, jd, qq, tt
379
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.removeSavedFile.html
380
+ */
381
+ removeSavedFile(option: FileSystemManager.RemoveSavedFileOption): void
382
+ /** 重命名文件。可以把文件从 oldPath 移动到 newPath
383
+ * @supported weapp, alipay, swan, jd, qq, tt
384
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.rename.html
385
+ */
386
+ rename(option: FileSystemManager.RenameOption): void
387
+ /** [FileSystemManager.rename](#rename) 的同步版本
388
+ * @supported weapp, alipay, swan, jd, qq, tt
389
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.renameSync.html
390
+ */
391
+ renameSync(
392
+ /** 源文件路径,可以是普通文件或目录 */
393
+ oldPath: string,
394
+ /** 新文件路径 */
395
+ newPath: string,
396
+ ): void
397
+ /** 删除目录
398
+ * @supported weapp, tt
399
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.rmdir.html
400
+ */
401
+ rmdir(option: FileSystemManager.RmdirOption): void
402
+ /** [FileSystemManager.rmdir](#rmdir) 的同步版本
403
+ * @supported weapp, tt
404
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.rmdirSync.html
405
+ */
406
+ rmdirSync(
407
+ /** 要删除的目录路径 */
408
+ dirPath: string,
409
+ /** 是否递归删除目录。如果为 true,则删除该目录和该目录下的所有子目录以及文件。 */
410
+ recursive?: boolean,
411
+ ): void
412
+ /** 保存临时文件到本地。此接口会移动临时文件,因此调用成功后,tempFilePath 将不可用。
413
+ * @supported weapp, alipay, swan, jd, qq, tt
414
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.saveFile.html
415
+ */
416
+ saveFile(option: FileSystemManager.SaveFileOption): void
417
+ /** [FileSystemManager.saveFile](#savefile) 的同步版本
418
+ * @supported weapp, alipay, swan, jd, qq, tt
419
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.saveFileSync.html
420
+ */
421
+ saveFileSync(
422
+ /** 临时存储文件路径 */
423
+ tempFilePath: string,
424
+ /** 要存储的文件路径 */
425
+ filePath?: string,
426
+ ): string
427
+ /** 获取文件 Stats 对象
428
+ * @supported weapp, alipay, swan, jd, qq, tt
429
+ * https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.stat.html
430
+ */
431
+ stat(option: FileSystemManager.StatOption): void
432
+ /** [FileSystemManager.stat](#stat) 的同步版本
433
+ * @supported weapp, alipay, swan, jd, qq, tt
434
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.statSync.html
435
+ */
436
+ statSync(
437
+ /** 文件/目录路径 */
438
+ path: string,
439
+ /** 是否递归获取目录下的每个文件的 Stats 信息 */
440
+ recursive?: boolean,
441
+ ): Stats | TaroGeneral.IAnyObject
442
+ /** 对文件内容进行截断操作
443
+ * @supported weapp, tt
444
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.truncate.html
445
+ */
446
+ truncate(option: FileSystemManager.TruncateOption): void
447
+ /** 对文件内容进行截断操作 ([truncate](#truncate) 的同步版本)
448
+ * @supported weapp, tt
449
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.truncateSync.html
450
+ */
451
+ truncateSync(option: FileSystemManager.TruncateSyncOption): void
452
+ /** 删除文件
453
+ * @supported weapp, alipay, swan, jd, qq, tt
454
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.unlink.html
455
+ */
456
+ unlink(option: FileSystemManager.UnlinkOption): void
457
+ /** [FileSystemManager.unlink](#unlink) 的同步版本
458
+ * @supported weapp, alipay, swan, jd, qq, tt
459
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.unlinkSync.html
460
+ */
461
+ unlinkSync(
462
+ /** 要删除的文件路径 */
463
+ filePath: string,
464
+ ): void
465
+ /** 解压文件
466
+ * @supported weapp, alipay, swan, jd, qq, tt
467
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.unzip.html
468
+ */
469
+ unzip(option: FileSystemManager.UnzipOption): void
470
+ /** 写入文件
471
+ * @supported weapp
472
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.write.html
473
+ */
474
+ write(option: FileSystemManager.WriteOption): void
475
+ /** 写文件
476
+ * @supported weapp, alipay, swan, jd, qq, tt
477
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.writeFile.html
478
+ */
479
+ writeFile(option: FileSystemManager.WriteFileOption): void
480
+ /** [FileSystemManager.writeFile](#writefile) 的同步版本
481
+ * @supported weapp, alipay, swan, jd, qq, tt
482
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.writeFileSync.html
483
+ */
484
+ writeFileSync(
485
+ /** 要写入的文件路径 */
486
+ filePath: string,
487
+ /** 要写入的文本或二进制数据 */
488
+ data: string | ArrayBuffer,
489
+ /** 指定写入文件的字符编码 */
490
+ encoding?: keyof FileSystemManager.Encoding,
491
+ ): void
492
+ /** [write](#write) 的同步版本
493
+ * @supported weapp
494
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/FileSystemManager.writeSync.html
495
+ */
496
+ writeSync(
497
+ option: FileSystemManager.WriteSyncOption
498
+ ): {
499
+ /** 实际被写入到文件中的字节数(注意,被写入的字节数不一定与被写入的字符串字符数相同) */
500
+ bytesWritten: number
501
+ }
502
+ }
503
+
504
+ namespace FileSystemManager {
505
+ /** 字符编码 */
506
+ interface Encoding {
507
+ ascii
508
+ base64
509
+ binary
510
+ hex
511
+ /** 以小端序读取 */
512
+ ucs2
513
+ /** 以小端序读取 */
514
+ 'ucs-2'
515
+ /** 以小端序读取 */
516
+ utf16le
517
+ /** 以小端序读取 */
518
+ 'utf-16le'
519
+ 'utf-8'
520
+ utf8
521
+ latin1
522
+ }
523
+ /** 文件系统标志 */
524
+ interface flag {
525
+ a /**打开文件用于追加。 如果文件不存在,则创建该文件 */
526
+ ax /**类似于 'a',但如果路径存在,则失败 */
527
+ 'a+' /**打开文件用于读取和追加。 如果文件不存在,则创建该文件 */
528
+ 'ax+' /**类似于 'a+',但如果路径存在,则失败 */
529
+ as /**打开文件用于追加(在同步模式中)。 如果文件不存在,则创建该文件 */
530
+ 'as+' /**打开文件用于读取和追加(在同步模式中)。 如果文件不存在,则创建该文件 */
531
+ r /**打开文件用于读取。 如果文件不存在,则会发生异常 */
532
+ 'r+' /**打开文件用于读取和写入。 如果文件不存在,则会发生异常 */
533
+ w /**打开文件用于写入。 如果文件不存在则创建文件,如果文件存在则截断文件 */
534
+ wx /**类似于 'w',但如果路径存在,则失败 */
535
+ 'w+' /**打开文件用于读取和写入。 如果文件不存在则创建文件,如果文件存在则截断文件 */
536
+ 'wx+' /**类似于 'w+',但如果路径存在,则失败*/
537
+ }
538
+ interface AccessOption {
539
+ /** 要判断是否存在的文件/目录路径 */
540
+ path: string
541
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
542
+ complete?: (res: TaroGeneral.CallbackResult) => void
543
+ /** 接口调用失败的回调函数 */
544
+ fail?: (result: AccessFailCallbackResult) => void
545
+ /** 接口调用成功的回调函数 */
546
+ success?: (res: TaroGeneral.CallbackResult) => void
547
+ }
548
+
549
+ interface AccessFailCallbackResult extends TaroGeneral.CallbackResult {
550
+ /** 错误信息
551
+ *
552
+ * 可选值:
553
+ * - 'fail no such file or directory ${path}': 文件/目录不存在; */
554
+ errMsg: string
555
+ }
556
+
557
+ interface AppendFileOption {
558
+ /** 要追加的文本或二进制数据 */
559
+ data: string | ArrayBuffer
560
+ /** 要追加内容的文件路径 */
561
+ filePath: string
562
+ /** 指定写入文件的字符编码 */
563
+ encoding?: keyof FileSystemManager.Encoding
564
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
565
+ complete?: (res: TaroGeneral.CallbackResult) => void
566
+ /** 接口调用失败的回调函数 */
567
+ fail?: (result: AppendFileFailCallbackResult) => void
568
+ /** 接口调用成功的回调函数 */
569
+ success?: (res: TaroGeneral.CallbackResult) => void
570
+ }
571
+
572
+ interface AppendFileFailCallbackResult extends TaroGeneral.CallbackResult {
573
+ /** 错误信息
574
+ *
575
+ * 可选值:
576
+ * - 'fail no such file or directory, open ${filePath}': 指定的 filePath 文件不存在;
577
+ * - 'fail illegal operation on a directory, open "${filePath}"': 指定的 filePath 是一个已经存在的目录;
578
+ * - 'fail permission denied, open ${dirPath}': 指定的 filePath 路径没有写权限;
579
+ * - 'fail sdcard not mounted': 指定的 filePath 是一个已经存在的目录; */
580
+ errMsg: string
581
+ }
582
+
583
+ interface CopyFileOption {
584
+ /** 目标文件路径 */
585
+ destPath: string
586
+ /** 源文件路径,只可以是普通文件 */
587
+ srcPath: string
588
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
589
+ complete?: (res: TaroGeneral.CallbackResult) => void
590
+ /** 接口调用失败的回调函数 */
591
+ fail?: (result: CopyFileFailCallbackResult) => void
592
+ /** 接口调用成功的回调函数 */
593
+ success?: (res: TaroGeneral.CallbackResult) => void
594
+ }
595
+
596
+ interface CopyFileFailCallbackResult extends TaroGeneral.CallbackResult {
597
+ /** 错误信息
598
+ *
599
+ * 可选值:
600
+ * - 'fail permission denied, copyFile ${srcPath} -> ${destPath}': 指定目标文件路径没有写权限;
601
+ * - 'fail no such file or directory, copyFile ${srcPath} -> ${destPath}': 源文件不存在,或目标文件路径的上层目录不存在;
602
+ * - 'fail the maximum size of the file storage limit is exceeded': 存储空间不足; */
603
+ errMsg: string
604
+ }
605
+
606
+ interface getFileInfoOption {
607
+ /** 要读取的文件路径 */
608
+ filePath: string
609
+ /**
610
+ * 计算文件摘要的算法
611
+ * @default 'md5'
612
+ */
613
+ digestAlgorithm?: 'md5' | 'sha1'
614
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
615
+ complete?: (res: TaroGeneral.CallbackResult) => void
616
+ /** 接口调用失败的回调函数 */
617
+ fail?: (result: GetFileInfoFailCallbackResult) => void
618
+ /** 接口调用成功的回调函数 */
619
+ success?: (result: GetFileInfoSuccessCallbackResult) => void
620
+ }
621
+
622
+ interface GetFileInfoFailCallbackResult extends TaroGeneral.CallbackResult {
623
+ /** 错误信息
624
+ *
625
+ * 可选值:
626
+ * - 'fail file not exist': 指定的 filePath 找不到文件; */
627
+ errMsg: string
628
+ }
629
+ interface GetFileInfoSuccessCallbackResult extends TaroGeneral.CallbackResult {
630
+ /** 文件大小,以字节为单位 */
631
+ size: number
632
+ /** 按照传入的 digestAlgorithm 计算得出的的文件摘要 */
633
+ digest?: string
634
+ /** 调用结果 */
635
+ errMsg: string
636
+ }
637
+
638
+ interface getSavedFileListOption {
639
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
640
+ complete?: (res: TaroGeneral.CallbackResult) => void
641
+ /** 接口调用失败的回调函数 */
642
+ fail?: (res: TaroGeneral.CallbackResult) => void
643
+ /** 接口调用成功的回调函数 */
644
+ success?: (result: GetSavedFileListSuccessCallbackResult) => void
645
+ }
646
+
647
+ interface GetSavedFileListSuccessCallbackResult extends TaroGeneral.CallbackResult {
648
+ /** 文件数组 */
649
+ fileList: GetSavedFileListSuccessCallbackResultFileItem[]
650
+ /** 调用结果 */
651
+ errMsg: string
652
+ }
653
+ /** 文件数组 */
654
+ interface GetSavedFileListSuccessCallbackResultFileItem {
655
+ /** 文件保存时的时间戳,从1970/01/01 08:00:00 到当前时间的秒数 */
656
+ createTime: number
657
+ /** 本地路径 */
658
+ filePath: string
659
+ /** 本地文件大小,以字节为单位 */
660
+ size: number
661
+ }
662
+
663
+ interface MkdirOption {
664
+ /** 创建的目录路径 */
665
+ dirPath: string
666
+ /** 是否在递归创建该目录的上级目录后再创建该目录。如果对应的上级目录已经存在,则不创建该上级目录。
667
+ * 如 dirPath 为 a/b/c/d 且 recursive 为 true,将创建 a 目录,再在 a 目录下创建 b 目录,以此类推直至创建 a/b/c 目录下的 d 目录。
668
+ * @default false
669
+ */
670
+ recursive?: boolean
671
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
672
+ complete?: (res: TaroGeneral.CallbackResult) => void
673
+ /** 接口调用失败的回调函数 */
674
+ fail?: (result: MkdirFailCallbackResult) => void
675
+ /** 接口调用成功的回调函数 */
676
+ success?: (res: TaroGeneral.CallbackResult) => void
677
+ }
678
+
679
+ interface MkdirFailCallbackResult extends TaroGeneral.CallbackResult {
680
+ /** 错误信息
681
+ *
682
+ * 可选值:
683
+ * - 'fail no such file or directory ${dirPath}': 上级目录不存在;
684
+ * - 'fail permission denied, open ${dirPath}': 指定的 filePath 路径没有写权限;
685
+ * - 'fail file already exists ${dirPath}': 有同名文件或目录; */
686
+ errMsg: string
687
+ }
688
+
689
+ interface ReadFileOption {
690
+ /** 要读取的文件的路径 */
691
+ filePath: string
692
+ /** 从文件指定位置开始读,如果不指定,则从文件头开始读。读取的范围应该是左闭右开区间 [position, position+length)。有效范围:[0, fileLength - 1]。单位:byte*/
693
+ position?: number
694
+ /**指定文件的长度,如果不指定,则读到文件末尾。有效范围:[1, fileLength]。单位:byte */
695
+ length?: number
696
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
697
+ complete?: (res: TaroGeneral.CallbackResult) => void
698
+ /** 指定读取文件的字符编码,如果不传 encoding,则以 ArrayBuffer 格式读取文件的二进制内容 */
699
+ encoding?: keyof FileSystemManager.Encoding
700
+ /** 接口调用失败的回调函数 */
701
+ fail?: (result: ReadFileFailCallbackResult) => void
702
+ /** 接口调用成功的回调函数 */
703
+ success?: (res: ReadFileSuccessCallbackResult) => void
704
+ }
705
+ interface ReadFileSuccessCallbackResult extends TaroGeneral.CallbackResult {
706
+ /** 文件内容 */
707
+ data: string | ArrayBuffer
708
+ /** 调用结果 */
709
+ errMsg: string
710
+ }
711
+ interface ReadFileFailCallbackResult extends TaroGeneral.CallbackResult {
712
+ /** 错误信息
713
+ *
714
+ * 可选值:
715
+ * - 'fail no such file or directory, open ${filePath}': 指定的 filePath 所在目录不存在;
716
+ * - 'fail permission denied, open ${dirPath}': 指定的 filePath 路径没有读权限; */
717
+ errMsg: string
718
+ }
719
+
720
+ interface ReaddirOption {
721
+ /** 要读取的目录路径 */
722
+ dirPath: string
723
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
724
+ complete?: (res: TaroGeneral.CallbackResult) => void
725
+ /** 接口调用失败的回调函数 */
726
+ fail?: (result: ReaddirFailCallbackResult) => void
727
+ /** 接口调用成功的回调函数 */
728
+ success?: (result: ReaddirSuccessCallbackResult) => void
729
+ }
730
+
731
+ interface ReaddirFailCallbackResult extends TaroGeneral.CallbackResult {
732
+ /** 错误信息
733
+ *
734
+ * 可选值:
735
+ * - 'fail no such file or directory ${dirPath}': 目录不存在;
736
+ * - 'fail not a directory ${dirPath}': dirPath 不是目录;
737
+ * - 'fail permission denied, open ${dirPath}': 指定的 filePath 路径没有读权限; */
738
+ errMsg: string
739
+ }
740
+ interface ReaddirSuccessCallbackResult extends TaroGeneral.CallbackResult {
741
+ /** 指定目录下的文件名数组。 */
742
+ files: string[]
743
+ /** 调用结果 */
744
+ errMsg: string
745
+ }
746
+
747
+ namespace readZipEntry {
748
+ type Promised = FailCallbackResult | SuccessCallbackResult
749
+ interface Option {
750
+ /** 要读取的压缩包的路径 (本地路径) */
751
+ filePath: string
752
+ /** 统一指定读取文件的字符编码,只在 entries 值为"all"时有效。如果 entries 值为"all"且不传 encoding,则以 ArrayBuffer 格式读取文件的二进制内容 */
753
+ encoding?: keyof Encoding | string
754
+ /** 要读取的压缩包内的文件列表(当传入"all" 时表示读取压缩包内所有文件) */
755
+ entries: File[] | 'all'
756
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
757
+ complete?: (res: TaroGeneral.CallbackResult) => void
758
+ /** 接口调用失败的回调函数 */
759
+ fail?: (result: FailCallbackResult) => void
760
+ /** 接口调用成功的回调函数 */
761
+ success?: (res: SuccessCallbackResult) => void
762
+ }
763
+ interface File {
764
+ /** 压缩包内文件路径 */
765
+ path: string
766
+ /** 指定读取文件的字符编码,如果不传 encoding,则以 ArrayBuffer 格式读取文件的二进制内容 */
767
+ encoding?: keyof Encoding | string
768
+ /** 从文件指定位置开始读,如果不指定,则从文件头开始读。读取的范围应该是左闭右开区间 [position, position+length)。有效范围:[0, fileLength - 1]。单位:byte */
769
+ position?: number
770
+ /** 指定文件的长度,如果不指定,则读到文件末尾。有效范围:[1, fileLength]。单位:byte */
771
+ length?: number
772
+ }
773
+ /** 字符编码合法值 */
774
+ interface Encoding {
775
+ ascii
776
+ base64
777
+ binary
778
+ hex
779
+ /** @illustrate 以小端序读取 */
780
+ ucs2
781
+ /** @illustrate 以小端序读取 */
782
+ 'ucs-2'
783
+ /** @illustrate 以小端序读取 */
784
+ utf16le
785
+ /** @illustrate 以小端序读取 */
786
+ 'utf-16le'
787
+ 'utf-8'
788
+ utf8
789
+ latin1
790
+ }
791
+ interface FailCallbackResult extends TaroGeneral.CallbackResult {
792
+ /** 错误信息
793
+ *
794
+ * 可选值:
795
+ * - 'fail no such file or directory, open ${filePath}': 指定的 filePath 所在目录不存在
796
+ * - 'fail permission denied, open ${dirPath}': 指定的 filePath 路径没有读权限
797
+ * - 'fail sdcard not mounted': Android sdcard 挂载失败
798
+ * */
799
+ errMsg: string
800
+ }
801
+ interface SuccessCallbackResult extends TaroGeneral.CallbackResult {
802
+ /** 文件读取结果。res.entries 是一个对象,key是文件路径,value是一个对象 FileItem ,表示该文件的读取结果。每个 FileItem 包含 data (文件内容) 和 errMsg (错误信息) 属性。 */
803
+ entries: {
804
+ [path: string]: FileItem
805
+ }
806
+ }
807
+ interface FileItem extends TaroGeneral.CallbackResult {
808
+ /** 文件内容 */
809
+ data: string | ArrayBuffer
810
+ /** 错误信息 */
811
+ errMsg: string
812
+ }
813
+ }
814
+
815
+ interface RemoveSavedFileOption {
816
+ /** 需要删除的文件路径 */
817
+ filePath: string
818
+ /** 本地缓存文件路径
819
+ * @supported alipay
820
+ */
821
+ apFilePath?: string
822
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
823
+ complete?: (res: TaroGeneral.CallbackResult) => void
824
+ /** 接口调用失败的回调函数 */
825
+ fail?: (result: RemoveSavedFileFailCallbackResult) => void
826
+ /** 接口调用成功的回调函数 */
827
+ success?: (res: TaroGeneral.CallbackResult) => void
828
+ }
829
+ interface RemoveSavedFileFailCallbackResult extends TaroGeneral.CallbackResult {
830
+ /** 错误信息
831
+ *
832
+ * 可选值:
833
+ * - 'fail file not exist': 指定的 tempFilePath 找不到文件; */
834
+ errMsg: string
835
+ }
836
+
837
+ interface RenameOption {
838
+ /** 新文件路径 */
839
+ newPath: string
840
+ /** 源文件路径,可以是普通文件或目录 */
841
+ oldPath: string
842
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
843
+ complete?: (res: TaroGeneral.CallbackResult) => void
844
+ /** 接口调用失败的回调函数 */
845
+ fail?: (result: RenameFailCallbackResult) => void
846
+ /** 接口调用成功的回调函数 */
847
+ success?: (res: TaroGeneral.CallbackResult) => void
848
+ }
849
+ interface RenameFailCallbackResult extends TaroGeneral.CallbackResult {
850
+ /** 错误信息
851
+ *
852
+ * 可选值:
853
+ * - 'fail permission denied, rename ${oldPath} -> ${newPath}': 指定源文件或目标文件没有写权限;
854
+ * - 'fail no such file or directory, rename ${oldPath} -> ${newPath}': 源文件不存在,或目标文件路径的上层目录不存在; */
855
+ errMsg: string
856
+ }
857
+
858
+ interface RmdirOption {
859
+ /** 要删除的目录路径 */
860
+ dirPath: string
861
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
862
+ complete?: (res: TaroGeneral.CallbackResult) => void
863
+ /** 接口调用失败的回调函数 */
864
+ fail?: (result: RmdirFailCallbackResult) => void
865
+ /** 是否递归删除目录。如果为 true,则删除该目录和该目录下的所有子目录以及文件。 */
866
+ recursive?: boolean
867
+ /** 接口调用成功的回调函数 */
868
+ success?: (res: TaroGeneral.CallbackResult) => void
869
+ }
870
+ interface RmdirFailCallbackResult extends TaroGeneral.CallbackResult {
871
+ /** 错误信息
872
+ *
873
+ * 可选值:
874
+ * - 'fail no such file or directory ${dirPath}': 目录不存在;
875
+ * - 'fail directory not empty': 目录不为空;
876
+ * - 'fail permission denied, open ${dirPath}': 指定的 dirPath 路径没有写权限; */
877
+ errMsg: string
878
+ }
879
+
880
+ interface SaveFileOption {
881
+ /** 临时存储文件路径 */
882
+ tempFilePath: string
883
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
884
+ complete?: (res: TaroGeneral.CallbackResult) => void
885
+ /** 接口调用失败的回调函数 */
886
+ fail?: (result: SaveFileFailCallbackResult) => void
887
+ /** 要存储的文件路径 */
888
+ filePath?: string
889
+ /** 接口调用成功的回调函数 */
890
+ success?: (result: SaveFileSuccessCallbackResult) => void
891
+ }
892
+
893
+ interface SaveFileFailCallbackResult extends TaroGeneral.CallbackResult {
894
+ /** 错误信息
895
+ *
896
+ * 可选值:
897
+ * - 'fail tempFilePath file not exist': 指定的 tempFilePath 找不到文件;
898
+ * - 'fail permission denied, open "${filePath}"': 指定的 filePath 路径没有写权限;
899
+ * - 'fail no such file or directory "${dirPath}"': 上级目录不存在;
900
+ * - 'fail the maximum size of the file storage limit is exceeded': 存储空间不足; */
901
+ errMsg: string
902
+ }
903
+ interface SaveFileSuccessCallbackResult extends TaroGeneral.CallbackResult {
904
+ /** 存储后的文件路径 */
905
+ savedFilePath: string
906
+ /** 调用结果 */
907
+ errMsg: string
908
+ }
909
+
910
+ interface StatOption {
911
+ /** 文件/目录路径 */
912
+ path: string
913
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
914
+ complete?: (res: TaroGeneral.CallbackResult) => void
915
+ /** 接口调用失败的回调函数 */
916
+ fail?: (result: StatFailCallbackResult) => void
917
+ /** 是否递归获取目录下的每个文件的 Stats 信息 */
918
+ recursive?: boolean
919
+ /** 接口调用成功的回调函数 */
920
+ success?: (result: StatSuccessCallbackResult) => void
921
+ }
922
+ interface StatFailCallbackResult extends TaroGeneral.CallbackResult {
923
+ /** 错误信息
924
+ *
925
+ * 可选值:
926
+ * - 'fail permission denied, open ${path}': 指定的 path 路径没有读权限;
927
+ * - 'fail no such file or directory ${path}': 文件不存在; */
928
+ errMsg: string
929
+ }
930
+ interface StatSuccessCallbackResult extends TaroGeneral.CallbackResult {
931
+ /** [Stats](/docs/apis/files/Stats) | Object
932
+ *
933
+ * 当 recursive 为 false 时,res.stats 是一个 Stats 对象。当 recursive 为 true 且 path 是一个目录的路径时,res.stats 是一个 Object,key 以 path 为根路径的相对路径,value 是该路径对应的 Stats 对象。 */
934
+ stats: Stats | TaroGeneral.IAnyObject
935
+ /** 调用结果 */
936
+ errMsg: string
937
+ }
938
+
939
+ interface UnlinkOption {
940
+ /** 要删除的文件路径 */
941
+ filePath: string
942
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
943
+ complete?: (res: TaroGeneral.CallbackResult) => void
944
+ /** 接口调用失败的回调函数 */
945
+ fail?: (result: UnlinkFailCallbackResult) => void
946
+ /** 接口调用成功的回调函数 */
947
+ success?: (res: TaroGeneral.CallbackResult) => void
948
+ }
949
+ interface UnlinkFailCallbackResult extends TaroGeneral.CallbackResult {
950
+ /** 错误信息
951
+ *
952
+ * 可选值:
953
+ * - 'fail permission denied, open ${path}': 指定的 path 路径没有读权限;
954
+ * - 'fail no such file or directory ${path}': 文件不存在;
955
+ * - 'fail operation not permitted, unlink ${filePath}': 传入的 filePath 是一个目录; */
956
+ errMsg: string
957
+ }
958
+
959
+ interface UnzipOption {
960
+ /** 目标目录路径 */
961
+ targetPath: string
962
+ /** 源文件路径,只可以是 zip 压缩文件 */
963
+ zipFilePath: string
964
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
965
+ complete?: (res: TaroGeneral.CallbackResult) => void
966
+ /** 接口调用失败的回调函数 */
967
+ fail?: (result: UnzipFailCallbackResult) => void
968
+ /** 接口调用成功的回调函数 */
969
+ success?: (res: TaroGeneral.CallbackResult) => void
970
+ }
971
+
972
+ interface UnzipFailCallbackResult extends TaroGeneral.CallbackResult {
973
+ /** 错误信息
974
+ *
975
+ * 可选值:
976
+ * - 'fail permission denied, unzip ${zipFilePath} -> ${destPath}': 指定目标文件路径没有写权限;
977
+ * - 'fail no such file or directory, unzip ${zipFilePath} -> "${destPath}': 源文件不存在,或目标文件路径的上层目录不存在; */
978
+ errMsg: string
979
+ }
980
+
981
+ interface WriteFileOption {
982
+ /** 要写入的文本或二进制数据 */
983
+ data: string | ArrayBuffer
984
+ /** 要写入的文件路径 */
985
+ filePath: string
986
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
987
+ complete?: (res: TaroGeneral.CallbackResult) => void
988
+ /** 指定写入文件的字符编码 */
989
+ encoding?: keyof FileSystemManager.Encoding
990
+ /** 接口调用失败的回调函数 */
991
+ fail?: (result: WriteFileFailCallbackResult) => void
992
+ /** 接口调用成功的回调函数 */
993
+ success?: (res: TaroGeneral.CallbackResult) => void
994
+ }
995
+ interface WriteFileFailCallbackResult extends TaroGeneral.CallbackResult {
996
+ /** 错误信息
997
+ *
998
+ * 可选值:
999
+ * - 'fail no such file or directory, open ${filePath}': 指定的 filePath 所在目录不存在;
1000
+ * - 'fail permission denied, open ${dirPath}': 指定的 filePath 路径没有写权限;
1001
+ * - 'fail the maximum size of the file storage limit is exceeded': 存储空间不足; */
1002
+ errMsg: string
1003
+ }
1004
+ interface FstatOption {
1005
+ /** 文件描述符。fd 通过 FileSystemManager.open 或 FileSystemManager.openSync 接口获得 */
1006
+ fd: string
1007
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
1008
+ complete?: (res: TaroGeneral.CallbackResult) => void
1009
+ /** 接口调用失败的回调函数 */
1010
+ fail?: (result: FstatFailCallbackResult) => void
1011
+ /** 接口调用成功的回调函数 */
1012
+ success?: (res: FstatSuccessCallbackResult) => void
1013
+ }
1014
+
1015
+ interface FstatFailCallbackResult extends TaroGeneral.CallbackResult {
1016
+ /** 错误信息
1017
+ *
1018
+ * 可选值:
1019
+ * - 'bad file descriptor': 无效的文件描述符;
1020
+ * - 'fail permission denied': 指定的 fd 路径没有读权限; */
1021
+ errMsg: string
1022
+ }
1023
+ interface FstatSuccessCallbackResult extends TaroGeneral.CallbackResult {
1024
+ /** Stats 对象,包含了文件的状态信息 */
1025
+ stats: Stats
1026
+ /** 调用结果 */
1027
+ errMsg: string
1028
+ }
1029
+ interface FstatSyncOption {
1030
+ /** 文件描述符。fd 通过 FileSystemManager.open 或 FileSystemManager.openSync 接口获得 */
1031
+ fd: string
1032
+ }
1033
+ interface CloseOption {
1034
+ /** 需要被关闭的文件描述符。fd 通过 FileSystemManager.open 或 FileSystemManager.openSync 接口获得 */
1035
+ fd: string
1036
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
1037
+ complete?: (res: TaroGeneral.CallbackResult) => void
1038
+ /** 接口调用失败的回调函数 */
1039
+ fail?: (result: CloseFailCallbackResult) => void
1040
+ /** 接口调用成功的回调函数 */
1041
+ success?: (res: TaroGeneral.CallbackResult) => void
1042
+ }
1043
+ interface CloseFailCallbackResult extends TaroGeneral.CallbackResult {
1044
+ /** 错误信息
1045
+ *
1046
+ * 可选值:
1047
+ * - 'bad file descriptor': 无效的文件描述符 */
1048
+ errMsg: string
1049
+ }
1050
+ interface CloseSyncOption {
1051
+ /** 需要被关闭的文件描述符。fd 通过 FileSystemManager.open 或 FileSystemManager.openSync 接口获得 */
1052
+ fd: string
1053
+ }
1054
+ interface FtruncateOption {
1055
+ /** 文件描述符。fd 通过 FileSystemManager.open 或 FileSystemManager.openSync 接口获得 */
1056
+ fd: string
1057
+ /** 截断位置,默认0。如果 length 小于文件长度(单位:字节),则只有前面 length 个字节会保留在文件中,其余内容会被删除;如果 length 大于文件长度,则会对其进行扩展,并且扩展部分将填充空字节('\0') */
1058
+ length: number
1059
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
1060
+ complete?: (res: TaroGeneral.CallbackResult) => void
1061
+ /** 接口调用失败的回调函数 */
1062
+ fail?: (result: FtruncateFailCallbackResult) => void
1063
+ /** 接口调用成功的回调函数 */
1064
+ success?: (res: TaroGeneral.CallbackResult) => void
1065
+ }
1066
+ interface FtruncateFailCallbackResult extends TaroGeneral.CallbackResult {
1067
+ /** 错误信息
1068
+ *
1069
+ * 可选值:
1070
+ * - 'bad file descriptor': 无效的文件描述符
1071
+ * - 'fail permission denied': 指定的 fd 没有写权限
1072
+ * - 'fail the maximum size of the file storage limit is exceeded': 存储空间不足
1073
+ * - 'fail sdcard not mounted android sdcard': 挂载失败 */
1074
+ errMsg: string
1075
+ }
1076
+ interface FtruncateSyncOption {
1077
+ /** 文件描述符。fd 通过 FileSystemManager.open 或 FileSystemManager.openSync 接口获得 */
1078
+ fd: string
1079
+ /**截断位置,默认0。如果 length 小于文件长度(单位:字节),则只有前面 length 个字节会保留在文件中,其余内容会被删除;如果 length 大于文件长度,则会对其进行扩展,并且扩展部分将填充空字节('\0') */
1080
+ length: number
1081
+ }
1082
+
1083
+ interface OpenOption {
1084
+ /** 文件路径 (本地路径) */
1085
+ filePath: string
1086
+ /** 文件系统标志,默认值: 'r' */
1087
+ flag?: keyof FileSystemManager.flag
1088
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
1089
+ complete?: (res: TaroGeneral.CallbackResult) => void
1090
+ /** 接口调用失败的回调函数 */
1091
+ fail?: (result: OpenFailCallbackResult) => void
1092
+ /** 接口调用成功的回调函数 */
1093
+ success?: (res: OpenSuccessCallbackResult) => void
1094
+ }
1095
+ interface OpenFailCallbackResult extends TaroGeneral.CallbackResult {
1096
+ /** 错误信息
1097
+ *
1098
+ * 可选值:
1099
+ * - 'fail no such file or directory "${filePath}"': 上级目录不存在 */
1100
+ errMsg: string
1101
+ }
1102
+ interface OpenSuccessCallbackResult extends TaroGeneral.CallbackResult {
1103
+ /** 文件描述符 */
1104
+ fd: string
1105
+ /** 调用结果 */
1106
+ errMsg: string
1107
+ }
1108
+ interface OpenSyncOption {
1109
+ /** 文件路径 (本地路径) */
1110
+ filePath: string
1111
+ /** 文件系统标志,默认值: 'r' */
1112
+ flag?: keyof FileSystemManager.flag
1113
+ }
1114
+ interface ReadOption {
1115
+ /** 文件描述符。fd 通过 FileSystemManager.open 或 FileSystemManager.openSync 接口获得 */
1116
+ fd: string
1117
+ /** 数据写入的缓冲区,必须是 ArrayBuffer 实例 */
1118
+ arrayBuffer: ArrayBuffer
1119
+ /** 缓冲区中的写入偏移量,默认0 */
1120
+ offset?: number
1121
+ /** 要从文件中读取的字节数,默认0 */
1122
+ length?: number
1123
+ /** 文件读取的起始位置,如不传或传 null,则会从当前文件指针的位置读取。如果 position 是正整数,则文件指针位置会保持不变并从 position 读取文件。 */
1124
+ position?: number
1125
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
1126
+ complete?: (res: TaroGeneral.CallbackResult) => void
1127
+ /** 接口调用失败的回调函数 */
1128
+ fail?: (result: ReadFailCallbackResult) => void
1129
+ /** 接口调用成功的回调函数 */
1130
+ success?: (res: ReadSuccessCallbackResult) => void
1131
+ }
1132
+ interface ReadFailCallbackResult extends TaroGeneral.CallbackResult {
1133
+ /** 错误信息
1134
+ *
1135
+ * 可选值:
1136
+ * - 'bad file descriptor': 无效的文件描述符
1137
+ * - 'fail permission denied': 指定的 fd 路径没有读权限
1138
+ * - 'fail the value of "offset" is out of range': 传入的 offset 不合法
1139
+ * - 'fail the value of "length" is out of range': 传入的 length 不合法
1140
+ * - 'fail sdcard not mounted': android sdcard 挂载失败
1141
+ * - 'bad file descriptor': 无效的文件描述符
1142
+ * */
1143
+ errMsg: string
1144
+ }
1145
+ interface ReadSuccessCallbackResult extends TaroGeneral.CallbackResult {
1146
+ /** 实际读取的字节数 */
1147
+ bytesRead: string
1148
+ /** 被写入的缓存区的对象,即接口入参的 arrayBuffer */
1149
+ arrayBuffer: ArrayBuffer
1150
+ /** 调用结果 */
1151
+ errMsg: string
1152
+ }
1153
+ namespace readCompressedFile {
1154
+ type Promised = FailCallbackResult | SuccessCallbackResult
1155
+ interface Option {
1156
+ /** 要读取的文件的路径 (本地用户文件或代码包文件) */
1157
+ filePath: string
1158
+ /** 文件压缩类型,目前仅支持 'br'。 */
1159
+ compressionAlgorithm: keyof CompressionAlgorithm | string
1160
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
1161
+ complete?: (res: TaroGeneral.CallbackResult) => void
1162
+ /** 接口调用失败的回调函数 */
1163
+ fail?: (result: FailCallbackResult) => void
1164
+ /** 接口调用成功的回调函数 */
1165
+ success?: (res: SuccessCallbackResult) => void
1166
+ }
1167
+ /** 文件压缩类型合法值 */
1168
+ interface CompressionAlgorithm {
1169
+ /** brotli压缩文件 */
1170
+ br
1171
+ }
1172
+ interface FailCallbackResult extends TaroGeneral.CallbackResult {
1173
+ /** 错误信息
1174
+ *
1175
+ * 可选值:
1176
+ * - 'fail decompress fail': 指定的 compressionAlgorithm 与文件实际压缩格式不符
1177
+ * - 'fail no such file or directory, open ${filePath}': 指定的 filePath 所在目录不存在
1178
+ * - 'fail permission denied, open ${dirPath}': 指定的 filePath 路径没有读权限
1179
+ * */
1180
+ errMsg: string
1181
+ }
1182
+ interface SuccessCallbackResult extends TaroGeneral.CallbackResult {
1183
+ /** 文件内容 */
1184
+ data: ArrayBuffer
1185
+ }
1186
+ }
1187
+ namespace readCompressedFileSync {
1188
+ interface Option {
1189
+ /** 要读取的文件的路径 (本地用户文件或代码包文件) */
1190
+ filePath: string
1191
+ /** 文件压缩类型,目前仅支持 'br'。 */
1192
+ compressionAlgorithm: keyof CompressionAlgorithm | string
1193
+ }
1194
+ /** 文件压缩类型合法值 */
1195
+ interface CompressionAlgorithm {
1196
+ /** brotli压缩文件 */
1197
+ br
1198
+ }
1199
+ }
1200
+ interface ReadSyncOption {
1201
+ /** 文件描述符。fd 通过 FileSystemManager.open 或 FileSystemManager.openSync 接口获得 */
1202
+ fd: string
1203
+ /** 数据写入的缓冲区,必须是 ArrayBuffer 实例 */
1204
+ arrayBuffer: ArrayBuffer
1205
+ /** 缓冲区中的写入偏移量,默认0 */
1206
+ offset?: number
1207
+ /** 要从文件中读取的字节数,默认0 */
1208
+ length?: number
1209
+ /** 文件读取的起始位置,如不传或传 null,则会从当前文件指针的位置读取。如果 position 是正整数,则文件指针位置会保持不变并从 position 读取文件。 */
1210
+ position?: number
1211
+ }
1212
+ interface TruncateOption {
1213
+ /** 要截断的文件路径 (本地路径) */
1214
+ filePath: string
1215
+ /** 截断位置,默认0。如果 length 小于文件长度(字节),则只有前面 length 个字节会保留在文件中,其余内容会被删除;如果 length 大于文件长度,则会对其进行扩展,并且扩展部分将填充空字节('\0') */
1216
+ length?: number
1217
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
1218
+ complete?: (res: TaroGeneral.CallbackResult) => void
1219
+ /** 接口调用失败的回调函数 */
1220
+ fail?: (result: TruncateFailCallbackResult) => void
1221
+ /** 接口调用成功的回调函数 */
1222
+ success?: (res: TaroGeneral.CallbackResult) => void
1223
+ }
1224
+ interface TruncateFailCallbackResult extends TaroGeneral.CallbackResult {
1225
+ /** 错误信息
1226
+ *
1227
+ * 可选值:
1228
+ * - 'fail no such file or directory, open ${filePath}': 指定的 filePath 所在目录不存在
1229
+ * - 'fail illegal operation on a directory, open "${filePath}"': 指定的 filePath 是一个已经存在的目录
1230
+ * - 'fail permission denied, open ${dirPath}': 指定的 filePath 路径没有写权限
1231
+ * - 'fail the maximum size of the file storage limit is exceeded': 存储空间不足
1232
+ * - 'fail sdcard not mounted': android sdcard 挂载失败
1233
+ * */
1234
+ errMsg: string
1235
+ }
1236
+ interface TruncateSyncOption {
1237
+ /** 要截断的文件路径 (本地路径) */
1238
+ filePath: string
1239
+ /** 截断位置,默认0。如果 length 小于文件长度(字节),则只有前面 length 个字节会保留在文件中,其余内容会被删除;如果 length 大于文件长度,则会对其进行扩展,并且扩展部分将填充空字节('\0') */
1240
+ length?: number
1241
+ }
1242
+ interface WriteOption {
1243
+ /** 文件描述符。fd 通过 FileSystemManager.open 或 FileSystemManager.openSync 接口获得 */
1244
+ fd: string
1245
+ /** 写入的内容,类型为 String 或 ArrayBuffer */
1246
+ data: string | ArrayBuffer
1247
+ /** 只在 data 类型是 ArrayBuffer 时有效,决定 arrayBuffe 中要被写入的部位,即 arrayBuffer 中的索引,默认0 */
1248
+ offset?: number
1249
+ /** 只在 data 类型是 ArrayBuffer 时有效,指定要写入的字节数,默认为 arrayBuffer 从0开始偏移 offset 个字节后剩余的字节数 */
1250
+ length?: number
1251
+ /** 只在 data 类型是 String 时有效,指定写入文件的字符编码,默认为 utf8 */
1252
+ encoding?: keyof FileSystemManager.Encoding
1253
+ /** 指定文件开头的偏移量,即数据要被写入的位置。当 position 不传或者传入非 Number 类型的值时,数据会被写入当前指针所在位置。 */
1254
+ position?: number
1255
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
1256
+ complete?: (res: TaroGeneral.CallbackResult) => void
1257
+ /** 接口调用失败的回调函数 */
1258
+ fail?: (result: WriteFailCallbackResult) => void
1259
+ /** 接口调用成功的回调函数 */
1260
+ success?: (res: WriteSuccessCallbackResult) => void
1261
+ }
1262
+ interface WriteFailCallbackResult extends TaroGeneral.CallbackResult {
1263
+ /** 错误信息
1264
+ *
1265
+ * 可选值:
1266
+ * 'bad file descriptor': 无效的文件描述符
1267
+ * 'fail permission denied': 指定的 fd 路径没有写权限
1268
+ * 'fail sdcard not mounted': android sdcard 挂载失败
1269
+ * */
1270
+ errMsg: string
1271
+ }
1272
+ interface WriteSuccessCallbackResult extends TaroGeneral.CallbackResult {
1273
+ /** 实际被写入到文件中的字节数(注意,被写入的字节数不一定与被写入的字符串字符数相同) */
1274
+ bytesWritten: number
1275
+ /** 调用结果 */
1276
+ errMsg: string
1277
+ }
1278
+ interface WriteSyncOption {
1279
+ /** 文件描述符。fd 通过 FileSystemManager.open 或 FileSystemManager.openSync 接口获得 */
1280
+ fd: string
1281
+ /** 写入的内容,类型为 String 或 ArrayBuffer */
1282
+ data: string | ArrayBuffer
1283
+ /** 只在 data 类型是 ArrayBuffer 时有效,决定 arrayBuffe 中要被写入的部位,即 arrayBuffer 中的索引,默认0 */
1284
+ offset?: number
1285
+ /** 只在 data 类型是 ArrayBuffer 时有效,指定要写入的字节数,默认为 arrayBuffer 从0开始偏移 offset 个字节后剩余的字节数 */
1286
+ length?: number
1287
+ /** 只在 data 类型是 String 时有效,指定写入文件的字符编码,默认为 utf8 */
1288
+ encoding?: keyof FileSystemManager.Encoding
1289
+ /** 指定文件开头的偏移量,即数据要被写入的位置。当 position 不传或者传入非 Number 类型的值时,数据会被写入当前指针所在位置。 */
1290
+ position?: number
1291
+ }
1292
+ }
1293
+
1294
+ /** 文件读取结果。 通过 [FileSystemManager.readSync](./FileSystemManager#readsync) 接口返回
1295
+ * @supported weapp
1296
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/ReadResult.html
1297
+ */
1298
+ interface ReadResult {
1299
+ /** 实际读取的字节数 */
1300
+ bytesRead: number
1301
+ /** 被写入的缓存区的对象,即接口入参的 arrayBuffer */
1302
+ arrayBuffer: ArrayBuffer
1303
+ }
1304
+
1305
+ /** 描述文件状态的对象
1306
+ * @supported weapp
1307
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/Stats.html
1308
+ */
1309
+ interface Stats {
1310
+ /** 文件的类型和存取的权限,对应 POSIX stat.st_mode */
1311
+ mode: string
1312
+ /** 文件大小,单位:B,对应 POSIX stat.st_size */
1313
+ size: number
1314
+ /** 文件最近一次被存取或被执行的时间,UNIX 时间戳,对应 POSIX stat.st_atime */
1315
+ lastAccessedTime: number
1316
+ /** 文件最后一次被修改的时间,UNIX 时间戳,对应 POSIX stat.st_mtime */
1317
+ lastModifiedTime: number
1318
+ /** 判断当前文件是否一个目录
1319
+ * @supported weapp, alipay, jd, qq, tt
1320
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/Stats.isDirectory.html
1321
+ */
1322
+ isDirectory(): boolean
1323
+ /** 判断当前文件是否一个普通文件
1324
+ * @supported weapp, aliapy, jd, qq, tt
1325
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/Stats.isFile.html
1326
+ */
1327
+ isFile(): boolean
1328
+ }
1329
+
1330
+ /** 文件写入结果。 通过 [FileSystemManager.writeSync](./FileSystemManager#writesync) 接口返回
1331
+ * @supported weapp
1332
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/WriteResult.html
1333
+ */
1334
+ interface WriteResult {
1335
+ /** 实际被写入到文件中的字节数(注意,被写入的字节数不一定与被写入的字符串字符数相同) */
1336
+ bytesWritten: number
1337
+ }
1338
+
1339
+ interface TaroStatic {
1340
+ /** 保存文件系统的文件到用户磁盘,仅在 PC 端支持
1341
+ * @supported weapp, alipay
1342
+ * @example
1343
+ * ```tsx
1344
+ * Taro.saveFileToDisk({
1345
+ * filePath: `${Taro.env.USER_DATA_PATH}/hello.txt`,
1346
+ * success(res) {
1347
+ * console.log(res)
1348
+ * },
1349
+ * fail(res) {
1350
+ * console.error(res)
1351
+ * }
1352
+ * })
1353
+ * ```
1354
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/wx.saveFileToDisk.html
1355
+ */
1356
+ saveFileToDisk(option: saveFileToDisk.Option): Promise<TaroGeneral.CallbackResult>
1357
+
1358
+ /** 保存文件到本地。**注意:saveFile 会把临时文件移动,因此调用成功后传入的 tempFilePath 将不可用**
1359
+ * @supported weapp, alipay, swan, jd, qq, tt, rn
1360
+ * @example
1361
+ * ```tsx
1362
+ * Taro.chooseImage({
1363
+ * success: function (res) {
1364
+ * var tempFilePaths = res.tempFilePaths
1365
+ * Taro.saveFile({
1366
+ * tempFilePath: tempFilePaths[0],
1367
+ * success: function (res) {
1368
+ * var savedFilePath = res.savedFilePath
1369
+ * }
1370
+ * })
1371
+ * }
1372
+ * })
1373
+ * ```
1374
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/wx.saveFile.html
1375
+ */
1376
+ saveFile(option: saveFile.Option): Promise<saveFile.SuccessCallbackResult | saveFile.FailCallbackResult>
1377
+
1378
+ /** 删除该小程序下已保存的本地缓存文件
1379
+ * @supported weapp, rn, tt
1380
+ * @example
1381
+ * ```tsx
1382
+ * Taro.getSavedFileList({
1383
+ * success: function (res) {
1384
+ * if (res.fileList.length > 0){
1385
+ * Taro.removeSavedFile({
1386
+ * filePath: res.fileList[0].filePath,
1387
+ * complete: function (res) {
1388
+ * console.log(res)
1389
+ * }
1390
+ * })
1391
+ * }
1392
+ * }
1393
+ * })
1394
+ * ```
1395
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/wx.removeSavedFile.html
1396
+ */
1397
+ removeSavedFile(option: removeSavedFile.Option): Promise<TaroGeneral.CallbackResult>
1398
+
1399
+ /** 新开页面打开文档,支持格式
1400
+ * @supported weapp, alipay, swan, jd, qq, tt
1401
+ * @example
1402
+ * ```tsx
1403
+ * Taro.downloadFile({
1404
+ * url: 'https://example.com/somefile.pdf',
1405
+ * success: function (res) {
1406
+ * var filePath = res.tempFilePath
1407
+ * Taro.openDocument({
1408
+ * filePath: filePath,
1409
+ * success: function (res) {
1410
+ * console.log('打开文档成功')
1411
+ * }
1412
+ * })
1413
+ * }
1414
+ * })
1415
+ * ```
1416
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/wx.openDocument.html
1417
+ */
1418
+ openDocument(option: openDocument.Option): Promise<TaroGeneral.CallbackResult>
1419
+
1420
+ /** 获取本地已保存的文件列表
1421
+ * @supported weapp, alipay, swan, jd, qq, tt, rn
1422
+ * @example
1423
+ * ```tsx
1424
+ * Taro.getSavedFileList({
1425
+ * success: function (res) {
1426
+ * console.log(res.fileList)
1427
+ * }
1428
+ * })
1429
+ * ```
1430
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/wx.getSavedFileList.html
1431
+ */
1432
+ getSavedFileList(option?: getSavedFileList.Option): Promise<getSavedFileList.SuccessCallbackResult>
1433
+
1434
+ /** 获取本地文件的文件信息。此接口只能用于获取已保存到本地的文件,若需要获取临时文件信息,请使用 [Taro.getFileInfo](/docs/apis/files/getFileInfo) 接口。
1435
+ * @supported weapp, alipay, swan, jd, qq, rn
1436
+ * @example
1437
+ * ```tsx
1438
+ * Taro.getSavedFileInfo({
1439
+ * filePath: 'wxfile://somefile', //仅做示例用,非真正的文件路径
1440
+ * success: function (res) {
1441
+ * console.log(res.size)
1442
+ * console.log(res.createTime)
1443
+ * }
1444
+ * })
1445
+ * ```
1446
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/wx.getSavedFileInfo.html
1447
+ */
1448
+ getSavedFileInfo(option: getSavedFileInfo.Option): Promise<getSavedFileInfo.SuccessCallbackResult>
1449
+
1450
+ /**
1451
+ * 获取该小程序下的 本地临时文件 或 本地缓存文件 信息
1452
+ * @supported weapp, alipay, swan, jd, qq, tt, rn
1453
+ * @example
1454
+ * ```tsx
1455
+ * Taro.getFileInfo({
1456
+ * success: function (res) {
1457
+ * console.log(res.size)
1458
+ * console.log(res.digest)
1459
+ * }
1460
+ * })
1461
+ * ```
1462
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/wx.getFileInfo.html
1463
+ */
1464
+ getFileInfo(option: getFileInfo.Option): Promise<getFileInfo.SuccessCallbackResult | getFileInfo.FailCallbackResult>
1465
+
1466
+ /** 获取全局唯一的文件管理器
1467
+ * @supported weapp, alipay, swan, jd, qq, tt, harmony_hybrid, harmony
1468
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/file/wx.getFileSystemManager.html
1469
+ */
1470
+ getFileSystemManager(): FileSystemManager
1471
+ }
1472
+ }