readFileSync
Start from API_LEVEL
2.0. Please refer to API_LEVEL.
Returns the entire contents of the specified file in the /data directory of the Mini Program.
Type
function readFileSync(option: Option): Result
Parameters
Option
| Property | Type | Required | DefaultValue | Description | API_LEVEL |
|---|---|---|---|---|---|
| path | string | Y | - | path | 2.0 |
| options | Options | N | - | Other Options | 2.0 |
Options
| Property | Type | Required | DefaultValue | Description | API_LEVEL |
|---|---|---|---|---|---|
| encoding | string | N | - | When the encoding method is specified, the API returns string as the result | 2.0 |
Result
| Type | Description |
|---|---|
ArrayBuffer|string|undefined | File content. If undefined is returned, the file failed to be read |
Example
import { readFileSync } from '@zos/fs'
const contentBuffer = readFileSync({
path: 'test.txt',
})
const contentString = readFileSync({
path: 'test.txt',
options: {
encoding: 'utf8',
},
})