harmony 鸿蒙Rawfile
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
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 |
---|---|
struct RawFileDescriptor | Defines the file descriptor information of a file in the rawfile directory. |
struct RawFileDescriptor64 | Defines the file descriptor of a large rawfile. |
Types
Name | Description |
---|---|
typedef struct RawDir RawDir | Provides access to the rawfile directory. |
typedef struct RawFile RawFile | Provides access to rawfiles. |
typedef struct RawFile64 RawFile64 | Provides access to large rawfiles. |
typedef struct NativeResourceManager NativeResourceManager | Represents the native ResourceManager. |
Functions
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. |
bool OH_ResourceManager_ReleaseRawFileDescriptorData (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. |
Type Description
NativeResourceManager
typedef struct NativeResourceManager NativeResourceManager
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 RawDir RawDir
Description
Provides access to the rawfile directory.
Since: 8
RawFile
typedef struct RawFile RawFile
Description
Provides access to rawfiles.
Since: 8
RawFile64
typedef struct RawFile64 RawFile64
Description
Provides access to large rawfiles.
Since: 11
Function Description
OH_ResourceManager_CloseRawDir()
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
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 to read. |
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 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.
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 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.
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 file.
Since: 11
Parameters
Name | Description |
---|---|
rawFile | Pointer to RawFile64. |
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; false if the access to the file is rejected.
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.
Since: 8
Parameters
Name | Description |
---|---|
rawDir | Pointer to the RawDir. |
index | Index of the file 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 to read. |
Returns
Current offset of the rawfile. If the rawfile is empty, 0 is returned.
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
Returns the current offset of the rawfile. If the rawfile is empty, 0 is returned.
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 to read. |
Returns
Remaining length of the rawfile. If the rawfile is empty, 0 is returned.
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. If the rawfile is empty, 0 is returned.
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 to read. |
Returns
Overall length of the rawfile. If the rawfile is empty, 0 is returned.
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. If the rawfile is empty, 0 is returned.
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 JavaScript Native API (napi) environment. |
jsResMgr | JS ResourceManager. |
Returns
Pointer to NativeResourceManager. If the operation fails, a null pointer is returned.
OH_ResourceManager_IsRawDir()
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.
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. If the operation fails or mgr is empty, a null pointer is returned.
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 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
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 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
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 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.
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
Number of read bytes. If the read length exceeds the length of the file end or rawfile is empty, 0 is 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 instance to release. |
OH_ResourceManager_ReleaseRawFileDescriptor()
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.
OH_ResourceManager_ReleaseRawFileDescriptorData()
bool OH_ResourceManager_ReleaseRawFileDescriptorData (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: 12
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.
OH_ResourceManager_ReleaseRawFileDescriptor64()
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.
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 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.
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.
你可能感兴趣的鸿蒙文章
harmony 鸿蒙ResourceManager_Configuration
harmony 鸿蒙Font Management Error Codes
harmony 鸿蒙Resource Manager Error Codes
harmony 鸿蒙@ohos.fontManager (Font Management)
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