get-file-system-manager.uvue 46.3 KB
Newer Older
1
<template>
2
  <!-- #ifdef APP -->
W
WOSHIMAHAIFENG 已提交
3 4
  <text>显示简易操作日志,详细日志需真机运行查看</text><button size="mini" @click="log=''">清空日志</button>
  <text style="margin: 2px; padding: 2px; border: 1px solid #000000;">{{ log }}</text>
W
WOSHIMAHAIFENG 已提交
5
  <scroll-view style="flex: 1;">
6
  <!-- #endif -->
W
WOSHIMAHAIFENG 已提交
7 8 9 10 11 12 13 14 15 16 17 18 19
    <button class="btnstyle" type="primary" @tap="statFileInfoTest" id="btn-stat-file">递归获取目录files的Stats对象{{statFile}}</button>
    <button class="btnstyle" type="primary" @tap="mkdirTest" id="btn-mkdir">创建文件夹{{mkdirFile}}</button>
    <button class="btnstyle" type="primary" @tap="writeFileTest" id="btn-write-file">覆盖写入文件{{writeFile}}</button>
    <button class="btnstyle" type="primary" @tap="readDirTest" id="btn-read-dir">读取文件夹{{readDir}}</button>
    <button class="btnstyle" type="primary" @tap="readFileTest" id="btn-read-file">读取文件{{readFile}}</button>
    <button class="btnstyle" type="primary" @tap="copyFileTest" id="btn-copy-file">复制文件{{copyFromFile}}到{{copyToFile}}</button>
    <button class="btnstyle" type="primary" @tap="renameFileTest" id="btn-rename-file">重命名文件{{renameFromFile}}到{{renameToFile}}</button>
    <button class="btnstyle" type="primary" @tap="accessFileTest" id="btn-access-file">判断文件{{accessFile}}是否存在</button>
    <button class="btnstyle" type="primary" @tap="getFileInfoTest" id="btn-get-file-info">获取文件信息{{getFileInfoFile}}</button>
    <button class="btnstyle" type="primary" @tap="unlinkTest" id="btn-unlink-file">删除文件{{unlinkFile}}</button>
    <button class="btnstyle" type="primary" @tap="copyStaticToFilesTest" id="btn-copyStatic-file">从static目录复制文件到a目录</button>
    <button class="btnstyle" type="primary" @tap="unlinkAllFileTest" id="btn-clear-file">删除文件夹{{rmDirFile}}下的所有文件</button>
    <button class="btnstyle" type="primary" @tap="rmdirTest" id="btn-remove-dir">删除文件夹{{rmDirFile}}</button>
W
WOSHIMAHAIFENG 已提交
20 21


W
WOSHIMAHAIFENG 已提交
22 23
    <!-- #ifdef APP-ANDROID -->
    <button class="btnstyle" type="primary" @tap="statFileInfoSyncTest"
W
WOSHIMAHAIFENG 已提交
24
      id="btn-stat-file-sync">同步递归获取目录files的Stats对象{{statFile}}</button>
W
WOSHIMAHAIFENG 已提交
25 26 27 28 29 30 31 32 33 34
    <button class="btnstyle" type="primary" @tap="appendFileTest" id="btn-append-file">在文件{{readFile}}结尾追加内容</button>
    <button class="btnstyle" type="primary" @tap="appendFileSyncTest" id="btn-append-file-sync">同步在文件{{readFile}}结尾追加内容</button>
    <button class="btnstyle" type="primary" @tap="writeFileSyncTest" id="btn-write-file-sync">同步覆盖写入文件{{writeFile}}</button>
    <button class="btnstyle" type="primary" @tap="readFileSyncTest" id="btn-read-file-sync">同步读取文件{{readFile}}</button>
    <button class="btnstyle" type="primary" @tap="unlinkSyncTest" id="btn-unlink-file-sync">同步删除文件{{unlinkFile}}</button>
    <button class="btnstyle" type="primary" @tap="mkdirSyncTest" id="btn-mkdir-sync">同步创建文件夹{{mkdirFile}}</button>
    <button class="btnstyle" type="primary" @tap="rmdirSyncTest" id="btn-remove-dir-sync">同步删除文件夹{{rmDirFile}}</button>
    <button class="btnstyle" type="primary" @tap="readDirSyncTest" id="btn-read-dir-sync">同步读取文件夹{{readDir}}</button>
    <button class="btnstyle" type="primary" @tap="accessFileSyncTest" id="btn-access-file-sync">同步判断文件{{accessFile}}是否存在</button>
    <button class="btnstyle" type="primary" @tap="renameFileSync"
W
WOSHIMAHAIFENG 已提交
35
      id="btn-rename-file-sync">同步重命名文件{{renameFromFile}}到{{renameToFile}}</button>
W
WOSHIMAHAIFENG 已提交
36
    <button class="btnstyle" type="primary" @tap="copyFileSyncTest"
W
WOSHIMAHAIFENG 已提交
37
      id="btn-copy-file-sync">同步复制文件{{copyFromFile}}到{{copyToFile}}</button>
