Rawfile
Overview
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
Since: 8
Summary
Files
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. |
Structs
Name | Description |
---|---|
RawFileDescriptor | Defines the file descriptor of a large rawfile. |
RawFileDescriptor64 | Defines the file descriptor of a large rawfile. NOTE This new API supports large rawfiles and provides better performance. |
Types
Name | Description |
---|---|
RawDir | Provides access to the rawfile directory. |
RawFile | Provides access to the rawfiles in the rawfile directory. |
RawFile64 | Provides access to the rawfiles in the rawfile directory. NOTE This new API supports large rawfiles and provides better performance. |
NativeResourceManager | Represents the native ResourceManager. |
Functions
Name | Description |
---|---|
OH_ResourceManager_GetRawFileName (RawDir *rawDir, int index) | Obtains the name of a rawfile based on the index. |
OH_ResourceManager_GetRawFileCount (RawDir *rawDir) | Obtains the number of files in the RawDir directory. |
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 of the specified length from the current position in a rawfile. |
OH_ResourceManager_SeekRawFile (const RawFile *rawFile, long offset, int whence) | Searches for the data read/write position based on the specified offset (in long) in a rawfile. |
OH_ResourceManager_GetRawFileSize (RawFile *rawFile) | Obtains the length of the rawfile, in long. |
OH_ResourceManager_GetRawFileRemainingLength (const RawFile *rawFile) | Obtains the remaining length of the rawfile, in long. |
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 rawfile, in long. |
OH_ResourceManager_GetRawFileDescriptor (const RawFile *rawFile, RawFileDescriptor &descriptor) | Opens a rawfile based on the specified offset and file length and obtains the file descriptor. |
OH_ResourceManager_ReleaseRawFileDescriptor (const RawFileDescriptor &descriptor) | Releases the file descriptor of a rawfile. |
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. NOTE This new API supports large rawfiles and provides better performance. |
OH_ResourceManager_SeekRawFile64 (const RawFile64 *rawFile, int64_t offset, int whence) | Searches for the data read/write position based on the specified offset (in int64_t) in a large rawfile. |
OH_ResourceManager_GetRawFileSize64 (RawFile64 *rawFile) | Obtains the length of a large rawfile, in int64_t. |
OH_ResourceManager_GetRawFileRemainingLength64 (const RawFile64 *rawFile) | Obtains the remaining length of a large rawfile, in int64_t. |
OH_ResourceManager_CloseRawFile64 (RawFile64 *rawFile) | Closes a RawFile64 and releases all associated resources. |
OH_ResourceManager_GetRawFileOffset64 (const RawFile64 *rawFile) | Obtains the offset of a large rawfile, in int64_t. |
OH_ResourceManager_GetRawFileDescriptor64 (const RawFile64 *rawFile, RawFileDescriptor64 *descriptor) | Opens a large rawfile based on the specified offset and file length and obtains the file descriptor. |
OH_ResourceManager_ReleaseRawFileDescriptor64 (const RawFileDescriptor64 *descriptor) | Releases the file descriptor of a rawfile. |
OH_ResourceManager_InitNativeResourceManager (napi_env env, napi_value jsResMgr) | Obtains the native ResourceManager based on the JS ResourceManager to implement rawfile-specific functions. |
OH_ResourceManager_ReleaseNativeResourceManager (NativeResourceManager *resMgr) | Releases the native ResourceManager. |
OH_ResourceManager_OpenRawDir (const NativeResourceManager *mgr, const char *dirName) | Traverses all files in the rawfile directory. |
OH_ResourceManager_OpenRawFile (const NativeResourceManager *mgr, const char *fileName) | Opens a rawfile and reads the data in it. |
OH_ResourceManager_OpenRawFile64 (const NativeResourceManager *mgr, const char *fileName) | Opens a large rawfile and reads the data in it. |
Type Description
NativeResourceManager
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
RawDir
typedef struct RawDirRawDir
Description
Provides access to the rawfile directory.
Since: 8
RawFile
typedef struct RawFileRawFile
Description
Provides access to the rawfiles in the rawfile directory.
Since: 8
RawFile64
typedef struct RawFile64RawFile64
Description
Provides access to rawfiles on 64-bit devices..
Since: 11
Function Description
OH_ResourceManager_CloseRawDir()
void OH_ResourceManager_CloseRawDir (RawDir * rawDir)
Description
Closes a RawDir and releases all associated resources.
Since: 8
Parameters
Name | Description |
---|---|
rawDir | Pointer to the RawDir. |
See
OH_ResourceManager_CloseRawFile()
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. |
See
OH_ResourceManager_OpenRawFile
OH_ResourceManager_CloseRawFile64()
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
OH_ResourceManager_OpenRawFile64
OH_ResourceManager_GetRawFileCount()
int OH_ResourceManager_GetRawFileCount (RawDir * rawDir)
Description
Obtains the number of files in the RawDir directory.
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
OH_ResourceManager_GetRawFileDescriptor()
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 rawfile.
Since: 8
Parameters
Name | Description |
---|---|
rawFile | Pointer to the RawFile. |
descriptor | File descriptor of the rawfile, start position of the rawfile in the HAP, and length of the rawfile. |
Returns
true if the rawfile is opened; false if the access to the rawfile is rejected.
OH_ResourceManager_GetRawFileDescriptor64()
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 rawfile.
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 rawfile is opened; false if the access to the rawfile is rejected.
OH_ResourceManager_GetRawFileName()
const char* OH_ResourceManager_GetRawFileName (RawDir * rawDir, int index )
Description
Obtains the name of a rawfile based on the specified index.
You can use this function to traverse the rawfile directory.
Since: 8
Parameters
Name | Description |
---|---|
rawDir | Pointer to the RawDir. |
index | Index of the rawfile in the RawDir. |
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
OH_ResourceManager_OpenRawFile
OH_ResourceManager_GetRawFileOffset()
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. |
Returns
Current offset of the rawfile.
OH_ResourceManager_GetRawFileOffset64()
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
Current offset of the rawfile.
OH_ResourceManager_GetRawFileRemainingLength()
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. |
Returns
Remaining length of the rawfile.
OH_ResourceManager_GetRawFileRemainingLength64()
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.
OH_ResourceManager_GetRawFileSize()
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. |
Returns
Overall length of the rawfile.
OH_ResourceManager_GetRawFileSize64()
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.
OH_ResourceManager_InitNativeResourceManager()
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 the NativeResourceManager.
OH_ResourceManager_OpenRawDir()
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.
See
OH_ResourceManager_InitNativeResourceManager
OH_ResourceManager_CloseRawDir
OH_ResourceManager_OpenRawFile()
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 rawfile 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.
See
OH_ResourceManager_InitNativeResourceManager
OH_ResourceManager_CloseRawFile
OH_ResourceManager_OpenRawFile64()
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 rawfile 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.
See
OH_ResourceManager_InitNativeResourceManager
OH_ResourceManager_CloseRawFile64
OH_ResourceManager_ReadRawFile()
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. |
buf | Pointer to the buffer for receiving the read data. |
length | Length of the data to read. |
Returns
Returns the number of bytes read. If the read length exceeds the length of the file end, 0 will be returned.
OH_ResourceManager_ReadRawFile64()
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
Returns the number of bytes read. If the read length exceeds the length of the file end, 0 will be returned.
OH_ResourceManager_ReleaseNativeResourceManager()
void OH_ResourceManager_ReleaseNativeResourceManager (NativeResourceManager * resMgr)
Description
Releases the native ResourceManager.
Since: 8
Parameters
Name | Description |
---|---|
resMgr | Pointer to the NativeResourceManager to release. |
OH_ResourceManager_ReleaseRawFileDescriptor()
bool OH_ResourceManager_ReleaseRawFileDescriptor (const RawFileDescriptor & descriptor)
Description
Releases the file descriptor of a 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
true if the file descriptor is released; false otherwise.
OH_ResourceManager_ReleaseRawFileDescriptor64()
bool OH_ResourceManager_ReleaseRawFileDescriptor64 (const RawFileDescriptor64 * descriptor)
Description
Releases the file descriptor of a 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.
OH_ResourceManager_SeekRawFile()
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. |
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.
OH_ResourceManager_SeekRawFile64()
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.