readSync
Start from API_LEVEL
2.0. Please refer to API_LEVEL.
Synchronously reads the content from the file specified by the file handle into the given ArrayBuffer..
Type
function readSync(option: Option): Result
Parameters
Option
| Property | Type | Required | DefaultValue | Description | API_LEVEL |
|---|---|---|---|---|---|
| fd | number | Y | - | File handle, returned by the openSync, openAssetsSync and other APIs | 2.0 |
| buffer | ArrayBuffer | Y | - | The ArrayBuffer that the data will be written to | 2.0 |
| options | Options | N | - | Other Options | 2.0 |
Options
| Property | Type | Required | DefaultValue | Description | API_LEVEL |
|---|---|---|---|---|---|
| offset | number | N | 0 | The position in buffer to write the data to | 2.0 |
| length | number | N | buffer.byteLength | The number of bytes to read, the default is the number of bytes passed into the buffer | 2.0 |
| position | number|null | N | null | Specifies the position from which to start reading from the file. If position is null, the data will be read from the current file position and the file position will be updated | 2.0 |
Result
| Type | Description |
|---|---|
number | The number of bytes read |
Example
import { openSync, readSync, O_RDONLY } from '@zos/fs'
const fd = openSync({
path: 'test.txt',
flag: O_RDONLY,
})
const buffer = new ArrayBuffer(4)
const result = readSync({
fd,
buffer,
})