Rawfile
Provides APIs for operating the rawfile directory and its files, including traversing the rawfile directory and opening, searching for, reading, and closing a file in it.
Since
8
Summary
Files
Name | Description |
---|---|
raw_dir.h | Provides functions related to the rawfile directory. File to include: <rawfile/raw_dir.h> Library: librawfile.z.so |
raw_file.h | Provides functions related to the files in the rawfile directory. File to include: <rawfile/raw_file.h> Library: librawfile.z.so |
raw_file_manager.h | Provides file management functions for the rawfile directory. File to include: <rawfile/raw_file_manager.h> Library: librawfile.z.so |
Structs
Name | Description |
---|---|
RawFileDescriptor | Defines the file descriptor (FD) information of a file in the rawfile directory. |
Types
Name | Description |
---|---|
RawDir | Provides access to the rawfile directory. |
RawFile | Provides access to the files in rawfile. |
NativeResourceManager | Represents the resource manager. |
Functions
Name | Description |
---|---|
OH_ResourceManager_GetRawFileName (RawDir *rawDir, int index) | Obtains the name of a file in rawfile based on the index. |
OH_ResourceManager_GetRawFileCount (RawDir *rawDir) | Obtains the number of files in a RawDir. |
OH_ResourceManager_CloseRawDir (RawDir *rawDir) | Closes a RawDir and releases all associated resources. |
OH_ResourceManager_ReadRawFile (const RawFile *rawFile, void *buf, size_t length) | Reads data from a file in rawfile. |
OH_ResourceManager_SeekRawFile (const RawFile *rawFile, long offset, int whence) | Seeks for the data read/write position in a file in rawfile based on the specified offset. |
OH_ResourceManager_GetRawFileSize (RawFile *rawFile) | Obtains the size of a file in rawfile. |
OH_ResourceManager_CloseRawFile (RawFile *rawFile) | Closes a RawFile and releases all associated resources. |
OH_ResourceManager_GetRawFileOffset (const RawFile *rawFile) | Obtains the current offset of a file in rawfile. |
OH_ResourceManager_GetRawFileDescriptor (const RawFile *rawFile, RawFileDescriptor &descriptor) | Opens a file in rawfile based on the offset and file length and obtains the FD. |
OH_ResourceManager_ReleaseRawFileDescriptor (const RawFileDescriptor &descriptor) | Releases an FD. |
OH_ResourceManager_InitNativeResourceManager (napi_env env, napi_value jsResMgr) | Initializes a Native resource manager using the JavaScript resource manager. You can use the Native resource manager obtained to implement operations related to rawfile. |
OH_ResourceManager_ReleaseNativeResourceManager (NativeResourceManager *resMgr) | Releases a Native resource manager instance. |
OH_ResourceManager_OpenRawDir (const NativeResourceManager *mgr, const char *dirName) | Opens a directory in the rawfile directory. |
OH_ResourceManager_OpenRawFile (const NativeResourceManager *mgr, const char *fileName) | Opens a file in the rawfile directory. |
Description
Type Description
NativeResourceManager
typedef struct NativeResourceManager NativeResourceManager
Description
Represents the resource manager.
This class encapsulates the native implementation of the JavaScript resource manager. The ResourceManager pointer can be obtained by using OH_ResourceManager_InitNativeResourceManager.
Since
8
RawDir
typedef struct RawDir RawDir
Description
Provides access to the rawfile directory.
Since
8
RawFile
typedef struct RawFile RawFile
Description
Provides access to the files in rawfile.
Since
8
Function Description
OH_ResourceManager_CloseRawDir()
void OH_ResourceManager_CloseRawDir (RawDir * rawDir)
Description
Closes a RawDir opened and releases all associated resources.
Parameters
Name | Description |
---|---|
rawDir | Pointer to the RawDir to close. |
See
Since
8
OH_ResourceManager_CloseRawFile()
void OH_ResourceManager_CloseRawFile (RawFile * rawFile)
Description
Closes a RawFile and releases all associated resources.
Parameters
Name | Description |
---|---|
rawFile | Pointer to the RawFile to close. |
See
OH_ResourceManager_OpenRawFile
Since
8
OH_ResourceManager_GetRawFileCount()
int OH_ResourceManager_GetRawFileCount (RawDir * rawDir)
Description
Obtains the number of files in a RawDir.
You can use this function to obtain available indexes in OH_ResourceManager_GetRawFileName.
Parameters
Name | Description |
---|---|
rawDir | Pointer to the target RawDir. |
See
OH_ResourceManager_GetRawFileName
Since
8
OH_ResourceManager_GetRawFileDescriptor()
bool OH_ResourceManager_GetRawFileDescriptor (const RawFile * rawFile, RawFileDescriptor & descriptor )
Description
Opens a file in the rawfile directory based on the offset and file length and obtains the FD.
The FD obtained can be used to read the file.
Parameters
Name | Description |
---|---|
rawFile | Pointer to the RawFile. |
descriptor | File descriptor of the file, start position of the file in the hAP, and length of the file. |
Returns
Returns true if the file is opened; returns false if the access to the file is rejected.
Since
8
OH_ResourceManager_GetRawFileName()
const char* OH_ResourceManager_GetRawFileName (RawDir * rawDir, int index )
Description
Obtains the name of a file in rawfile based on the index.
You can use this function to traverse the rawfile directory.
Parameters
Name | Description |
---|---|
rawDir | Pointer to the RawDir. |
index | Index of the file in the RawDir. |
Returns
Returns the file name obtained if the file exists in the directory; returns null otherwise. The file name returned can be used as the input parameter of OH_ResourceManager_OpenRawFile.
See
OH_ResourceManager_OpenRawFile
Since
8
OH_ResourceManager_GetRawFileOffset()
long OH_ResourceManager_GetRawFileOffset (const RawFile * rawFile)
Description
Obtains the current offset of a file in rawfile.
The offset indicates the position of the file in the HAP.
Parameters
Name | Description |
---|---|
rawFile | Pointer to the target RawFile. |
Returns
Returns the file offset obtained.
Since
8
OH_ResourceManager_GetRawFileSize()
long OH_ResourceManager_GetRawFileSize (RawFile * rawFile)
Description
Obtains the size of a file in rawfile.
Parameters
Name | Description |
---|---|
rawFile | Pointer to the target RawFile. |
Returns
Returns the file size obtained.
Since
8
OH_ResourceManager_InitNativeResourceManager()
NativeResourceManager* OH_ResourceManager_InitNativeResourceManager (napi_env env, napi_value jsResMgr )
Description
Initializes a Native resource manager using the JavaScript resource manager.
You can use the resource manager obtained to implement rawfile operations.
Parameters
Name | Description |
---|---|
env | Pointer to the JavaScript Native API (napi) environment. |
jsResMgr | JavaScript resource manager. |
Returns
Returns the pointer to the NativeResourceManager obtained.
Since
8
OH_ResourceManager_OpenRawDir()
RawDir* OH_ResourceManager_OpenRawDir (const NativeResourceManager * mgr, const char * dirName )
Description
Opens a directory in rawfile.
After opening the directory, you can traverse all files in it.
Parameters
Name | Description |
---|---|
mgr | Pointer to the NativeResourceManager, which is obtained by using OH_ResourceManager_InitNativeResourceManager. |
dirName | Pointer to the name of the directory to open. If this field is left empty, the root directory will be opened. |
Returns
Returns the pointer to the RawDir opened. You can use OH_ResourceManager_CloseRawDir to close the directory and release resources.
See
OH_ResourceManager_InitNativeResourceManager
OH_ResourceManager_CloseRawDir
Since
8
OH_ResourceManager_OpenRawFile()
RawFile* OH_ResourceManager_OpenRawFile (const NativeResourceManager * mgr, const char * fileName )
Description
Opens a file in rawfile.
After the file is opened, you can read data in it.
Parameters
Name | Description |
---|---|
mgr | Pointer to the NativeResourceManager, which is obtained by using OH_ResourceManager_InitNativeResourceManager. |
fileName | Pointer to the name of the file in the relative path of the rawfile root directory. |
Returns
Returns the pointer to the RawFile opened. You can use OH_ResourceManager_CloseRawFile to close the file and release resources.
See
OH_ResourceManager_InitNativeResourceManager
OH_ResourceManager_CloseRawFile
Since
8
OH_ResourceManager_ReadRawFile()
int OH_ResourceManager_ReadRawFile (const RawFile * rawFile, void * buf, size_t length )
Description
Reads data of the specified raw file.
Parameters
Name | Description |
---|---|
rawFile | Pointer to the RawFile to read. |
buf | Pointer to the buffer for receiving the read data. |
length | Length of the data to read. |
Returns
Length of the raw file read. If length is less than the file length, 0 is returned.
Since
8
OH_ResourceManager_ReleaseNativeResourceManager()
void OH_ResourceManager_ReleaseNativeResourceManager (NativeResourceManager * resMgr)
Description
Releases a Native resource manager instance.
Parameters
Name | Description |
---|---|
resMgr | Pointer to the NativeResourceManager instance to release. |
Since
8
OH_ResourceManager_ReleaseRawFileDescriptor()
bool OH_ResourceManager_ReleaseRawFileDescriptor (const RawFileDescriptor & descriptor)
Description
Releases the FD of a file in rawfile.
To prevent FD leakage, you are advised to release an FD immediately after use.
Parameters
Name | Description |
---|---|
descriptor | File descriptor to close. It contains the FD, start position in the HAP, and file length. |
Returns
Returns true if the FD is released; returns false otherwise.
Since
8
OH_ResourceManager_SeekRawFile()
int OH_ResourceManager_SeekRawFile (const RawFile * rawFile, long offset, int whence )
Description
Seeks for the data read/write position in a file in rawfile based on the specified offset.
Parameters
Name | Description |
---|---|
rawFile | Pointer to the target RawFile. |
offset | Offset. |
whence | Read/Write position. The options are as follows: 0: The read/write position is the offset. 1: The read/write position is the current position plus the offset. 2: The read/write position is the end of the file (EOF) plus the offset. |
Returns
If the operation is successful, 0 is returned and the rawFile pointer is directed to the new read/write position. If an error occurs, (long) -1 is returned.
Since
8