W
WOSHIMAHAIFENG 已提交
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
    <button class="btnstyle" type="primary" @tap="saveFileTest" id="btn-save-file">保存临时文件到本地</button>
    <button class="btnstyle" type="primary" @tap="saveFileSyncTest" id="btn-save-file-sync">同步保存临时文件到本地</button>
    <button class="btnstyle" type="primary" @tap="removeSavedFileTest" id="btn-remove-saved-file">删除已保存的本地文件</button>
    <button class="btnstyle" type="primary" @tap="unzipFileTest" id="btn-unzip-file-sync">解压文件</button>
    <button class="btnstyle" type="primary" @tap="getSavedFileListTest" id="btn-getsaved-filelist">获取该已保存的本地缓存文件列表</button>
    <button class="btnstyle" type="primary" @tap="truncateFileTest" id="btn-truncate-file">对文件{{writeFile}}内容进行截断操作</button>
    <button class="btnstyle" type="primary" @tap="truncateFileSyncTest" id="btn-truncate-file-sync">同步对文件{{writeFile}}内容进行截断操作</button>
    <button class="btnstyle" type="primary" @tap="readCompressedFileTest" id="btn-compressed-file">读取指定压缩类型的本地文件内容</button>
    <button class="btnstyle" type="primary" @tap="readCompressedFileSyncTest" id="btn-compressed-file-sync">同步读取指定压缩类型的本地文件内容</button>
    <button class="btnstyle" type="primary" @tap="openFileTest" id="btn-open-file">打开文件{{readFile}},返回描述符</button>
    <button class="btnstyle" type="primary" @tap="openFileSyncTest" id="btn-open-file-sync">同步打开文件{{readFile}},返回描述符</button>
    <button class="btnstyle" type="primary" @tap="closeTest" id="btn-close-file">通过文件描述符关闭文件{{readFile}}</button>
    <button class="btnstyle" type="primary" @tap="closeSyncTest" id="btn-close-file-sync">通过文件描述符同步关闭文件{{readFile}}</button>
    <button class="btnstyle" type="primary" @tap="writeTest" id="btn-write">通过文件描述符写入文件{{readFile}}</button>
    <button class="btnstyle" type="primary" @tap="writeSyncTest" id="btn-read-file">同步通过文件描述符写入文件{{readFile}}</button>
    <button class="btnstyle" type="primary" @tap="fstatTest" id="btn-fstat-file">通过文件描述符获取{{statFile}}的状态信息</button>
    <button class="btnstyle" type="primary" @tap="fstatSyncTest" id="btn-fstat-file-sync">同步通过文件描述符获取{{statFile}}的状态信息</button>
    <button class="btnstyle" type="primary" @tap="ftruncateFileTest" id="btn-ftruncate-file">通过文件描述符对文件{{writeFile}}内容进行截断</button>
    <button class="btnstyle" type="primary" @tap="ftruncateFileSyncTest"
      id="btn-ftruncate-file-sync">同步通过文件描述符对文件{{writeFile}}内容进行截断</button>
    <button class="btnstyle" type="primary" @tap="readZipEntry" id="btn-readzip-entry">读取压缩包内的文件</button>
    <view style="height: 4px;"></view>
    <!-- #endif -->
61 62 63
  <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
64 65 66
</template>

