Provides the function of operating rawfile directories and rawfiles. You can use the APIs to traverse, open, search for, read, and close raw files. The rawfile APIs are non-thread-safe, and the close and open APIs are thread-safe.
Since: 8
| Name | Description |
|---|---|
| raw_dir.h | Provides functions related to the rawfile directory. |
| raw_file.h | Provides functions related to rawfiles, including searching for, reading, and closing rawfiles. |
| raw_file_manager.h | Provides file management functions for the rawfile directory. You can use the ResourceManager to open a rawfile and perform operations such as data search and reading. |
| Name | Description |
|---|---|
| struct RawFileDescriptor | Defines the file descriptor information of a file in the rawfile directory. |
| struct RawFileDescriptor64 | Defines the file descriptor of a large rawfile. |
| Name | Description |
|---|---|
| typedef struct RawDirRawDir | Provides access to the rawfile directory. |
| typedef struct RawFileRawFile | Provides access to rawfiles. |
| typedef struct RawFile64RawFile64 | Provides access to large rawfiles. |
| typedef struct NativeResourceManagerNativeResourceManager | Represents the native ResourceManager. |
| Name | Description |
|---|---|
| const char * OH_ResourceManager_GetRawFileName (RawDir *rawDir, int index) | Obtains the name of a file in rawfile based on the index. |
| int OH_ResourceManager_GetRawFileCount (RawDir *rawDir) | Obtains the number of files in a RawDir. |
| void OH_ResourceManager_CloseRawDir (RawDir *rawDir) | Closes a RawDir and releases all associated resources. |
| int OH_ResourceManager_ReadRawFile (const RawFile *rawFile, void *buf, size_t length) | Reads data of the specified length from the current position in a rawfile. |
| int OH_ResourceManager_SeekRawFile (const RawFile *rawFile, long offset, int whence) | Searches for the data read/write position in a rawfile based on the specified offset. |
| long OH_ResourceManager_GetRawFileSize (RawFile *rawFile) | Obtains the length of the rawfile, in long. |
| long OH_ResourceManager_GetRawFileRemainingLength (const RawFile *rawFile) | Obtains the remaining length of the rawfile, in long. |
| void OH_ResourceManager_CloseRawFile (RawFile *rawFile) | Closes a RawFile and releases all associated resources. |
| long OH_ResourceManager_GetRawFileOffset (const RawFile *rawFile) | Obtains the current offset of a rawfile, in long. |
| bool OH_ResourceManager_GetRawFileDescriptor (const RawFile *rawFile, RawFileDescriptor &descriptor) | Opens a rawfile based on the specified offset (in long) and file length (in long) and obtains the file descriptor. |
| bool OH_ResourceManager_ReleaseRawFileDescriptor (const RawFileDescriptor &descriptor) | Releases a file descriptor. |
| int64_t OH_ResourceManager_ReadRawFile64 (const RawFile64 *rawFile, void *buf, int64_t length) | Reads data of the specified length from the current position in a large rawfile. |
| int OH_ResourceManager_SeekRawFile64 (const RawFile64 *rawFile, int64_t offset, int whence) | Searches for the data read/write position in a large rawfile based on the specified offset. |
| int64_t OH_ResourceManager_GetRawFileSize64 (RawFile64 *rawFile) | Obtains the length of a large rawfile, in int64_t. |
| int64_t OH_ResourceManager_GetRawFileRemainingLength64 (const RawFile64 *rawFile) | Obtains the remaining length of a large rawfile, in int64_t. |
| void OH_ResourceManager_CloseRawFile64 (RawFile64 *rawFile) | Closes a RawFile64 and releases all associated resources. |
| int64_t OH_ResourceManager_GetRawFileOffset64 (const RawFile64 *rawFile) | Obtains the offset of a large rawfile, in int64_t. |
| bool OH_ResourceManager_GetRawFileDescriptor64 (const RawFile64 *rawFile, RawFileDescriptor64 *descriptor) | Opens a large rawfile based on the specified offset (in int64_t) and file length (in int64_t) and obtains the file descriptor. |
| bool OH_ResourceManager_ReleaseRawFileDescriptor64 (const RawFileDescriptor64 *descriptor) | Releases a file descriptor. |
| NativeResourceManager * OH_ResourceManager_InitNativeResourceManager (napi_env env, napi_value jsResMgr) | Obtains the native ResourceManager based on the JS ResourceManager to implement rawfile-specific functions. |
| void OH_ResourceManager_ReleaseNativeResourceManager (NativeResourceManager *resMgr) | Releases the native ResourceManager. |
| RawDir * OH_ResourceManager_OpenRawDir (const NativeResourceManager *mgr, const char *dirName) | Traverses all files in the rawfile directory. |
| RawFile * OH_ResourceManager_OpenRawFile (const NativeResourceManager *mgr, const char *fileName) | Opens a rawfile and reads the data in it. |
| RawFile64 * OH_ResourceManager_OpenRawFile64 (const NativeResourceManager *mgr, const char *fileName) | Opens a large rawfile and reads the data in it. |
| bool OH_ResourceManager_IsRawDir (const NativeResourceManager *mgr, const char *path) | Checks whether a path is a subdirectory in the rawfile directory. |
typedef struct NativeResourceManagerNativeResourceManager
Description
Represents the native ResourceManager.
This class encapsulates the native implementation of the JavaScript resource manager. The ResourceManager pointer can be obtained by using OH_ResourceManager_InitNativeResourceManager.
Since: 8
typedef struct RawDirRawDir
Description
Provides access to the rawfile directory.
Since: 8
typedef struct RawFile64RawFile64
Description
Provides access to large rawfiles.
Since: 11
void OH_ResourceManager_CloseRawDir (RawDir * rawDir)
Description
Closes a RawDir opened and releases all associated resources.
Since: 8
Parameters
| Name | Description |
|---|---|
| rawDir | Pointer to the RawDir. |
See
void OH_ResourceManager_CloseRawFile (RawFile * rawFile)
Description
Closes a RawFile and releases all associated resources.
Since: 8
Parameters
| Name | Description |
|---|---|
| rawFile | Pointer to the RawFile to read. |
See
void OH_ResourceManager_CloseRawFile64 (RawFile64 * rawFile)
Description
Closes a RawFile64 and releases all associated resources.
Since: 11
Parameters
| Name | Description |
|---|---|
| rawFile | Pointer to RawFile64. |
See
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.
Since: 8
Parameters
| Name | Description |
|---|---|
| rawDir | Pointer to the RawDir. |
See
OH_ResourceManager_GetRawFileName
Returns
Number of files in rawDir. If rawDir is empty, 0 is returned.
bool OH_ResourceManager_GetRawFileDescriptor (const RawFile * rawFile, RawFileDescriptor & descriptor )
Description
Opens a rawfile based on the specified offset (in long) and file length (in long) and obtains the file descriptor.
The file descriptor obtained can be used to read the file.
Since: 8
Parameters
| Name | Description |
|---|---|
| rawFile | Pointer to the RawFile to read. |
| descriptor | File descriptor of the rawfile, start position of the rawfile in the HAP, and length of the rawfile. |
Returns
true if the file is opened; returns false if the access to the file is rejected.
bool OH_ResourceManager_GetRawFileDescriptor64 (const RawFile64 * rawFile, RawFileDescriptor64 * descriptor )
Description
Opens a large rawfile based on the specified offset (in int64_t) and file length (in int64_t) and obtains the file descriptor.
The file descriptor obtained can be used to read the file.
Since: 11
Parameters
| Name | Description |
|---|---|
| rawFile | Pointer to RawFile64. |
| File descriptor of the rawfile, start position of the rawfile in the HAP, and length of the rawfile. |
Returns
true if the file is opened; false if the access to the file is rejected.
const char* OH_ResourceManager_GetRawFileName (RawDir * rawDir, int index )
Description
Obtain the name of the rawfile file through the index. You can use this method to traverse the rawfile directory.
Since: 8
Parameters
Returns
File name obtained if the rawfile exists in the directory; returns null otherwise. The file name returned can be used as the input parameter of OH_ResourceManager_OpenRawFile.
See
long OH_ResourceManager_GetRawFileOffset (const RawFile * rawFile)
Description
Obtains the current offset of a rawfile, in long.
Current offset of the rawfile.
Since: 8
Parameters
| Name | Description |
|---|---|
| rawFile | Pointer to the RawFile to read. |
Returns
Current offset of the rawfile. If the rawfile is empty, 0 is returned.
int64_t OH_ResourceManager_GetRawFileOffset64 (const RawFile64 * rawFile)
Description
Obtains the offset of a large rawfile, in int64_t.
Since: 11
Parameters
| Name | Description |
|---|---|
| rawFile | Pointer to RawFile64. |
Returns
Returns the current offset of the rawfile. If the rawfile is empty, 0 is returned.
long OH_ResourceManager_GetRawFileRemainingLength (const RawFile * rawFile)
Description
Obtains the remaining length of the rawfile, in long.
Since: 11
Parameters
| Name | Description |
|---|---|
| rawFile | Pointer to the RawFile to read. |
Returns
Remaining length of the rawfile. If the rawfile is empty, 0 is returned.
int64_t OH_ResourceManager_GetRawFileRemainingLength64 (const RawFile64 * rawFile)
Description
Obtains the remaining length of a large rawfile, in int64_t.
Since: 11
Parameters
| Name | Description |
|---|---|
| rawFile | Pointer to RawFile64. |
Returns
Remaining length of the rawfile. If the rawfile is empty, 0 is returned.
long OH_ResourceManager_GetRawFileSize (RawFile * rawFile)
Description
Obtains the length of the rawfile, in long.
Since: 8
Parameters
| Name | Description |
|---|---|
| rawFile | Pointer to the RawFile to read. |
Returns
Overall length of the rawfile. If the rawfile is empty, 0 is returned.
int64_t OH_ResourceManager_GetRawFileSize64 (RawFile64 * rawFile)
Description
Obtains the length of a large rawfile, in int64_t.
Since: 11
Parameters
| Name | Description |
|---|---|
| rawFile | Pointer to RawFile64. |
Returns
Overall length of the rawfile. If the rawfile is empty, 0 is returned.
NativeResourceManager* OH_ResourceManager_InitNativeResourceManager (napi_env env, napi_value jsResMgr )
Description
Obtains the native ResourceManager based on the JS ResourceManager to implement rawfile-specific functions.
Since: 8
Parameters
| Name | Description |
|---|---|
| env | Pointer to the JS native API (napi) environment. |
| jsResMgr | JS ResourceManager. |
Returns
Pointer to NativeResourceManager. If the operation fails, a null pointer is returned.
bool OH_ResourceManager_IsRawDir (const NativeResourceManager * mgr, const char * path )
Description
Checks whether a path is a subdirectory in the rawfile directory.
Since: 12
Parameters
| Name | Description |
|---|---|
| mgr | Pointer to the NativeResourceManager, which is obtained by using OH_ResourceManager_InitNativeResourceManager. |
| path | Path of a rawfile. |
Returns
true if the path is a subdirectory in the rawfile directory; false otherwise.
RawDir* OH_ResourceManager_OpenRawDir (const NativeResourceManager * mgr, const char * dirName )
Description
Traverses all files in the rawfile directory.
Since: 8
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
Pointer to the RawDir. You can use OH_ResourceManager_CloseRawDir to close the directory and release resources. If the operation fails or mgr is empty, a null pointer is returned.
See
RawFile* OH_ResourceManager_OpenRawFile (const NativeResourceManager * mgr, const char * fileName )
Description
Opens a rawfile and reads the data in it.
Since: 8
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
Pointer to the RawFile opened. You can use OH_ResourceManager_CloseRawFile to close the rawfile and release resources. If the operation fails or mgr or fileName is empty, a null pointer is returned.
See
RawFile64* OH_ResourceManager_OpenRawFile64 (const NativeResourceManager * mgr, const char * fileName )
Description
Opens a large rawfile and reads the data in it.
Since: 11
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
Pointer to RawFile64. After this pointer is used, call OH_ResourceManager_CloseRawFile64 to release it. If the operation fails or mgr or fileName is empty, a null pointer is returned.
See
int OH_ResourceManager_ReadRawFile (const RawFile * rawFile, void * buf, size_t length )
Description
Reads data of the specified length from the current position in a rawfile.
Since: 8
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
Number of read bytes. If the read length exceeds the length of the file end or rawfile is empty, 0 is returned.
int64_t OH_ResourceManager_ReadRawFile64 (const RawFile64 * rawFile, void * buf, int64_t length )
Description
Reads data of the specified length from the current position in a large rawfile.
Since: 11
Parameters
| Name | Description |
|---|---|
| rawFile | Pointer to RawFile64. |
| buf | Pointer to the buffer for receiving the read data. |
| length | Length of the data to read. |
Returns
Number of read bytes. If the read length exceeds the length of the file end or rawfile is empty, 0 is returned.
void OH_ResourceManager_ReleaseNativeResourceManager (NativeResourceManager * resMgr)
Description
Releases the native ResourceManager.
Since: 8
Parameters
| Name | Description |
|---|---|
| resMgr | Pointer to the NativeResourceManager instance to release. |
bool OH_ResourceManager_ReleaseRawFileDescriptor (const RawFileDescriptor & descriptor)
Description
Releases the file descriptor of a file in rawfile.
To prevent file descriptor leakage, you are advised to release a rawfile descriptor immediately after use.
Since: 8
Parameters
| Name | Description |
|---|---|
| descriptor | File descriptor of the rawfile. It contains the file descriptor, start position in the HAP, and file length. |
Returns
Returns true if the file descriptor is released; returns false otherwise.
bool OH_ResourceManager_ReleaseRawFileDescriptor64 (const RawFileDescriptor64 * descriptor)
Description
Releases the file descriptor of a file in rawfile.
To prevent file descriptor leakage, you are advised to release a rawfile descriptor immediately after use.
Since: 11
Parameters
| Name | Description |
|---|---|
| descriptor | File descriptor of the rawfile. It contains the file descriptor, start position in the HAP, and file length. |
Returns
true if the file descriptor is released; false otherwise.
int OH_ResourceManager_SeekRawFile (const RawFile * rawFile, long offset, int whence )
Description
Searches for the data read/write position in a rawfile based on the specified offset.
Since: 8
Parameters
| Name | Description |
|---|---|
| rawFile | Pointer to the RawFile to read. |
| offset | Specified offset. |
| whence | Read/Write position. The options are as follows: 0: The read/write position is the start position of the file plus the offset. 1: The read/write position is the current position plus the offset. 2: The read/write position is the end position of the file plus the offset. |
Returns
0 if the search is successful; -1 otherwise.
int OH_ResourceManager_SeekRawFile64 (const RawFile64 * rawFile, int64_t offset, int whence )
Description
Searches for the data read/write position in a large rawfile based on the specified offset.
Since: 11
Parameters
| Name | Description |
|---|---|
| rawFile | Pointer to RawFile64. |
| offset | Specified offset. |
| whence | Read/Write position. The options are as follows: 0: The read/write position is the start position of the file plus the offset. 1: The read/write position is the current position plus the offset. 2: The read/write position is the end position of the file plus the offset. |
Returns
0 if the search is successful; -1 otherwise.