# FileSystemManager.read(Object object)
Start from base library version 2.16.1. Please remaining backward compatible.
with Promise style call: Not supported
Mini Program plugin: Support, need to Mini Program base library version no less than 2.19.2
Read Files
# parameter
# Object object
attribute | type | Default values | Required | Introductions |
---|---|---|---|---|
fd | string | yes | File descriptor. fd adopt FileSystemManager.open or FileSystemManager.openSync Interface acquisition | |
arrayBuffer | ArrayBuffer | yes | The buffer to which the data is written must be ArrayBuffer Example | |
offset | number | 0 | no | Write offset in buffer, default 0 |
length | number | 0 | no | Number of bytes to read from the file, default 0 |
position | number | no | The starting position of a file read, such as no upload or upload Null, it is read from the position of the current file pointer. if position Is a positive integer, the file pointer position remains the same and is converted from the position Read the file. | |
success | function | no | Interface calls the successful callback function | |
fail | function | no | Interface calls failed callback functions | |
complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) |
# object.success callback
# parameter
# Object res
attribute | type | Introductions |
---|---|---|
bytesRead | number | Number of bytes actually read |
arrayBuffer | ArrayBuffer | Object that is written to the buffer, that is, the arrayBuffer |
# object.fail callback
# parameter
# Object res
attribute | type | Introductions |
---|---|---|
errMsg | string | Error message |
res.errMsg Legal value
value | Introductions | Minimum version |
---|---|---|
bad file descriptor | Invalid file descriptor | |
fail permission denied | Specified fd Path not read | |
fail the value of "offset" is out of range | Incoming offset illegal | |
fail the value of "length" is out of range | Incoming length illegal | |
fail sdcard not mounted | android sdcard Mount failure | |
bad file descriptor | Invalid file descriptor |
# sample code
const fs = wx.getFileSystemManager()
const ab = new ArrayBuffer(1024)
// Open the file
fs.open({
filePath: `${wx.env.USER_DATA_PATH}/hello.txt`,
flag: 'a+',
success(res) {
// Read file to ArrayBuffer in
fs.read({
fd: res.fd,
arrayBuffer: AB,
length: 10,
success(res) {
console.log(res)
}
})
}
})