Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
fe7c408e
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
5995
Star
90
Fork
162
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
18
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
18
Issue
18
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
fe7c408e
编写于
8月 29, 2024
作者:
M
mahaifeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[fillemanager] 添加arraybuffer测试用例与示例
上级
72d747b8
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
3144 addition
and
2679 deletion
+3144
-2679
pages/API/get-file-system-manager/get-file-system-manager.test.js
...I/get-file-system-manager/get-file-system-manager.test.js
+1481
-1403
pages/API/get-file-system-manager/get-file-system-manager.uvue
.../API/get-file-system-manager/get-file-system-manager.uvue
+1659
-1274
pages/API/provider/provider.uvue
pages/API/provider/provider.uvue
+4
-2
未找到文件。
pages/API/get-file-system-manager/get-file-system-manager.test.js
浏览文件 @
fe7c408e
...
...
@@ -3,7 +3,8 @@ const PAGE_PATH = '/pages/API/get-file-system-manager/get-file-system-manager'
describe
(
'
ExtApi-FileManagerTest
'
,
()
=>
{
if
(
process
.
env
.
uniTestPlatformInfo
.
indexOf
(
'
web
'
)
>
-
1
||
process
.
env
.
UNI_AUTOMATOR_APP_WEBVIEW
==
'
true
'
)
{
if
(
process
.
env
.
uniTestPlatformInfo
.
indexOf
(
'
web
'
)
>
-
1
||
process
.
env
.
UNI_AUTOMATOR_APP_WEBVIEW
==
'
true
'
)
{
it
(
'
dummyTest
'
,
()
=>
{
expect
(
1
).
toBe
(
1
)
})
...
...
@@ -427,10 +428,12 @@ describe('ExtApi-FileManagerTest', () => {
fileListComplete
=
await
getData
(
'
fileListComplete
'
)
fileListComplete
.
sort
()
expect
(
JSON
.
stringify
(
fileListComplete
)).
toEqual
(
"
[
\"
b
\"
,
\"
"
+
testDirName
+
"
\"
,
\"
提前创建的目录
\"
]
"
)
expect
(
JSON
.
stringify
(
fileListComplete
)).
toEqual
(
"
[
\"
b
\"
,
\"
"
+
testDirName
+
"
\"
,
\"
提前创建的目录
\"
]
"
)
fileListSuccess
=
await
getData
(
'
fileListSuccess
'
)
fileListSuccess
.
sort
()
expect
(
JSON
.
stringify
(
fileListSuccess
)).
toEqual
(
"
[
\"
b
\"
,
\"
"
+
testDirName
+
"
\"
,
\"
提前创建的目录
\"
]
"
)
expect
(
JSON
.
stringify
(
fileListSuccess
)).
toEqual
(
"
[
\"
b
\"
,
\"
"
+
testDirName
+
"
\"
,
\"
提前创建的目录
\"
]
"
)
await
page
.
setData
({
...
...
@@ -1142,7 +1145,8 @@ describe('ExtApi-FileManagerTest', () => {
}
function
isAndroid
()
{
if
(
process
.
env
.
uniTestPlatformInfo
.
indexOf
(
'
web
'
)
>
-
1
||
process
.
env
.
UNI_AUTOMATOR_APP_WEBVIEW
===
'
true
'
)
{
if
(
process
.
env
.
uniTestPlatformInfo
.
indexOf
(
'
web
'
)
>
-
1
||
process
.
env
.
UNI_AUTOMATOR_APP_WEBVIEW
===
'
true
'
)
{
expect
(
1
).
toBe
(
1
)
return
false
}
...
...
@@ -1307,9 +1311,10 @@ describe('ExtApi-FileManagerTest', () => {
await
isDone
()
let
bytesWritten
=
await
getData
(
"
bytesWritten
"
)
let
lastFailError
=
await
getData
(
"
lastFailError
"
)
if
(
bytesWritten
!=
7
)
{
if
(
bytesWritten
!=
7
)
{
let
writeData
=
await
getData
(
"
writeData
"
)
console
.
log
(
'
writeTest
'
,
lastFailError
.
errCode
,
lastFailError
.
errMsg
,
bytesWritten
,
writeData
)
console
.
log
(
'
writeTest
'
,
lastFailError
.
errCode
,
lastFailError
.
errMsg
,
bytesWritten
,
writeData
)
}
expect
(
bytesWritten
).
toEqual
(
7
)
...
...
@@ -1405,4 +1410,77 @@ describe('ExtApi-FileManagerTest', () => {
expect
(
ftruncateRet
).
toEqual
(
'
ftruncate:ok
'
)
console
.
log
(
'
ftruncateFileTest
'
,
'
7
'
)
});
//testAppendFileBuffer
it
(
'
testAppendFileBuffer
'
,
async
()
=>
{
if
(
!
isAndroid
())
{
return
}
var
btnWrite
=
await
page
.
$
(
'
#btn-appendfile-buffer
'
)
await
btnWrite
.
tap
()
await
isDone
()
let
arrayBufferRes
=
await
getData
(
"
arrayBufferRes
"
)
expect
(
bytesWritten
).
toEqual
(
21
)
});
it
(
'
testAppendFileBufferSync
'
,
async
()
=>
{
if
(
!
isAndroid
())
{
return
}
var
btnWrite
=
await
page
.
$
(
'
#btn-appendfilesync-buffer
'
)
await
btnWrite
.
tap
()
await
isDone
()
let
arrayBufferRes
=
await
getData
(
"
arrayBufferRes
"
)
expect
(
bytesWritten
).
toEqual
(
20
)
});
it
(
'
testWriteReadSyncBuffer
'
,
async
()
=>
{
if
(
!
isAndroid
())
{
return
}
var
btnWrite
=
await
page
.
$
(
'
#btn-writereadsync-buffer
'
)
await
btnWrite
.
tap
()
await
isDone
()
let
arrayBufferRes
=
await
getData
(
"
arrayBufferRes
"
)
expect
(
bytesWritten
).
toEqual
(
1.11
)
});
it
(
'
testWriteReadBuffer
'
,
async
()
=>
{
if
(
!
isAndroid
())
{
return
}
var
btnWrite
=
await
page
.
$
(
'
#btn-writeread-buffer
'
)
await
btnWrite
.
tap
()
await
isDone
()
let
arrayBufferRes
=
await
getData
(
"
arrayBufferRes
"
)
expect
(
bytesWritten
).
toEqual
(
1.24
)
});
it
(
'
testWriteReadFileSyncBuffer
'
,
async
()
=>
{
if
(
!
isAndroid
())
{
return
}
var
btnWrite
=
await
page
.
$
(
'
#btn-writereadfilesync-buffer
'
)
await
btnWrite
.
tap
()
await
isDone
()
let
arrayBufferRes
=
await
getData
(
"
arrayBufferRes
"
)
expect
(
bytesWritten
).
toEqual
(
1.333
)
});
it
(
'
testReadFileBuffer
'
,
async
()
=>
{
if
(
!
isAndroid
())
{
return
}
var
btnWrite
=
await
page
.
$
(
'
#btn-writereadfile-buffer
'
)
await
btnWrite
.
tap
()
await
isDone
()
let
arrayBufferRes
=
await
getData
(
"
arrayBufferRes
"
)
expect
(
bytesWritten
).
toEqual
(
1.2222222
)
});
});
\ No newline at end of file
pages/API/get-file-system-manager/get-file-system-manager.uvue
浏览文件 @
fe7c408e
...
...
@@ -14,7 +14,8 @@
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="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>
...
...
@@ -28,17 +29,21 @@
<!-- #ifdef APP-ANDROID -->
<button class="btnstyle" type="primary" @tap="statFileInfoSyncTest"
id="btn-stat-file-sync">同步递归获取目录files的Stats对象{{statFile}}</button>
<button class="btnstyle" type="primary" @tap="appendFileTest" id="btn-append-file">在文件{{readFile}}结尾追加内容</button>
<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="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="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"
...
...
@@ -47,7 +52,8 @@
id="btn-copy-file-sync">同步复制文件{{copyFromFile}}到{{copyToFile}}</button>
<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="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>
...
...
@@ -60,13 +66,14 @@
<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('r'
)"
<button class="btnstyle" type="primary" @tap="openFileSyncTest('r',true
)"
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-write-sync">同步通过文件描述符写入文件{{readFile}}</button>
<button class="btnstyle" type="primary" @tap="writeSyncTest"
id="btn-write-sync">同步通过文件描述符写入文件{{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>
...
...
@@ -75,6 +82,21 @@
<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>
<button class="btnstyle" type="primary" @tap="testWriteReadFileBuffer" id="btn-writereadfile-buffer">写入/读取
ArrayBuffer</button>
<button class="btnstyle" type="primary" @tap="testWriteReadFileSyncBuffer"
id="btn-writereadfilesync-buffer">同步写入/读取
ArrayBuffer</button>
<button class="btnstyle" type="primary" @tap="testWriteReadBuffer" id="btn-writeread-buffer">通过文件描述符写入/读取
ArrayBuffer</button>
<button class="btnstyle" type="primary" @tap="testWriteReadSyncBuffer"
id="btn-writereadsync-buffer">通过文件描述符同步写入/读取
ArrayBuffer</button>
<button class="btnstyle" type="primary" @tap="testAppendFileBuffer" id="btn-appendfile-buffer">在文件末尾追加
ArrayBuffer</button>
<button class="btnstyle" type="primary" @tap="testAppendFileBufferSync" id="btn-appendfilesync-buffer">同步在文件末尾追加
ArrayBuffer</button>
<view style="height: 4px;"></view>
<!-- #endif -->
<!-- #ifdef APP -->
...
...
@@ -136,6 +158,7 @@
ftruncateRet: '',
readZipFile: 'to.zip',
getSavedFileListRet: '',
arrayBufferRes: 0,
/**
* 待测试的全局环境变量
*/
...
...
@@ -342,7 +365,7 @@
this.log += 'readFileTest success:' + JSON.stringify(res) + '\n\n'
}
console.log('success', res)
this.readFileRet = res.data
this.readFileRet = res.data.toString()
},
fail: (res : IUniError) => {
if (this.logAble) {
...
...
@@ -623,7 +646,7 @@
this.log += 'readFileSyncTest result:' + data + '\n\n'
}
this.done = true
this.readFileRet = data
this.readFileRet = data.toString()
} catch (e) {
if (this.logAble) {
this.log += 'readFileSyncTest fail:' + e + '\n\n'
...
...
@@ -1006,17 +1029,20 @@
}
} as OpenFileOptions)
},
openFileSyncTest(param : string
) : string {
openFileSyncTest(param : string, isTest : boolean
) : string {
const fileManager = uni.getFileSystemManager()
try {
let fd = fileManager.openSync({
filePath: `${this.basePath}${this.readFile}`,
flag: param,
} as OpenFileSyncOptions)
if (this.logAble
) {
if (this.logAble && isTest
) {
this.log += 'openFileSyncTest success:' + fd + '\n\n'
}
if (isTest) {
this.done = true
}
this.fd = fd
return fd
} catch (e) {
...
...
@@ -1034,7 +1060,7 @@
try {
console.log('closeSync')
fileManager.closeSync({
fd: this.openFileSyncTest('r'
)
fd: this.openFileSyncTest('r', false
)
} as CloseSyncOptions)
if (this.logAble) {
this.log += 'closeSyncTest success:' + '\n\n'
...
...
@@ -1052,7 +1078,7 @@
closeTest() {
const fileManager = uni.getFileSystemManager()
fileManager.close({
fd: this.openFileSyncTest('r'
),
fd: this.openFileSyncTest('r', false
),
success: (res : FileManagerSuccessResult) => {
if (this.logAble) {
this.log += 'closeTest success:' + JSON.stringify(res) + '\n\n'
...
...
@@ -1083,7 +1109,7 @@
}
fileManager.write({
fd: this.openFileSyncTest('w+'
),
fd: this.openFileSyncTest('w+', false
),
data: this.writeData,
encoding: "utf-8",
success: (res : WriteResult) => {
...
...
@@ -1159,7 +1185,7 @@
fstatTest() {
const fileManager = uni.getFileSystemManager()
fileManager.fstat({
fd: this.openFileSyncTest('r'
),
fd: this.openFileSyncTest('r', false
),
success: (res : FStatSuccessResult) => {
if (this.logAble) {
this.log += 'fstatTest success:' + JSON.stringify(res) + '\n\n'
...
...
@@ -1186,7 +1212,7 @@
try {
let stat =
fileManager.fstatSync({
fd: this.openFileSyncTest('r'
),
fd: this.openFileSyncTest('r', false
),
} as FStatSyncOptions)
if (this.logAble) {
this.log += 'fstatSyncTest success:' + JSON.stringify(stat) + '\n\n'
...
...
@@ -1203,7 +1229,7 @@
ftruncateFileTest() {
const fileManager = uni.getFileSystemManager()
fileManager.ftruncate({
fd: this.openFileSyncTest('r+'
),
fd: this.openFileSyncTest('r+', false
),
length: 6,
success: (res : FileManagerSuccessResult) => {
if (this.logAble) {
...
...
@@ -1232,7 +1258,7 @@
const fileManager = uni.getFileSystemManager()
try {
fileManager.ftruncateSync({
fd: this.openFileSyncTest('r+'
),
fd: this.openFileSyncTest('r+', false
),
length: 4
} as FTruncateFileSyncOptions)
if (this.logAble) {
...
...
@@ -1268,6 +1294,365 @@
}
} as ReadZipEntryOptions)
},
testWriteReadFileBuffer() {
const fs = uni.getFileSystemManager()
let buffer = new ArrayBuffer(16)
let float64 = new Float64Array(buffer)
float64[1] = 1.2222222
let that = this
fs.writeFile({
filePath: `${uni.env.USER_DATA_PATH}/hello.txt`,
// data: 'test some',
data: buffer,
// encoding: 'ascii',
success(res) {
if (this.logAble) {
this.log += 'testWriteReadFileBuffer :' + res.errMsg + '\n\n'
}
console.log(res)
// that.testAppendFile()
that.testReadFileBuffer()
},
fail(res) {
if (this.logAble) {
this.log += 'testWriteReadFileBuffer fail:' + JSON.stringify(res) + '\n\n'
}
this.lastFailError = new UniError(res.errSubject, res.errCode, res.errMsg)
console.error(res)
this.done = true
},
complete: (res : any) => {
}
} as WriteFileOptions)
},
testReadFileBuffer() {
const fs = uni.getFileSystemManager()
fs.readFile({
filePath: `${uni.env.USER_DATA_PATH}/hello.txt`,
success(res) {
console.log(res)
// let uint8Array = new Uint8Array(res.data as ArrayBuffer)
// for (let i = 0; i < uint8Array.length; i++) {
// console.log(`Byte ${i}: ${uint8Array[i]}`);
// }
let float64 = new Float64Array(res.data as ArrayBuffer)
if (this.logAble) {
for (let i = 0; i < float64.length; i++) {
if (this.logAble) {
this.log += 'testReadFileBuffer success :' + `Byte ${i}: ${float64[i]}` + '\n\n'
}
}
}
this.arrayBufferRes = float64[1] //1.2222222
console.log(this.arrayBufferRes)
},
fail(res) {
if (this.logAble) {
this.log += 'testReadFileBuffer fail:' + JSON.stringify(res) + '\n\n'
}
this.lastFailError = new UniError(res.errSubject, res.errCode, res.errMsg)
console.error(res)
},
complete: (res : any) => {
console.log("complete", res)
this.done = true
if (res instanceof UniError) {
this.lastCompleteError = res
}
}
} as ReadFileOptions)
},
testWriteReadFileSyncBuffer() {
try {
const fs = uni.getFileSystemManager()
let buffer = new ArrayBuffer(16)
// let int8 = new Int8Array(buffer)
// int8[1] = 20
let float64 = new Float64Array(buffer)
float64[1] = 1.333
fs.writeFileSync(`${uni.env.USER_DATA_PATH}/hello.txt`, buffer, 'utf-8')
if (this.logAble) {
this.log += 'testWriteReadFileSyncBuffer success' + '\n\n'
}
this.testReadFileSyncBuffer()
this.done = true
} catch (e) {
if (this.logAble) {
this.log += 'testWriteReadFileSyncBuffer fail:' + JSON.stringify(e) + '\n\n'
}
this.done = true
}
},
testReadFileSyncBuffer() {
try {
const fs = uni.getFileSystemManager()
let res = fs.readFileSync(`${uni.env.USER_DATA_PATH}/hello.txt`, null)
console.log(res)
let float64 = new Float64Array(res as ArrayBuffer)
for (let i = 0; i < float64.length; i++) {
if (this.logAble) {
this.log += 'testReadFileSyncBuffer success:' + `Byte ${i}: ${float64[i]}` + '\n\n'
}
console.log(`Byte ${i}: ${float64[i]}`);
}
this.arrayBufferRes = float64[1] // 1.333
console.log(this.arrayBufferRes)
} catch (e) {
if (this.logAble) {
this.log += 'testReadFileSyncBuffer fail:' + JSON.stringify(e) + '\n\n'
}
this.done = true
}
},
testWriteReadBuffer() {
const fileManager = uni.getFileSystemManager()
try {
fileManager.mkdirSync(`${this.basePath}${this.mkdirFile}`, true)
} catch (e) {
console.error(e)
}
let buffer = new ArrayBuffer(24)
let float64 = new Float64Array(buffer)
float64[1] = 1.24
float64[2] = 1.33
let that = this
fileManager.write({
fd: this.openFileSyncTest('w+', false),
length: 16,
offset: 8,
data: buffer,
position: 10,
success: (res : WriteResult) => {
console.log("success", res)
const ab = new ArrayBuffer(24)
fileManager.read({
arrayBuffer: ab,
fd: this.openFileSyncTest('a+', false),
length: 8,
position: 10,
success(res : ReadSuccessCallbackResult) {
console.log(res)
let value = new Float64Array(res.arrayBuffer)
for (let i = 0; i < value.length; i++) {
console.log(`Byte ${i}: ${value[i]}`);
if (this.logAble) {
this.log += 'testWriteReadBuffer success:' + `Byte ${i}: ${value[i]}` + '\n\n'
}
}
this.arrayBufferRes = float64[0] //1.24
console.log(this.arrayBufferRes)
},
fail(res) {
console.log(res)
this.done = true
if (res instanceof UniError) {
this.lastCompleteError = res
}
},
complete: (res : any) => {
console.log("complete", res)
this.done = true
if (res instanceof UniError) {
this.lastCompleteError = res
}
}
} as ReadOption)
},
fail: (res : IUniError) => {
this.done = true
if (res instanceof UniError) {
this.lastCompleteError = res
}
},
complete: (_) => {
}
} as WriteOptions)
},
testWriteReadSyncBuffer() {
const fileManager = uni.getFileSystemManager()
try {
fileManager.mkdirSync(`${this.basePath}${this.mkdirFile}`, true)
} catch (e) {
}
try {
let buffer = new ArrayBuffer(24)
let float64 = new Float64Array(buffer)
float64[1] = 1.11
float64[2] = 1.33
let ret = fileManager.writeSync({
fd: this.openFileSyncTest('w+', false),
// data: this.writeData,
data: buffer,
length: 16,
offset: 8,
position: 10,
encoding: "utf-8"
} as WriteSyncOptions)
console.log("success", ret)
const ab = new ArrayBuffer(24)
let res = fileManager.readSync({
arrayBuffer: ab,
fd: this.openFileSyncTest('a+', false),
length: 8,
offset: 8,
position: 10
} as ReadSyncOption)
console.log(res)
let value = new Float64Array(res.arrayBuffer)
for (let i = 0; i < value.length; i++) {
if (this.logAble) {
this.log += 'testWriteReadSyncBuffer success :' + `Byte ${i}: ${value[i]}` + '\n\n'
}
}
this.done = true
this.arrayBufferRes = float64[1] //1.11
console.log(this.arrayBufferRes)
} catch (e) {
this.done = true
if (e instanceof UniError) {
this.lastCompleteError = e
}
console.error(e)
}
},
testAppendFileBufferSync() {
// 同步接口
const fs = uni.getFileSystemManager()
try {
let buffer = new ArrayBuffer(24)
let float64 = new Float64Array(buffer)
float64[1] = 1.2222222
float64[2] = 1.33
let ret = fs.writeSync({
fd: fs.openSync({ filePath: `${uni.env.USER_DATA_PATH}/hello.txt`, flag: 'w+' } as OpenFileSyncOptions),
data: buffer,
length: 16,
offset: 8,
position: 10
} as WriteSyncOptions)
console.log(ret)
buffer = new ArrayBuffer(16)
float64 = new Float64Array(buffer)
float64[0] = 20
fs.appendFileSync(`${uni.env.USER_DATA_PATH}/hello.txt`, buffer, null)
const ab = new ArrayBuffer(32)
// 打开文件
// 读取文件到 ArrayBuffer 中
let readResult = fs.readSync({
fd: fs.openSync({
filePath: `${uni.env.USER_DATA_PATH}/hello.txt`,
flag: 'a+',
} as OpenFileSyncOptions),
arrayBuffer: ab,
length: 24,
position: 10,
offset: 8
} as ReadSyncOption)
console.log(readResult)
float64 = new Float64Array(readResult.arrayBuffer)
for (let i = 0; i < float64.length; i++) {
if (this.logAble) {
this.log += 'testAppendFileBufferSync success :' + `Byte ${i}: ${float64[i]}` + '\n\n'
}
console.log(`Byte ${i}: ${float64[i]}`);
}
this.arrayBufferRes = float64[3] //20
console.log(this.arrayBufferRes)
this.done = true
} catch (e) {
this.done = true
if (this.logAble) {
this.log += 'testAppendFileBufferSync fail:' + JSON.stringify(e) + '\n\n'
}
console.error(e)
}
},
testAppendFileBuffer() {
// 同步接口
const fs = uni.getFileSystemManager()
try {
let buffer = new ArrayBuffer(24)
let float64 = new Float64Array(buffer)
float64[1] = 1.2222222
float64[2] = 1.33
let ret = fs.writeSync({
fd: fs.openSync({ filePath: `${uni.env.USER_DATA_PATH}/hello.txt`, flag: 'w+' } as OpenFileSyncOptions),
data: buffer,
length: 16,
offset: 8,
position: 10
} as WriteSyncOptions)
console.log(ret)
buffer = new ArrayBuffer(16)
float64 = new Float64Array(buffer)
float64[0] = 21
fs.appendFile({
filePath: `${uni.env.USER_DATA_PATH}/hello.txt`,
data: buffer,
success(res) {
console.log(res)
const ab = new ArrayBuffer(32)
// 打开文件
// 读取文件到 ArrayBuffer 中
let readResult = fs.readSync({
fd: fs.openSync({
filePath: `${uni.env.USER_DATA_PATH}/hello.txt`,
flag: 'a+',
} as OpenFileSyncOptions),
arrayBuffer: ab,
length: 24,
position: 10,
offset: 8
} as ReadSyncOption)
console.log(readResult)
float64 = new Float64Array(readResult.arrayBuffer)
for (let i = 0; i < float64.length; i++) {
console.log(`Byte ${i}: ${float64[i]}`);
if (this.logAble) {
this.log += 'testAppendFileBuffer success :' + `Byte ${i}: ${float64[i]}` + '\n\n'
}
}
this.arrayBufferRes = float64[3] //21
console.log(this.arrayBufferRes)
},
fail(res) {
console.log(res)
},
complete: (_) => {
this.done =true
}
} as AppendFileOptions)
} catch (e) {
this.done = true
if (this.logAble) {
this.log += 'testAppendFileBufferSync fail:' + JSON.stringify(e) + '\n\n'
}
console.error(e)
}
}
},
...
...
pages/API/provider/provider.uvue
浏览文件 @
fe7c408e
...
...
@@ -57,7 +57,9 @@
var provider = uni.getProviderSync({
service: item.service,
} as GetProviderSyncOptions)
console.log('getProvider',provider,provider.providerIds.length)
provider.providerIds.forEach((value) => {
console.log('getProvider','value',value)
this.providerIds.push(value)
})
this.updateProvider(item.service, provider.providerIds, provider.providerObjects);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录