Skip to main content
Version: v3

openAssetsSync

Start from API_LEVEL 2.0 . Please refer to API_LEVEL.

Open the file in the /assets directory of the Mini Program synchronously and get the file handle.

Type

function openAssetsSync(option: Option): Result

Parameters

Option

PropertyTypeRequiredDefaultValueDescriptionAPI_LEVEL
pathstringY-path2.0
flagnumberNO_RDONLYValue refer to file open constants2.0

Result

TypeDescription
numberThe numeric file descriptor

Constants

file open constants

ConstantDescriptionAPI_LEVEL
O_RDONLYFlag indicating to open a file for read-only access2.0
O_WRONLYFlag indicating to open a file for write-only access2.0
O_RDWRFlag indicating to open a file for read-write access2.0
O_APPENDFlag indicating that data will be appended to the end of the file2.0
O_CREATFlag indicating to create the file if it does not already exist2.0
O_EXCLFlag indicating that opening a file should fail if the O_CREAT flag is set and the file already exists2.0
O_TRUNCFlag indicating that if the file exists and the file is opened successfully for write access, its length shall be truncated to zero2.0

Example

import { openSync, O_RDONLY } from '@zos/fs'

const fd = openAssetsSync({
path: 'test.txt',
flag: O_RDONLY,
})