提交 b88adc20 编写于 作者: WOSHIMAHAIFENG's avatar WOSHIMAHAIFENG

Merge branch 'alpha-filenew' into 'alpha'

Alpha filenew

See merge request !27
...@@ -10,6 +10,10 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -10,6 +10,10 @@ describe('ExtApi-FileManagerTest', () => {
return return
} }
let page; let page;
let mBasePath;
let mGlobalTempPath;
let mGlobalRootPath
function getData(key = '') { function getData(key = '') {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
...@@ -37,6 +41,9 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -37,6 +41,9 @@ describe('ExtApi-FileManagerTest', () => {
it('USER_DATA_PATH test', async () => { it('USER_DATA_PATH test', async () => {
// 测试 USER_DATA_PATH // 测试 USER_DATA_PATH
let globalUserDataPath = await getData('globalUserDataPath') let globalUserDataPath = await getData('globalUserDataPath')
mBasePath = await getData('basePath')
mGlobalRootPath = await getData('globalRootPath')
mGlobalTempPath = await getData('globalTempPath')
await page.setData({ await page.setData({
logAble: false, logAble: false,
...@@ -944,8 +951,10 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -944,8 +951,10 @@ describe('ExtApi-FileManagerTest', () => {
} }
let basePath = await getData('basePath')
await page.setData({ await page.setData({
basePath: mBasePath,
recursiveVal: true, recursiveVal: true,
logAble: false, logAble: false,
rmDirFile: 'appendfile', rmDirFile: 'appendfile',
...@@ -974,14 +983,14 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -974,14 +983,14 @@ describe('ExtApi-FileManagerTest', () => {
await btnMkdDirButton.tap() await btnMkdDirButton.tap()
await isDone() await isDone()
// // 先用utf-8 写入内容 // 先用utf-8 写入内容
const btnWriteFileButton = await page.$('#btn-write-file') const btnWriteFileButton = await page.$('#btn-write-file')
await btnWriteFileButton.tap() await btnWriteFileButton.tap()
await isDone() await isDone()
// //追加内容 //追加内容
const btnAppendFileButton = await page.$('#btn-append-file') const btnAppendFileButton = await page.$('#btn-append-file')
await btnAppendFileButton.tap() await btnAppendFileButton.tap()
await isDone() await isDone()
...@@ -1002,6 +1011,7 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -1002,6 +1011,7 @@ describe('ExtApi-FileManagerTest', () => {
await page.setData({ await page.setData({
basePath: mBasePath,
recursiveVal: false, recursiveVal: false,
logAble: false, logAble: false,
rmDirFile: 'sync', rmDirFile: 'sync',
...@@ -1019,18 +1029,7 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -1019,18 +1029,7 @@ describe('ExtApi-FileManagerTest', () => {
renameToFile: 'sync/sync.txt', renameToFile: 'sync/sync.txt',
renameFromFile: 'sync/sync.txt', renameFromFile: 'sync/sync.txt',
}) })
await clearDir('sync')
// 先清除文件,需要清除全部可能存在的历史测试文件,避免运行失败
const btnUnLinkFileButton = await page.$('#btn-unlink-file-sync')
await btnUnLinkFileButton.tap()
await isDone()
//清除文件夹
const btnRmDirButton = await page.$('#btn-remove-dir-sync')
await btnRmDirButton.tap()
await isDone()
// 重新创建测试目录,期望通过 recursive = true的 文件夹删除,得到一个空的 目录 // 重新创建测试目录,期望通过 recursive = true的 文件夹删除,得到一个空的 目录
const btnMkdDirButton = await page.$('#btn-mkdir-sync') const btnMkdDirButton = await page.$('#btn-mkdir-sync')
await btnMkdDirButton.tap() await btnMkdDirButton.tap()
...@@ -1098,6 +1097,8 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -1098,6 +1097,8 @@ describe('ExtApi-FileManagerTest', () => {
// 测试 copyfile // 测试 copyfile
await page.setData({ await page.setData({
basePath: mBasePath,
copyToBasePath: mBasePath,
copyFromFile: "sync/sync.txt", copyFromFile: "sync/sync.txt",
copyToFile: "sync/syncto.txt", copyToFile: "sync/syncto.txt",
accessFile: "sync/syncto.txt" accessFile: "sync/syncto.txt"
...@@ -1111,7 +1112,7 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -1111,7 +1112,7 @@ describe('ExtApi-FileManagerTest', () => {
accessFileRet = await getData("accessFileRet") accessFileRet = await getData("accessFileRet")
expect(accessFileRet).toEqual('access:ok') expect(accessFileRet).toEqual('access:ok')
clearDir('sync') await clearDir('sync')
}); });
async function createFile() { async function createFile() {
...@@ -1131,7 +1132,11 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -1131,7 +1132,11 @@ describe('ExtApi-FileManagerTest', () => {
await page.setData({ await page.setData({
rmDirFile: dir, rmDirFile: dir,
}) })
const btnClear = await page.$('#btn-clear-file') const btnUnLinkFileButton = await page.$('#btn-clear-file')
await btnUnLinkFileButton.tap()
await isDone()
const btnClear = await page.$('#btn-remove-dir')
await btnClear.tap() await btnClear.tap()
await isDone() await isDone()
} }
...@@ -1148,77 +1153,29 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -1148,77 +1153,29 @@ describe('ExtApi-FileManagerTest', () => {
return true return true
} }
it('saveFileSyncTest',
async () => {
if (!isAndroid()) {
return
}
console.log('saveFileSyncTest', 'start')
let globalTempPath = await getData('globalTempPath')
let basePath = await getData('basePath')
await page.setData({
logAble: false,
basePath: basePath
})
await clearDir('')
console.log('saveFileSyncTest', '1')
await page.setData({
logAble: false,
basePath: globalTempPath,
temFile: 'save/2.txt',
mkdirFile: 'save',
writeFile: 'save/2.txt',
accessFile: '2.txt'
})
await createFile()
console.log('saveFileSyncTest', '2')
await page.setData({
basePath: basePath,
writeFile: 'save/2.txt',
})
btnSaveFile = await page.$('#btn-save-file-sync')
await btnSaveFile.tap()
let btnRemoveSavedFileRet = await page.$('#btn-remove-saved-file')
await btnRemoveSavedFileRet.tap()
await isDone()
console.log('saveFileSyncTest', '3')
let removeSavedFileRet = await getData("removeSavedFileRet")
console.log('saveFileSyncTest', '4')
expect(removeSavedFileRet).toEqual('removeSavedFile:ok')
console.log('saveFileSyncTest', '5')
await page.setData({
removeSavedFileRet: ''
})
console.log('saveFileSyncTest', '6')
});
it('getSavedFileListTest', it('getSavedFileListTest',
async () => { async () => {
if (!isAndroid()) { if (!isAndroid()) {
return return
} }
// await page.setData({
// logAble: false,
let globalTempPath = await getData('globalTempPath') // basePath: mBasePath
let basePath = await getData('basePath') // })
await page.setData({
logAble: false,
basePath: basePath
})
// console.log('getSavedFileListTest', 'start') // console.log('getSavedFileListTest', 'start')
// await clearDir('') // await clearDir('')
// console.log('getSavedFileListTest', 'end') // console.log('getSavedFileListTest', 'end')
await page.setData({ await page.setData({
logAble: false, logAble: false,
basePath: globalTempPath, basePath: mGlobalTempPath,
temFile: 'save/2.txt', temFile: 'save3/2.txt',
mkdirFile: 'save', mkdirFile: 'save3',
writeFile: 'save/2.txt', writeFile: 'save3/2.txt',
accessFile: '2.txt' accessFile: '2.txt'
}) })
await createFile() await createFile()
await page.setData({ await page.setData({
basePath: basePath, basePath: mBasePath,
writeFile: 'save/2.txt', writeFile: 'save/2.txt',
}) })
btnSaveFile = await page.$('#btn-save-file-sync') btnSaveFile = await page.$('#btn-save-file-sync')
...@@ -1236,37 +1193,26 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -1236,37 +1193,26 @@ describe('ExtApi-FileManagerTest', () => {
if (!isAndroid()) { if (!isAndroid()) {
return return
} }
let globalTempPath = await getData('globalTempPath')
let basePath = await getData('basePath')
await page.setData({ await page.setData({
logAble: false, logAble: false,
basePath: basePath basePath: mBasePath
}) })
// await clearDir('') await clearDir('save4')
await page.setData({ await page.setData({
logAble: false, logAble: false,
basePath: globalTempPath, basePath: mGlobalTempPath,
temFile: 'save/2.txt', temFile: 'save4/saveSync.txt',
mkdirFile: 'save', mkdirFile: 'save4',
writeFile: 'save/2.txt', writeFile: 'save4/saveSync.txt',
accessFile: '2.txt' accessFile: 'saveSync.txt'
}) })
await createFile() await createFile()
await page.setData({
basePath: basePath,
writeFile: 'save/2.txt',
})
btnSaveFile = await page.$('#btn-save-file-sync')
await btnSaveFile.tap()
await isDone()
let btnRemoveSavedFileRet = await page.$('#btn-remove-saved-file') let btnRemoveSavedFileRet = await page.$('#btn-remove-saved-file')
await btnRemoveSavedFileRet.tap() await btnRemoveSavedFileRet.tap()
await isDone() await isDone()
let removeSavedFileRet = await getData("removeSavedFileRet") let removeSavedFileRet = await getData("removeSavedFileRet")
expect(removeSavedFileRet).toEqual('removeSavedFile:ok') expect(removeSavedFileRet).toEqual('removeSavedFile:ok')
}); });
//openFiletest openFileSynctest closeTest closeTestSync writeTest writeSyncTest //openFiletest openFileSynctest closeTest closeTestSync writeTest writeSyncTest
...@@ -1275,15 +1221,16 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -1275,15 +1221,16 @@ describe('ExtApi-FileManagerTest', () => {
return return
} }
// await clearDir('')
await page.setData({ await page.setData({
basePath: mBasePath,
logAble: false, logAble: false,
mkdirFile: 'fd', mkdirFile: 'fd',
writeFile: 'fd/1.txt', writeFile: 'fd/1.txt',
readFile: 'fd/1.txt' readFile: 'fd/1.txt'
}) })
await clearDir('fd')
await createFile() await createFile()
console.log('openFiletest', '2')
//openFiletest //openFiletest
let btnOpenFile = await page.$('#btn-open-file') let btnOpenFile = await page.$('#btn-open-file')
await btnOpenFile.tap() await btnOpenFile.tap()
...@@ -1293,13 +1240,14 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -1293,13 +1240,14 @@ describe('ExtApi-FileManagerTest', () => {
await page.setData({ await page.setData({
fd: '', fd: '',
}) })
console.log('openFiletest', '3')
//openFileSynctest //openFileSynctest
btnOpenFile = await page.$('#btn-open-file-sync') btnOpenFile = await page.$('#btn-open-file-sync')
await btnOpenFile.tap() await btnOpenFile.tap()
await isDone() await isDone()
fd = await getData("fd") fd = await getData("fd")
expect(fd).not.toBe(''); expect(fd).not.toBe('');
console.log('openFiletest', '4')
}); });
// closeTest closeTestSync // closeTest closeTestSync
it('closeTest', async () => { it('closeTest', async () => {
...@@ -1308,13 +1256,15 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -1308,13 +1256,15 @@ describe('ExtApi-FileManagerTest', () => {
} }
// await clearDir('')
await page.setData({ await page.setData({
basePath: mBasePath,
logAble: false, logAble: false,
mkdirFile: 'fd', mkdirFile: 'fd',
writeFile: 'fd/1.txt', writeFile: 'fd/1.txt',
readFile: 'fd/1.txt' readFile: 'fd/1.txt'
}) })
await clearDir('fd')
await createFile() await createFile()
//closeTest //closeTest
let btnCloseFile = await page.$('#btn-close-file') let btnCloseFile = await page.$('#btn-close-file')
...@@ -1339,14 +1289,16 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -1339,14 +1289,16 @@ describe('ExtApi-FileManagerTest', () => {
return return
} }
console.log('writeTest', 'start') console.log('writeTest', 'start')
// await clearDir('')
await page.setData({ await page.setData({
basePath: mBasePath,
logAble: false, logAble: false,
mkdirFile: 'fd', mkdirFile: 'fd',
writeFile: 'fd/1.txt', writeFile: 'fd/1.txt',
readFile: 'fd/1.txt', readFile: 'fd/1.txt',
writeData: '我是一只小小鸟' writeData: '我是一只小小鸟'
}) })
await clearDir('fd')
await createFile() await createFile()
console.log('writeTest', '1') console.log('writeTest', '1')
let btnWrite = await page.$('#btn-write') let btnWrite = await page.$('#btn-write')
...@@ -1409,14 +1361,16 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -1409,14 +1361,16 @@ describe('ExtApi-FileManagerTest', () => {
return return
} }
console.log('ftruncateFileTest', 'start') console.log('ftruncateFileTest', 'start')
// await clearDir('')
await page.setData({ await page.setData({
basePath: mBasePath,
logAble: false, logAble: false,
mkdirFile: 'fd', mkdirFile: 'fd',
writeFile: 'fd/1.txt', writeFile: 'fd/1.txt',
readFile: 'fd/1.txt', readFile: 'fd/1.txt',
writeData: '我是一只小小鸟我是' writeData: '我是一只小小鸟我是'
}) })
await clearDir('fd')
await createFile() await createFile()
console.log('ftruncateFileTest', '1') console.log('ftruncateFileTest', '1')
btnWrite = await page.$('#btn-write-sync') btnWrite = await page.$('#btn-write-sync')
...@@ -1444,45 +1398,4 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -1444,45 +1398,4 @@ describe('ExtApi-FileManagerTest', () => {
expect(ftruncateRet).toEqual('ftruncate:ok') expect(ftruncateRet).toEqual('ftruncate:ok')
console.log('ftruncateFileTest', '7') console.log('ftruncateFileTest', '7')
}); });
//saveFileTest saveFileSyncTest getSavedFileListTest removeSavedFileTest
it('savefile test',
async () => {
if (!isAndroid()) {
return
}
let globalTempPath = await getData('globalTempPath')
let basePath = await getData('basePath')
await page.setData({
logAble: false,
basePath: basePath
})
// await clearDir('')
await page.setData({
basePath: globalTempPath,
temFile: 'save/1.txt',
mkdirFile: 'save',
writeFile: 'save/1.txt',
accessFile: '1.txt'
})
await createFile()
await page.setData({
basePath: basePath,
temFile: 'save/1.txt',
})
let btnSaveFile = await page.$('#btn-save-file')
await btnSaveFile.tap()
await isDone()
let saveFileRet = await getData("saveFileRet")
expect(saveFileRet).not.toBe('');
await page.setData({
saveFileRet: ''
})
// await clearDir('')
});
}); });
...@@ -60,7 +60,7 @@ ...@@ -60,7 +60,7 @@
<button class="btnstyle" type="primary" @tap="readCompressedFileSyncTest" <button class="btnstyle" type="primary" @tap="readCompressedFileSyncTest"
id="btn-compressed-file-sync">同步读取指定压缩类型的本地文件内容</button> 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="openFileTest" id="btn-open-file">打开文件{{readFile}},返回描述符</button>
<button class="btnstyle" type="primary" @tap="openFileSyncTest" <button class="btnstyle" type="primary" @tap="openFileSyncTest('r')"
id="btn-open-file-sync">同步打开文件{{readFile}},返回描述符</button> 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="closeTest" id="btn-close-file">通过文件描述符关闭文件{{readFile}}</button>
<button class="btnstyle" type="primary" @tap="closeSyncTest" <button class="btnstyle" type="primary" @tap="closeSyncTest"
...@@ -483,8 +483,14 @@ ...@@ -483,8 +483,14 @@
console.log("success to readdir", res) console.log("success to readdir", res)
res.files.forEach(element => { res.files.forEach(element => {
console.log(element) console.log(element)
let filePath : string
if (this.rmDirFile.length <= 0) {
filePath = `${this.basePath}${element}`
} else {
filePath = `${this.basePath}${this.rmDirFile}/${element}`
}
fileManager.unlink({ fileManager.unlink({
filePath: `${this.basePath}${this.rmDirFile}/${element}`, filePath: filePath,
success: (res : FileManagerSuccessResult) => { success: (res : FileManagerSuccessResult) => {
if (this.logAble) { if (this.logAble) {
this.log += 'unlinkAllFileTest success:' + JSON.stringify(res) + '\n\n' this.log += 'unlinkAllFileTest success:' + JSON.stringify(res) + '\n\n'
...@@ -768,7 +774,7 @@ ...@@ -768,7 +774,7 @@
const fileManager = uni.getFileSystemManager() const fileManager = uni.getFileSystemManager()
try { try {
fileManager.saveFileSync( fileManager.saveFileSync(
`${this.globalTempPath}${this.temFile}`, `${this.basePath}local/`) `${this.globalTempPath}${this.temFile}`, `${this.basePath}/`)
// filePath:`${this.basePath}local/`,) // filePath:`${this.basePath}local/`,)
this.done = true this.done = true
...@@ -780,20 +786,23 @@ ...@@ -780,20 +786,23 @@
} }
}, },
unzipFileTest: function (_ : any) { unzipFileTest: function (_ : any) {
uni.downloadFile({
url: 'https://b2c-store.oss-ap-southeast-1.aliyuncs.com/ceshi/FRT.zip',
success: (res) => {
console.log(res)
const fileManager = uni.getFileSystemManager() const fileManager = uni.getFileSystemManager()
fileManager.unzip({ fileManager.unzip({
zipFilePath: `${this.basePath}${this.unzipFile}`, zipFilePath: res.tempFilePath,
targetPath: `${this.basePath}${this.targetZip}`, targetPath: `${this.basePath}${this.targetZip}`,
success: (res : FileManagerSuccessResult) => { success: (res : FileManagerSuccessResult) => {
if (this.logAble) { if (this.logAble) {
this.log += 'saveFileTest success:' + JSON.stringify(res) + '\n\n' this.log += 'unzipFileTest success:' + JSON.stringify(res) + '\n\n'
} }
console.log('success', res) console.log('success', res)
}, },
fail: (res : UniError) => { fail: (res : UniError) => {
if (this.logAble) { if (this.logAble) {
this.log += 'saveFileTest fail:' + JSON.stringify(res) + '\n\n' this.log += 'unzipFileTest fail:' + JSON.stringify(res) + '\n\n'
} }
console.log('fail', res) console.log('fail', res)
this.lastFailError = res this.lastFailError = res
...@@ -803,6 +812,11 @@ ...@@ -803,6 +812,11 @@
} }
} as UnzipFileOptions) } as UnzipFileOptions)
}, },
fail: (e) => {
console.log(e)
}
})
},
getSavedFileListTest: function () { getSavedFileListTest: function () {
const fileManager = uni.getFileSystemManager() const fileManager = uni.getFileSystemManager()
...@@ -875,7 +889,7 @@ ...@@ -875,7 +889,7 @@
readCompressedFileTest() { readCompressedFileTest() {
const fileManager = uni.getFileSystemManager() const fileManager = uni.getFileSystemManager()
fileManager.readCompressedFile({ fileManager.readCompressedFile({
filePath: `${this.basePath}${this.brFile}`, filePath: '/static/filemanager/1.txt.br',
compressionAlgorithm: "br", compressionAlgorithm: "br",
success: (res : ReadCompressedFileResult) => { success: (res : ReadCompressedFileResult) => {
if (this.logAble) { if (this.logAble) {
...@@ -900,7 +914,7 @@ ...@@ -900,7 +914,7 @@
const fileManager = uni.getFileSystemManager() const fileManager = uni.getFileSystemManager()
try { try {
let data = fileManager.readCompressedFileSync( let data = fileManager.readCompressedFileSync(
`${this.basePath}${this.brFile}`, '/static/filemanager/1.txt.br',
"br") "br")
if (this.logAble) { if (this.logAble) {
this.log += data this.log += data
...@@ -982,12 +996,12 @@ ...@@ -982,12 +996,12 @@
} }
} as OpenFileOptions) } as OpenFileOptions)
}, },
openFileSyncTest() : string { openFileSyncTest(param : string) : string {
const fileManager = uni.getFileSystemManager() const fileManager = uni.getFileSystemManager()
try { try {
let fd = fileManager.openSync({ let fd = fileManager.openSync({
filePath: `${this.basePath}${this.readFile}`, filePath: `${this.basePath}${this.readFile}`,
flag: "r", flag: param,
} as OpenFileSyncOptions) } as OpenFileSyncOptions)
if (this.logAble) { if (this.logAble) {
this.log += 'openFileSyncTest success:' + fd + '\n\n' this.log += 'openFileSyncTest success:' + fd + '\n\n'
...@@ -1010,7 +1024,7 @@ ...@@ -1010,7 +1024,7 @@
try { try {
console.log('closeSync') console.log('closeSync')
fileManager.closeSync({ fileManager.closeSync({
fd: this.openFileSyncTest() fd: this.openFileSyncTest('r')
} as CloseSyncOptions) } as CloseSyncOptions)
if (this.logAble) { if (this.logAble) {
this.log += 'closeSyncTest success:' + '\n\n' this.log += 'closeSyncTest success:' + '\n\n'
...@@ -1028,7 +1042,7 @@ ...@@ -1028,7 +1042,7 @@
closeTest() { closeTest() {
const fileManager = uni.getFileSystemManager() const fileManager = uni.getFileSystemManager()
fileManager.close({ fileManager.close({
fd: this.openFileSyncTest(), fd: this.openFileSyncTest('r'),
success: (res : FileManagerSuccessResult) => { success: (res : FileManagerSuccessResult) => {
if (this.logAble) { if (this.logAble) {
this.log += 'closeTest success:' + JSON.stringify(res) + '\n\n' this.log += 'closeTest success:' + JSON.stringify(res) + '\n\n'
...@@ -1051,17 +1065,14 @@ ...@@ -1051,17 +1065,14 @@
}, },
writeTest() { writeTest() {
const fileManager = uni.getFileSystemManager() const fileManager = uni.getFileSystemManager()
fileManager.open({ try {
filePath: `${this.basePath}${this.readFile}`, fileManager.mkdirSync(`${this.basePath}${this.mkdirFile}`, true)
flag: "r+", } catch (e) {
success: (res : OpenFileSuccessResult) => { console.error(e)
console.log("success", res)
if (res.fd.length <= 0) {
this.done = true
return
} }
fileManager.write({ fileManager.write({
fd: res.fd, fd: this.openFileSyncTest('w+'),
data: this.writeData, data: this.writeData,
encoding: "utf-8", encoding: "utf-8",
success: (res : WriteResult) => { success: (res : WriteResult) => {
...@@ -1084,18 +1095,13 @@ ...@@ -1084,18 +1095,13 @@
} as WriteOptions) } 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() { writeSyncTest() {
const fileManager = uni.getFileSystemManager() const fileManager = uni.getFileSystemManager()
try {
fileManager.mkdirSync(`${this.basePath}${this.mkdirFile}`, true)
} catch (e) {
console.error(e)
}
fileManager.open({ fileManager.open({
filePath: `${this.basePath}${this.readFile}`, filePath: `${this.basePath}${this.readFile}`,
flag: "r+", flag: "r+",
...@@ -1139,7 +1145,7 @@ ...@@ -1139,7 +1145,7 @@
fstatTest() { fstatTest() {
const fileManager = uni.getFileSystemManager() const fileManager = uni.getFileSystemManager()
fileManager.fstat({ fileManager.fstat({
fd: this.openFileSyncTest(), fd: this.openFileSyncTest('r'),
success: (res : FStatSuccessResult) => { success: (res : FStatSuccessResult) => {
if (this.logAble) { if (this.logAble) {
this.log += 'fstatTest success:' + JSON.stringify(res) + '\n\n' this.log += 'fstatTest success:' + JSON.stringify(res) + '\n\n'
...@@ -1165,7 +1171,7 @@ ...@@ -1165,7 +1171,7 @@
try { try {
let stat = let stat =
fileManager.fstatSync({ fileManager.fstatSync({
fd: this.openFileSyncTest(), fd: this.openFileSyncTest('r'),
} as FStatSyncOptions) } as FStatSyncOptions)
if (this.logAble) { if (this.logAble) {
this.log += 'fstatSyncTest success:' + JSON.stringify(stat) + '\n\n' this.log += 'fstatSyncTest success:' + JSON.stringify(stat) + '\n\n'
...@@ -1182,7 +1188,7 @@ ...@@ -1182,7 +1188,7 @@
ftruncateFileTest() { ftruncateFileTest() {
const fileManager = uni.getFileSystemManager() const fileManager = uni.getFileSystemManager()
fileManager.ftruncate({ fileManager.ftruncate({
fd: this.openFileSyncTest(), fd: this.openFileSyncTest('r+'),
length: 6, length: 6,
success: (res : FileManagerSuccessResult) => { success: (res : FileManagerSuccessResult) => {
if (this.logAble) { if (this.logAble) {
...@@ -1210,7 +1216,7 @@ ...@@ -1210,7 +1216,7 @@
const fileManager = uni.getFileSystemManager() const fileManager = uni.getFileSystemManager()
try { try {
fileManager.ftruncateSync({ fileManager.ftruncateSync({
fd: this.openFileSyncTest(), fd: this.openFileSyncTest('r+'),
length: 4 length: 4
} as FTruncateFileSyncOptions) } as FTruncateFileSyncOptions)
if (this.logAble) { if (this.logAble) {
...@@ -1226,25 +1232,17 @@ ...@@ -1226,25 +1232,17 @@
} }
}, },
readZipEntry() { readZipEntry() {
uni.downloadFile({
url: 'https://b2c-store.oss-ap-southeast-1.aliyuncs.com/ceshi/FRT.zip',
success: (res) => {
console.log(res)
const fileManager = uni.getFileSystemManager() const fileManager = uni.getFileSystemManager()
fileManager.readZipEntry({ fileManager.readZipEntry({
filePath: `${this.basePath}${this.readZipFile}`, filePath: res.tempFilePath,
encoding: 'utf-8', 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) => { success: (res : EntriesResult) => {
if (this.logAble) { if (this.logAble) {
this.log += 'readZipEntry success:' + JSON.stringify(res) + '\n\n' this.log += 'readZipEntry success:size=' + res.result.size + '\n\n'
} }
console.log("success", res) console.log("success", res)
}, },
...@@ -1257,6 +1255,11 @@ ...@@ -1257,6 +1255,11 @@
} }
} as ReadZipEntryOptions) } as ReadZipEntryOptions)
}, },
fail: (e) => {
console.log(e)
}
})
},
}, },
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册