Skip to main content
Version: v2

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

PropertyTypeRequiredDefaultValueDescriptionAPI_LEVEL
pathstringY-path2.0
optionsOptionsN-Other Options2.0

Options

PropertyTypeRequiredDefaultValueDescriptionAPI_LEVEL
encodingstringN-When the encoding method is specified, the API returns string as the result2.0

Result

TypeDescription
ArrayBuffer|string|undefinedFile 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',
},
})