<script>
67 68 69 70 71
  export default {

    data() {
      return {
        log: "",
72 73 74
        /**
         * 自动化测试需要关闭log
         */
H
hdx 已提交
75
        logAble: true,
76 77 78
        fileListSuccess: [] as string[],
        fileListComplete: [] as string[],
        accessFileRet: '',
79 80
        lastFailError: new UniError("uni-file-manager", 1300000, "mock error"),
        lastCompleteError: new UniError("uni-file-manager", 1300000, "mock error"),
81 82 83
        readDir: 'a',
        readFileRet: "",
        writeFileContent: "中文 en.\r\n\t换行",
W
WOSHIMAHAIFENG 已提交
84
        appendFileContent: "append content",
85 86 87 88 89 90
        getFileInfoAlgorithm: "md5",
        getFileInfoSize: -1,
        getFileInfoDigest: "",
        unlinkFile: 'a/1.txt',
        accessFile: 'a/1.txt',
        writeFile: 'a/1.txt',
W
WOSHIMAHAIFENG 已提交
91 92 93
        writeData: 'insert data哈哈哈',
        brFile: 'a/1.txt.br',
        temFile: 'a/1.txt',
94 95 96 97 98 99 100 101 102 103
        copyFromFile: 'a/1.txt',
        copyToFile: 'a/2.txt',
        renameFromFile: 'a/2.txt',
        renameToFile: 'a/3.txt',
        getFileInfoFile: 'a/1.txt',
        statFile: '',
        rmDirFile: 'a',
        mkdirFile: 'a',
        readFile: 'a/1.txt',
        recursiveVal: true,
104
        done: false,
105 106 107
        writeFileEncoding: "utf-8",
        readFileEncoding: "utf-8",
        statsRet: [] as Array<FileStats>,
W
WOSHIMAHAIFENG 已提交
108 109 110 111 112 113 114 115 116
        unzipFile: 'zip/1.zip',
        targetZip: "unzip",
        renameFileRet: '',
        saveFileRet: '',
        removeSavedFileRet: '',
        fd: '',
        closeFileRet: '',
        bytesWritten: 0,
        fstat: new Stats(),
W
WOSHIMAHAIFENG 已提交
117 118
        ftruncateRet: '',
        readZipFile: 'to.zip',
119 120 121 122 123
        /**
         * 待测试的全局环境变量
         */
        basePath: uni.env.USER_DATA_PATH,
        copyToBasePath: uni.env.USER_DATA_PATH,
124 125 126 127 128
        globalTempPath: uni.env.CACHE_PATH,
        globalRootPath: uni.env.SANDBOX_PATH,
        globalUserDataPath: uni.env.USER_DATA_PATH
      }
    },
129 130 131
    onLoad() {
    },

132
    methods: {
133
      statFileInfoTest: function (_ : any) {
H
hdx 已提交
134
        const fileManager = uni.getFileSystemManager()
135
        fileManager.stat({
W
wanganxp 已提交
136 137
          // path: `${this.basePath}${this.statFile}`, //USER_DATA_PATH
          path: `${this.globalTempPath}${this.statFile}`, //CACHE_PATH
138
          recursive: this.recursiveVal,
139
          success: (res : StatSuccessResult) => {
H
hdx 已提交
140
            if (this.logAble) {
141 142
              this.log += 'statFileInfoTest success:' + JSON.stringify(res) + '\n\n'
            }
143
            console.log('statFileInfoTest success', res)
杜庆泉's avatar
杜庆泉 已提交
144
            this.statsRet = res.stats
145 146
            console.log('this.statsRet', this.statsRet)
          },
147
          fail: (res : UniError) => {
H
hdx 已提交
148
            if (this.logAble) {
149 150
              this.log += 'statFileInfoTest fail:' + JSON.stringify(res) + '\n\n'
            }
151
            console.log('statFileInfoTest fail', res)
杜庆泉's avatar
杜庆泉 已提交
152
            this.lastFailError = res
153
          },
154
          complete: (res : any) => {
155
            console.log("statFileInfoTest complete", res)
杜庆泉's avatar
杜庆泉 已提交
156
            this.done = true
157
            if (res instanceof UniError) {
杜庆泉's avatar
杜庆泉 已提交
158 159
              this.lastCompleteError = res
            }
160 161 162 163
          }
        } as StatOptions)
      },

164
      getFileInfoTest: function () {
H
hdx 已提交
165
        const fileManager = uni.getFileSystemManager()
166 167 168 169

        fileManager.getFileInfo({
          filePath: `${this.basePath}${this.getFileInfoFile}`,
          digestAlgorithm: this.getFileInfoAlgorithm,
170
          success: (res : GetFileInfoSuccessResult) => {
H
hdx 已提交
171
            if (this.logAble) {
172 173
              this.log += 'getFileInfoTest success:' + JSON.stringify(res) + '\n\n'
            }
174
            console.log('success', res)
175 176
            this.getFileInfoSize = res.size
            this.getFileInfoDigest = res.digest
177
          },
178
          fail: (res : UniError) => {
H
hdx 已提交
179
            if (this.logAble) {
180 181
              this.log += 'getFileInfoTest fail:' + JSON.stringify(res) + '\n\n'
            }
182
            console.log('fail', res)
183
            this.lastFailError = res
184
          },
185
          complete: (res : any) => {
186
            console.log("complete", res)
187
            this.done = true
188
            if (res instanceof UniError) {
189 190
              this.lastCompleteError = res
            }
191 192 193
          }
        } as GetFileInfoOptions)
      },
194

195
      copyFileTest: function () {
H
hdx 已提交
196
        const fileManager = uni.getFileSystemManager()
197

198 199 200
        fileManager.copyFile({
          srcPath: `${this.basePath}${this.copyFromFile}`,
          destPath: `${this.copyToBasePath}${this.copyToFile}`,
201
          success: (res : FileManagerSuccessResult) => {
H
hdx 已提交
202
            if (this.logAble) {
203 204
              this.log += 'copyFileTest success:' + JSON.stringify(res) + '\n\n'
            }
205 206
            console.log('success', res)
          },
207
          fail: (res : UniError) => {
H
hdx 已提交
208
            if (this.logAble) {
209 210
              this.log += 'copyFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
211
            console.log('fail', res)
212
            this.lastFailError = res
213
          },
214
          complete: (res : any) => {
215
            console.log("complete", res)
216
            this.done = true
217
            if (res instanceof UniError) {
218 219
              this.lastCompleteError = res
            }
220 221 222 223
          }
        } as CopyFileOptions)
      },

224
      renameFileTest: function () {
H
hdx 已提交
225
        const fileManager = uni.getFileSystemManager()
226 227 228 229

        fileManager.rename({
          oldPath: `${this.basePath}${this.renameFromFile}`,
          newPath: `${this.basePath}${this.renameToFile}`,
W
WOSHIMAHAIFENG 已提交
230
          success: (res) => {
H
hdx 已提交
231
            if (this.logAble) {
232 233
              this.log += 'renameFileTest success:' + JSON.stringify(res) + '\n\n'
            }
234 235
            console.log('success', res)
          },
236
          fail: (res : UniError) => {
H
hdx 已提交
237
            if (this.logAble) {
238 239
              this.log += 'renameFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
240
            console.log('fail', res)
241
            this.lastFailError = res
242
          },
243
          complete: (res : any) => {
244
            this.done = true
245 246
            console.log("complete", res)
            if (res instanceof UniError) {
247 248
              this.lastCompleteError = res
            }
249 250 251 252
          }
        } as RenameOptions)
      },

253
      readDirTest: function () {
H
hdx 已提交
254
        const fileManager = uni.getFileSystemManager()
255 256
        fileManager.readdir({
          dirPath: `${this.basePath}${this.readDir}`,
257
          success: (res : ReadDirSuccessResult) => {
H
hdx 已提交
258
            if (this.logAble) {
259 260
              this.log += 'readDirTest success:' + JSON.stringify(res) + '\n\n'
            }
261
            console.log("success", res)
262
            this.fileListSuccess = res.files
263
          },
264
          fail: (res : UniError) => {
H
hdx 已提交
265
            if (this.logAble) {
266 267
              this.log += 'readDirTest fail:' + JSON.stringify(res) + '\n\n'
            }
268
            console.log('fail', res)
269
            this.lastFailError = res
270
          },
271
          complete: (res : any) => {
272
            console.log("complete", res)
273
            this.done = true
274
            if (res instanceof UniError) {
275
              this.lastCompleteError = res
276 277
            } else {
              this.fileListComplete = (res as ReadDirSuccessResult).files
278
            }
279 280 281 282
          }
        } as ReadDirOptions)
      },

283
      writeFileTest: function (_ : any) {
H
hdx 已提交
284
        const fileManager = uni.getFileSystemManager()
285 286 287 288 289

        fileManager.writeFile({
          filePath: `${this.basePath}${this.writeFile}`,
          data: this.writeFileContent,
          encoding: this.writeFileEncoding,
W
WOSHIMAHAIFENG 已提交
290
          success: (res) => {
H
hdx 已提交
291
            if (this.logAble) {
292 293
              this.log += 'writeFileTest success:' + JSON.stringify(res) + '\n\n'
            }
294 295
            console.log('success', res)
          },
W
WOSHIMAHAIFENG 已提交
296
          fail: (res : UniError) => {
H
hdx 已提交
297
            if (this.logAble) {
298 299
              this.log += 'writeFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
300
            console.log('fail')
301
            this.lastFailError = res
302
          },
303
          complete: (res : any) => {
304
            this.done = true
305 306
            console.log("complete")
            if (res instanceof UniError) {
307 308
              this.lastCompleteError = res
            }
W
WOSHIMAHAIFENG 已提交
309

310 311 312
          }
        } as WriteFileOptions)
      },
313

314
      readFileTest: function () {
H
hdx 已提交
315
        const fileManager = uni.getFileSystemManager()
316

317 318 319
        fileManager.readFile({
          filePath: `${this.basePath}${this.readFile}`,
          encoding: this.readFileEncoding,
320
          success: (res : ReadFileSuccessResult) => {
H
hdx 已提交
321
            if (this.logAble) {
322 323
              this.log += 'readFileTest success:' + JSON.stringify(res) + '\n\n'
            }
324
            console.log('success', res)
325
            this.readFileRet = res.data
326
          },
327
          fail: (res : UniError) => {
H
hdx 已提交
328
            if (this.logAble) {
329 330
              this.log += 'readFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
331
            console.log('fail', res)
332
            this.lastFailError = res
333
          },
334
          complete: (res : any) => {
335
            console.log("complete", res)
336
            this.done = true
337
            if (res instanceof UniError) {
338 339
              this.lastCompleteError = res
            }
340 341 342 343
          }
        } as ReadFileOptions)
      },

344
      rmdirTest: function () {
H
hdx 已提交
345
        const fileManager = uni.getFileSystemManager()
346 347 348
        fileManager.rmdir({
          dirPath: `${this.basePath}${this.rmDirFile}`,
          recursive: this.recursiveVal,
349
          success: (res : FileManagerSuccessResult) => {
H
hdx 已提交
350
            if (this.logAble) {
351 352
              this.log += 'rmdirTest success:' + JSON.stringify(res) + '\n\n'
            }
353 354
            console.log('success', res)
          },
355
          fail: (res : UniError) => {
H
hdx 已提交
356
            if (this.logAble) {
357 358
              this.log += 'rmdirTest fail:' + JSON.stringify(res) + '\n\n'
            }
359
            console.log('fail', res)
360
            this.lastFailError = res
361
          },
362
          complete: (res : any) => {
363
            console.log("complete", res)
364
            this.done = true
365
            if (res instanceof UniError) {
366 367
              this.lastCompleteError = res
            }
368 369 370
          }
        } as RmDirOptions)
      },
371

372
      mkdirTest: function () {
373
        // 准备测试数据
H
hdx 已提交
374
        const fileManager = uni.getFileSystemManager()
375 376 377 378

        fileManager.mkdir({
          dirPath: `${this.basePath}${this.mkdirFile}`,
          recursive: this.recursiveVal,
379
          success: (res : FileManagerSuccessResult) => {
H
hdx 已提交
380
            if (this.logAble) {
381 382
              this.log += 'mkdirTest success:' + JSON.stringify(res) + '\n\n'
            }
383 384
            console.log('success', res)
          },
385
          fail: (res : UniError) => {
H
hdx 已提交
386
            if (this.logAble) {
387 388
              this.log += 'mkdirTest fail:' + JSON.stringify(res) + '\n\n'
            }
389
            console.log('fail', res)
390
            this.lastFailError = res
391
          },
392
          complete: (res : any) => {
393
            if (res instanceof UniError) {
394 395 396
              this.lastCompleteError = res
            }
            this.done = true
397 398 399
            console.log("complete", res)
          }
        } as MkDirOptions)
400

401
      },
402
      accessFileTest: function () {
403
        this.accessFileRet = ''
H
hdx 已提交
404
        const fileManager = uni.getFileSystemManager()
405 406
        fileManager.access({
          path: `${this.basePath}${this.accessFile}`,
407
          success: (res : FileManagerSuccessResult) => {
H
hdx 已提交
408
            if (this.logAble) {
409 410
              this.log += 'accessFileTest success:' + JSON.stringify(res) + '\n\n'
            }
411
            console.log('success', res)
412
            this.accessFileRet = res.errMsg
413
          },
414
          fail: (res : UniError) => {
H
hdx 已提交
415
            if (this.logAble) {
416 417
              this.log += 'accessFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
418
            console.log('fail', res)
419
            this.lastFailError = res
420
          },
421
          complete: (res : any) => {
422
            if (res instanceof UniError) {
423 424
              this.lastCompleteError = res
            }
425
            console.log("complete", res)
426
            this.done = true
427 428
          }
        } as AccessOptions)
429

430
      },
431
      unlinkTest: function () {
H
hdx 已提交
432
        const fileManager = uni.getFileSystemManager()
433 434 435

        fileManager.unlink({
          filePath: `${this.basePath}${this.unlinkFile}`,
436
          success: (res : FileManagerSuccessResult) => {
H
hdx 已提交
437
            if (this.logAble) {
438 439
              this.log += 'unlinkTest success:' + JSON.stringify(res) + '\n\n'
            }
440 441
            console.log('success', res)
          },
442
          fail: (res : UniError) => {
H
hdx 已提交
443
            if (this.logAble) {
444 445
              this.log += 'unlinkTest fail:' + JSON.stringify(res) + '\n\n'
            }
446
            console.log('fail', res)
447
            this.lastFailError = res
448
          },
449
          complete: (res : any) => {
450
            if (res instanceof UniError) {
451 452
              this.lastCompleteError = res
            }
453
            console.log("complete", res)
454
            this.done = true
455 456 457
          }
        } as UnLinkOptions)
      },
458
      unlinkAllFileTest: function () {
H
hdx 已提交
459
        const fileManager = uni.getFileSystemManager()
W
wanganxp 已提交
460
        fileManager.readdir({
461
          dirPath: `${this.basePath}${this.rmDirFile}`,
462
          success: (res : ReadDirSuccessResult) => {
463
            console.log("success to readdir", res)
W
wanganxp 已提交
464
            res.files.forEach(element => {
465 466 467
              console.log(element)
              fileManager.unlink({
                filePath: `${this.basePath}${this.rmDirFile}/${element}`,
468
                success: (res : FileManagerSuccessResult) => {
H
hdx 已提交
469
                  if (this.logAble) {
470 471
                    this.log += 'unlinkAllFileTest success:' + JSON.stringify(res) + '\n\n'
                  }
472 473
                  console.log('success unlink', res)
                },
474
                fail: (res : UniError) => {
H
hdx 已提交
475
                  if (this.logAble) {
476 477
                    this.log += 'unlinkAllFileTest fail:' + JSON.stringify(res) + '\n\n'
                  }
478 479 480
                  console.log('fail unlink', res)
                  this.lastFailError = res
                },
W
WOSHIMAHAIFENG 已提交
481
                complete: (res : any) => {
482 483 484 485 486 487 488
                  if (res instanceof UniError) {
                    this.lastCompleteError = res
                  }
                  console.log("complete unlink", res)
                  this.done = true
                }
              } as UnLinkOptions)
W
wanganxp 已提交
489
            });
490
          },
W
WOSHIMAHAIFENG 已提交
491
          fail: (res : UniError) => {
492 493
            this.log += 'unlinkAllFileTest fail:' + JSON.stringify(res) + '\n\n'
            console.log('fail to readdir', res)
W
wanganxp 已提交
494
            this.lastFailError = res
495
          },
W
WOSHIMAHAIFENG 已提交
496
          complete: (res : any) => {
497
            console.log("complete readdir", res)
W
wanganxp 已提交
498
            this.done = true
499
            if (res instanceof UniError) {
W
wanganxp 已提交
500
              this.lastCompleteError = res
501 502
            } else {
              this.fileListComplete = (res as ReadDirSuccessResult).files
W
wanganxp 已提交
503
            }
504
          }
W
wanganxp 已提交
505 506
        } as ReadDirOptions)
      },
507
      copyStaticToFilesTest: function () {
H
hdx 已提交
508
        const fileManager = uni.getFileSystemManager()
509 510

        fileManager.copyFile({
511
          srcPath: "/static/list-mock/mock.json",
512
          destPath: `${this.copyToBasePath}/a/mock.json`,
W
WOSHIMAHAIFENG 已提交
513
          success: (res : FileManagerSuccessResult) => {
H
hdx 已提交
514
            if (this.logAble) {
515 516
              this.log += 'copyFileTest success:' + JSON.stringify(res) + '\n\n'
            }
517 518
            console.log('success', res)
          },
519
          fail: (res : UniError) => {
H
hdx 已提交
520
            if (this.logAble) {
521 522
              this.log += 'copyFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
523 524 525
            console.log('fail', res)
            this.lastFailError = res
          },
526
          complete: (res : any) => {
527 528 529 530 531 532 533 534
            console.log("complete", res)
            this.done = true
            if (res instanceof UniError) {
              this.lastCompleteError = res
            }
          }
        } as CopyFileOptions)
      },
W
WOSHIMAHAIFENG 已提交
535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738
      //start
      appendFileTest: function (_ : any) {
        const fileManager = uni.getFileSystemManager()
        fileManager.appendFile({
          filePath: `${this.basePath}${this.writeFile}`,
          data: this.appendFileContent,
          encoding: this.writeFileEncoding,
          success: (res : FileManagerSuccessResult) => {
            if (this.logAble) {
              this.log += 'appendFileTest success:' + JSON.stringify(res) + '\n\n'
            }
            console.log('success', res)
          },
          fail: (res : UniError) => {
            if (this.logAble) {
              this.log += 'appendFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail')
            this.lastFailError = res
          },
          complete: (res : any) => {
            this.done = true
            console.log("complete")
            if (res instanceof UniError) {
              this.lastCompleteError = res
            }

          }
        } as AppendFileOptions)
      },
      writeFileSyncTest: function (_ : any) {
        try {
          const fileManager = uni.getFileSystemManager()
          fileManager.writeFileSync(`${this.basePath}${this.writeFile}`, this.writeFileContent, this.writeFileEncoding)
          if (this.logAble) {
            this.log += 'writeFileSyncTest success:' + '\n\n'
          }
          this.done = true
        } catch (e) {
          if (this.logAble) {
            this.log += 'writeFileSyncTest fail:' + e + '\n\n'
          }
          this.done = true
        }

      },
      readFileSyncTest: function () {
        try {
          const fileManager = uni.getFileSystemManager()
          let data = fileManager.readFileSync(
            `${this.basePath}${this.readFile}`,
            this.readFileEncoding)
          if (this.logAble) {
            this.log += 'readFileSyncTest result:' + data + '\n\n'
          }
          this.done = true
          this.readFileRet = data
        } catch (e) {
          if (this.logAble) {
            this.log += 'readFileSyncTest fail:' + e + '\n\n'
          }
          this.done = true
        }

      },
      unlinkSyncTest: function () {
        try {
          const fileManager = uni.getFileSystemManager()
          fileManager.unlinkSync(
            `${this.basePath}${this.unlinkFile}`)
          this.done = true
        } catch (e) {
          if (this.logAble) {
            this.log += 'unlinkSyncTest fail:' + e + '\n\n'
          }
          this.done = true
        }
      },
      mkdirSyncTest: function () {
        // 准备测试数据
        try {
          const fileManager = uni.getFileSystemManager()
          fileManager.mkdirSync(`${this.basePath}${this.mkdirFile}`, this.recursiveVal)
          this.done = true
        } catch (e) {
          this.done = true
          if (this.logAble) {
            this.log += 'mkdirSyncTest fail:' + e + '\n\n'
          }
        }

      },
      rmdirSyncTest: function () {
        try {
          const fileManager = uni.getFileSystemManager()
          fileManager.rmdirSync(
            `${this.basePath}${this.rmDirFile}`,
            this.recursiveVal)
          this.done = true
        } catch (e) {
          if (this.logAble) {
            this.log += 'rmdirSyncTest fail:' + e + '\n\n'
          }
          this.done = true
        }
      },
      readDirSyncTest: function () {
        try {
          const fileManager = uni.getFileSystemManager()
          let res = fileManager.readdirSync(
            `${this.basePath}${this.readDir}`)
          if (this.logAble) {
            this.log += 'readDirTest success:' + JSON.stringify(res) + '\n\n'
          }
          if (res != null) {
            this.fileListSuccess = res
          }
          this.done = true
        } catch (e) {
          if (this.logAble) {
            this.log += 'rmdirSyncTest fail:' + e + '\n\n'
          }
          this.done = true
        }
      },
      accessFileSyncTest: function () {
        this.accessFileRet = ''
        const fileManager = uni.getFileSystemManager()
        try {
          fileManager.accessSync(`${this.basePath}${this.accessFile}`)
          this.done = true
          this.accessFileRet = 'access:ok'
        } catch (e) {
          if (this.logAble) {
            this.log += 'rmdirSyncTest fail:' + e + '\n\n'
          }
          this.done = true
        }
      },
      renameFileSync: function () {
        const fileManager = uni.getFileSystemManager()
        try {
          fileManager.renameSync(`${this.basePath}${this.renameFromFile}`,
            `${this.basePath}${this.renameToFile}`)
          this.done = true
          this.renameFileRet = "rename:ok"

        } catch (e) {
          if (this.logAble) {
            this.log += 'rmdirSyncTest fail:' + e + '\n\n'
          }
          console.log('renameSync:' + e)
          this.done = true
        }
      },
      copyFileSyncTest: function () {
        const fileManager = uni.getFileSystemManager()
        try {
          fileManager.copyFileSync(
            `${this.basePath}${this.copyFromFile}`,
            `${this.copyToBasePath}${this.copyToFile}`)
          this.done = true
        } catch (e) {
          if (this.logAble) {
            this.log += 'rmdirSyncTest fail:' + e + '\n\n'
          }
          this.done = true
        }
      },
      appendFileSyncTest: function (_ : any) {
        const fileManager = uni.getFileSystemManager()
        try {
          fileManager.appendFileSync(
            `${this.basePath}${this.writeFile}`,
            this.appendFileContent,
            this.writeFileEncoding)
          this.done = true
        } catch (e) {
          if (this.logAble) {
            this.log += 'rmdirSyncTest fail:' + e + '\n\n'
          }
          this.done = true
        }
      },
      saveFileTest: function (_ : any) {
        const fileManager = uni.getFileSystemManager()
        console.log('=====' + uni.env.USER_DATA_PATH)
        fileManager.saveFile({
          tempFilePath: `${this.globalTempPath}${this.temFile}`,
          // filePath:`${this.basePath}local/`,
          success: (res : SaveFileSuccessResult) => {
            if (this.logAble) {
              this.log += 'saveFileTest success:' + JSON.stringify(res) + '\n\n'
            }
            console.log('success', res)
            this.saveFileRet = res.savedFilePath
          },
          fail: (res : UniError) => {
            if (this.logAble) {
              this.log += 'saveFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
            this.lastFailError = res
          },
W
WOSHIMAHAIFENG 已提交
739
          complete: (_) => {
W
WOSHIMAHAIFENG 已提交
740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777
            this.done = true
          }
        } as SaveFileOptions)
      },
      saveFileSyncTest: function (_ : any) {
        const fileManager = uni.getFileSystemManager()
        try {
          fileManager.saveFileSync(
            `${this.globalTempPath}${this.temFile}`, `${this.basePath}local/`)
          // filePath:`${this.basePath}local/`,)
          this.done = true

          //todo 后面打开
          // this.saveFileRet=res
        } catch (e) {
          console.log(e)
          this.done = true
        }
      },
      unzipFileTest: function (_ : any) {
        const fileManager = uni.getFileSystemManager()

        fileManager.unzip({
          zipFilePath: `${this.basePath}${this.unzipFile}`,
          targetPath: `${this.basePath}${this.targetZip}`,
          success: (res : FileManagerSuccessResult) => {
            if (this.logAble) {
              this.log += 'saveFileTest success:' + JSON.stringify(res) + '\n\n'
            }
            console.log('success', res)
          },
          fail: (res : UniError) => {
            if (this.logAble) {
              this.log += 'saveFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
            this.lastFailError = res
          },
W
WOSHIMAHAIFENG 已提交
778
          complete: (_) => {
W
WOSHIMAHAIFENG 已提交
779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818
            this.done = true
          }
        } as UnzipFileOptions)
      },

      getSavedFileListTest: function () {
        const fileManager = uni.getFileSystemManager()
        fileManager.getSavedFileList({
          success: (res : GetSavedFileListResult) => {
            if (this.logAble) {
              this.log += 'getSavedFileListTest success:' + JSON.stringify(res) + '\n\n'
            }
            console.log("success", res)
            this.fileListSuccess = res.fileList
          },
          fail: (res : UniError) => {
            if (this.logAble) {
              this.log += 'getSavedFileListTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
            this.lastFailError = res
          },
          complete: (res : any) => {
            console.log("complete", res)
            this.done = true
            if (res instanceof UniError) {
              this.lastCompleteError = res
            } else {
              this.fileListComplete = (res as GetSavedFileListResult).fileList
            }
          }
        } as GetSavedFileListOptions)
      },
      truncateFileTest() {
        const fileManager = uni.getFileSystemManager()
        fileManager.truncate({
          filePath: `${this.basePath}${this.writeFile}`,
          length: 7,
          success: (res : FileManagerSuccessResult) => {
            if (this.logAble) {
W
WOSHIMAHAIFENG 已提交
819
              this.log += 'truncateFileTest success:' + JSON.stringify(res) + '\n\n'
W
WOSHIMAHAIFENG 已提交
820 821 822 823 824
            }
            console.log("success", res)
          },
          fail: (res : UniError) => {
            if (this.logAble) {
W
WOSHIMAHAIFENG 已提交
825
              this.log += 'truncateFileTest fail:' + JSON.stringify(res) + '\n\n'
W
WOSHIMAHAIFENG 已提交
826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868
            }
            console.log('fail', res)
            this.lastFailError = res
          },
          complete: (res : any) => {
            console.log("complete", res)
            this.done = true
            if (res instanceof UniError) {
              this.lastCompleteError = res
            }
          }
        } as TruncateFileOptions)
      },
      truncateFileSyncTest() {
        const fileManager = uni.getFileSystemManager()
        try {
          fileManager.truncateSync(
            `${this.basePath}${this.writeFile}`,
            4)
          this.done = true
        } catch (e) {
          console.log(e)
          this.done = true
        }
      },
      readCompressedFileTest() {
        const fileManager = uni.getFileSystemManager()
        fileManager.readCompressedFile({
          filePath: `${this.basePath}${this.brFile}`,
          compressionAlgorithm: "br",
          success: (res : ReadCompressedFileResult) => {
            if (this.logAble) {
              this.log += 'readCompressedFileTest success:' + JSON.stringify(res) + '\n\n'
            }
            console.log("success", res)
          },
          fail: (res : UniError) => {
            if (this.logAble) {
              this.log += 'readCompressedFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
            this.lastFailError = res
          },
W
WOSHIMAHAIFENG 已提交
869
          complete: (_) => {
W
WOSHIMAHAIFENG 已提交
870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886
            this.done = true
          }
        } as ReadCompressedFileOptions)
      },
      readCompressedFileSyncTest() {
        console.log('readCompressedFileSyncTest')
        const fileManager = uni.getFileSystemManager()
        try {
          let data = fileManager.readCompressedFileSync(
            `${this.basePath}${this.brFile}`,
            "br")
          if (this.logAble) {
            this.log += data
          }
          this.done = true
        } catch (e) {
          if (this.logAble) {
W
WOSHIMAHAIFENG 已提交
887
            this.log += 'readCompressedFileSyncTest fail:' + e + '\n\n'
W
WOSHIMAHAIFENG 已提交
888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910
          }
          this.done = true
        }

      },
      removeSavedFileTest() {
        console.log("removeSavedFileTest enter")
        const fileManager = uni.getFileSystemManager()
        fileManager.removeSavedFile({
          filePath: `${this.basePath}${this.writeFile}`,
          success: (res : FileManagerSuccessResult) => {
            if (this.logAble) {
              this.log += 'removeSavedFileTest success:' + JSON.stringify(res) + '\n\n'
            }
            this.removeSavedFileRet = res.errMsg
            console.log("removeSavedFileTest success", res)
          },
          fail: (res : UniError) => {
            if (this.logAble) {
              this.log += 'removeSavedFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('removeSavedFileTest fail', res)
          },
W
WOSHIMAHAIFENG 已提交
911
          complete: (_) => {
W
WOSHIMAHAIFENG 已提交
912 913 914 915 916 917 918 919 920 921 922 923 924
            this.done = true
          }
        } as RemoveSavedFileOptions)
      },

      statFileInfoSyncTest: function (_ : any) {
        const fileManager = uni.getFileSystemManager()
        try {
          let res = fileManager.statSync(
            // path: `${this.basePath}${this.statFile}`, //USER_DATA_PATH
            `${this.globalTempPath}${this.statFile}`, //CACHE_PATH
            this.recursiveVal)
          if (this.logAble) {
W
WOSHIMAHAIFENG 已提交
925
            this.log += 'statFileInfoSyncTest success:' + JSON.stringify(res) + '\n\n'
W
WOSHIMAHAIFENG 已提交
926 927 928 929 930
          }
          this.statsRet = res
          this.done = true
        } catch (e) {
          if (this.logAble) {
W
WOSHIMAHAIFENG 已提交
931
            this.log += 'statFileInfoSyncTest fail:' + e + '\n\n'
W
WOSHIMAHAIFENG 已提交
932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955
          }
          this.done = true
        }

      },
      openFileTest() {
        const fileManager = uni.getFileSystemManager()
        fileManager.open({
          filePath: `${this.basePath}${this.readFile}`,
          flag: "a",
          success: (res : OpenFileSuccessResult) => {
            if (this.logAble) {
              this.log += 'openFileTest success:' + JSON.stringify(res) + '\n\n'
            }
            console.log("success", res)
            this.fd = res.fd
          },
          fail: (res : UniError) => {
            if (this.logAble) {
              this.log += 'openFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
            this.lastFailError = res
          },
W
WOSHIMAHAIFENG 已提交
956
          complete: (_) => {
W
WOSHIMAHAIFENG 已提交
957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049
            this.done = true
          }
        } as OpenFileOptions)
      },
      openFileSyncTest() : string {
        const fileManager = uni.getFileSystemManager()
        try {
          let fd = fileManager.openSync({
            filePath: `${this.basePath}${this.readFile}`,
            flag: "r",
          } as OpenFileSyncOptions)
          if (this.logAble) {
            this.log += 'openFileSyncTest success:' + fd + '\n\n'
          }
          this.done = true
          this.fd = fd
          return fd
        } catch (e) {
          if (this.logAble) {
            this.log += 'openFileSyncTest fail:' + JSON.stringify(e) + '\n\n'
          }
          console.log('fail', e)
          this.done = true
        }
        return ""
      },
      closeSyncTest() {
        console.log('closeSyncTest')
        const fileManager = uni.getFileSystemManager()
        fileManager.open({
          filePath: `${this.basePath}${this.readFile}`,
          flag: "r+",
          success: (res : OpenFileSuccessResult) => {
            console.log("success", res)
            if (res.fd.length <= 0) {
              this.done = true
              return
            }
            try {
              console.log('closeSync')
              fileManager.closeSync({
                fd: res.fd
              } as CloseSyncOptions)
              this.log += 'closeSyncTest success:' + '\n\n'
              this.done = true
              this.closeFileRet = "close:ok"
            } catch (e) {
              if (this.logAble) {
                this.log += 'closeSyncTest fail:' + JSON.stringify(e) + '\n\n'
              }
              console.log('fail', e)
              this.done = true
            }

          },
          fail: (res : UniError) => {
            if (this.logAble) {
              this.log += 'openFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
            this.lastFailError = res
            this.done = true
          }
        } as OpenFileOptions)

      },
      closeTest() {
        const fileManager = uni.getFileSystemManager()
        fileManager.open({
          filePath: `${this.basePath}${this.readFile}`,
          flag: "r+",
          success: (res : OpenFileSuccessResult) => {
            console.log("success", res)
            if (res.fd.length <= 0) {
              this.done = true
              return
            }
            fileManager.close({
              fd: res.fd,
              success: (res : FileManagerSuccessResult) => {
                if (this.logAble) {
                  this.log += 'closeTest success:' + JSON.stringify(res) + '\n\n'
                }
                this.closeFileRet = res.errMsg
                console.log("success", res)
              },
              fail: (res : UniError) => {
                if (this.logAble) {
                  this.log += 'closeTest fail:' + JSON.stringify(res) + '\n\n'
                }
                console.log('fail', res)
                this.lastFailError = res
              },
W
WOSHIMAHAIFENG 已提交
1050
              complete: (_) => {
W
WOSHIMAHAIFENG 已提交
1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094
                this.done = true
              }

            } as CloseOptions)
          },
          fail: (res : UniError) => {
            if (this.logAble) {
              this.log += 'openFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
            this.lastFailError = res
            this.done = true
          }
        } as OpenFileOptions)
      },
      writeTest() {
        const fileManager = uni.getFileSystemManager()
        fileManager.open({
          filePath: `${this.basePath}${this.readFile}`,
          flag: "r+",
          success: (res : OpenFileSuccessResult) => {
            console.log("success", res)
            if (res.fd.length <= 0) {
              this.done = true
              return
            }
            fileManager.write({
              fd: res.fd,
              data: this.writeData,
              encoding: "utf-8",
              success: (res : WriteResult) => {
                if (this.logAble) {
                  this.log += 'writeTest success:' + JSON.stringify(res) + '\n\n'
                }
                console.log("success", res)
                this.bytesWritten = res.bytesWritten
              },
              fail: (res : UniError) => {
                if (this.logAble) {
                  this.log += 'writeTest fail:' + JSON.stringify(res) + '\n\n'
                }
                console.log('fail', res)
                this.lastFailError = res
              },
W
WOSHIMAHAIFENG 已提交
1095
              complete: (_) => {
W
WOSHIMAHAIFENG 已提交
1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128
                this.done = true
              }

            } as WriteOptions)
          },
          fail: (res : UniError) => {
            if (this.logAble) {
              this.log += 'openFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
            this.lastFailError = res
            this.done = true
          }
        } as OpenFileOptions)
      },
      writeSyncTest() {
        const fileManager = uni.getFileSystemManager()
        fileManager.open({
          filePath: `${this.basePath}${this.readFile}`,
          flag: "r+",
          success: (res : OpenFileSuccessResult) => {
            console.log("success", res)
            if (res.fd.length <= 0) {
              this.done = true
              return
            }
            try {
              let ret = fileManager.writeSync({
                fd: res.fd,
                data: this.writeData,
                encoding: "utf-8"
              } as WriteSyncOptions)
              if (this.logAble) {
W
WOSHIMAHAIFENG 已提交
1129
                this.log += 'writeSyncTest success:' + JSON.stringify(ret) + '\n\n'
W
WOSHIMAHAIFENG 已提交
1130 1131 1132 1133 1134 1135
              }
              console.log("success", ret)
              this.done = true
              this.bytesWritten = ret.bytesWritten
            } catch (e) {
              if (this.logAble) {
W
WOSHIMAHAIFENG 已提交
1136
                this.log += 'writeSyncTest fail:' + JSON.stringify(e) + '\n\n'
W
WOSHIMAHAIFENG 已提交
1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170
              }
              console.log('fail', e)
              this.done = true
            }
          },
          fail: (res : UniError) => {
            if (this.logAble) {
              this.log += 'openFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
            this.lastFailError = res
            this.done = true
          }
        } as OpenFileOptions)

      },
      fstatTest() {
        const fileManager = uni.getFileSystemManager()
        fileManager.fstat({
          fd: this.openFileSyncTest(),
          success: (res : FStatSuccessResult) => {
            if (this.logAble) {
              this.log += 'fstatTest success:' + JSON.stringify(res) + '\n\n'
            }
            console.log("success", res)
            this.fstat = res.stats
          },
          fail: (res : UniError) => {
            if (this.logAble) {
              this.log += 'fstatTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
            this.lastFailError = res
          },
W
WOSHIMAHAIFENG 已提交
1171
          complete: (_) => {
W
WOSHIMAHAIFENG 已提交
1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204
            this.done = true
          }

        } as FStatOptions)
      },
      fstatSyncTest() {
        const fileManager = uni.getFileSystemManager()
        try {
          let stat =
            fileManager.fstatSync({
              fd: this.openFileSyncTest(),
            } as FStatSyncOptions)
          if (this.logAble) {
            this.log += 'fstatSyncTest success:' + JSON.stringify(stat) + '\n\n'
          }
          this.done = true
          this.fstat = stat
        } catch (e) {
          if (this.logAble) {
            this.log += 'fstatSyncTest fail:' + JSON.stringify(e) + '\n\n'
          }
          this.done = true
        }
      },
      ftruncateFileTest() {
        const fileManager = uni.getFileSystemManager()
        fileManager.ftruncate({
          fd: this.openFileSyncTest(),
          length: 6,
          success: (res : FileManagerSuccessResult) => {
            if (this.logAble) {
              this.log += 'ftruncateFileTest success:' + JSON.stringify(res) + '\n\n'
            }
W
WOSHIMAHAIFENG 已提交
1205
            this.ftruncateRet = res.errMsg
W
WOSHIMAHAIFENG 已提交
1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233
          },
          fail: (res : UniError) => {
            if (this.logAble) {
              this.log += 'ftruncateFileTest fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
            this.lastFailError = res
          },
          complete: (res : any) => {
            console.log("complete", res)
            this.done = true
            if (res instanceof UniError) {
              this.lastCompleteError = res
            }
          }
        } as FTruncateFileOptions)
      },
      ftruncateFileSyncTest() {
        const fileManager = uni.getFileSystemManager()
        try {
          fileManager.ftruncateSync({
            fd: this.openFileSyncTest(),
            length: 4
          } as FTruncateFileSyncOptions)
          if (this.logAble) {
            this.log += 'ftruncateFileSyncTest success:' + '\n\n'
          }
          this.done = true
W
WOSHIMAHAIFENG 已提交
1234
          this.ftruncateRet = ''
W
WOSHIMAHAIFENG 已提交
1235 1236 1237 1238 1239 1240
        } catch (e) {
          if (this.logAble) {
            this.log += 'ftruncateFileSyncTest fail:' + JSON.stringify(e) + '\n\n'
          }
          this.done = true
        }
W
WOSHIMAHAIFENG 已提交
1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273
      },
      readZipEntry() {
        const fileManager = uni.getFileSystemManager()
        fileManager.readZipEntry({
          filePath: `${this.basePath}${this.readZipFile}`,
          encoding: 'utf-8',
          entries: [{
            path: 'kkkk',
            encoding: 'utf-8'
          } as EntryItem,
          {
            path: 'log/log1.txt',
            encoding: 'utf-8'
          } as EntryItem,
          {
            path: 'hello.txt',
            encoding: 'utf-8'
          } as EntryItem],
          success: (res : EntriesResult) => {
            if (this.logAble) {
              this.log += 'readZipEntry success:' + JSON.stringify(res) + '\n\n'
            }
            console.log("success", res)
          },
          fail: (res : UniError) => {
            if (this.logAble) {
              this.log += 'readZipEntry fail:' + JSON.stringify(res) + '\n\n'
            }
            console.log('fail', res)
            this.lastFailError = res
          }
        } as ReadZipEntryOptions)
      },
W
WOSHIMAHAIFENG 已提交
1274 1275 1276

    },

1277
  }
1278 1279 1280
</script>

<style>
W
WOSHIMAHAIFENG 已提交
1281 1282 1283
 .btnstyle{
   margin: 4px;
 }
1284
</style>