FileSystemManager.writeSync
FileSystemManager.write 的同步方法
参数
参数 | 类型 | 默认值 | 必填 | 说明 | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
fd | string | 是 | 文件描述符。通过 FileSystemManager.open 接口获得 | ||||||||||||||||||||||||||
data | string | ArrayBuffer | 是 | 写入的内容,类型为 string 或 ArrayBuffer | ||||||||||||||||||||||||||
offset | number | 0 | 否 | 只在 data 类型是 ArrayBuffer 时有效,决定 arrayBuffe 中要被写入的部位,即 arrayBuffer 中的索引,默认0 | |||||||||||||||||||||||||
length | number | 否 | 只在 data 类型是 ArrayBuffer 时有效,指定要写入的字节数,默认为 arrayBuffer 从0开始偏移 offset 个字节后剩余的字节数 | ||||||||||||||||||||||||||
encoding | string | utf8 | 否 | 只在 data 类型是 String 时有效,指定写入文件的字符编码,默认为 utf8 | |||||||||||||||||||||||||
| |||||||||||||||||||||||||||||
position | number | 否 | 指定文件开头的偏移量,即数据要被写入的位置。当 position 不传或者传入非 Number 类型的值时,数据会被写入当前指针所在位置 |
返回值
文件读取结果
Example
ts
const fs = ek.getFileSystemManager()
try {
const fd = fs.openSync({ filePath: `${ek.env.USER_DATA_PATH}/hello.txt`, flag: 'a+' })
const res = fs.writeSync({
fd,
data: 'some text'
})
console.log(res.bytesWritten)
} catch (e) {
console.log(e)
}