• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Rawfile
2
3
4## Overview
5
6Provides the function of operating rawfile directories and rawfiles.
7
8These functions include traversing, opening, searching, reading, and closing rawfiles.
9
10**Since:**
118
12
13
14## Summary
15
16
17### Files
18
19| Name | Description |
20| -------- | -------- |
21| [raw_dir.h](raw__dir_8h.md) | Provides functions for operating rawfile directories. <br>File to Include: <rawfile/raw_dir.h> |
22| [raw_file.h](raw__file_8h.md) | Provides functions for operating rawfiles.  <br>File to Include: <rawfile/raw_file.h>|
23| [raw_file_manager.h](raw__file__manager_8h.md) | Provides functions for managing rawfile resources.  <br>File to Include: <rawfile/raw_file_manager.h>|
24
25
26### Structs
27
28| Name | Description |
29| -------- | -------- |
30| [RawFileDescriptor](_raw_file_descriptor.md) | Provides rawfile descriptor information.  |
31
32
33### Types
34
35| Name | Description |
36| -------- | -------- |
37| [RawDir](#rawdir) | Provides the function of accessing rawfile directories.  |
38| [RawFile](#rawfile) | Provides the function of accessing rawfiles.  |
39| [NativeResourceManager](#nativeresourcemanager) | Implements the resource manager.  |
40
41
42### Functions
43
44| Name | Description |
45| -------- | -------- |
46| [OH_ResourceManager_GetRawFileName](#oh_resourcemanager_getrawfilename) ([RawDir](#rawdir) \*rawDir, int index) | Obtains the rawfile name via an index.  |
47| [OH_ResourceManager_GetRawFileCount](#oh_resourcemanager_getrawfilecount) ([RawDir](#rawdir) \*rawDir) |Obtains the number of rawfiles in [RawDir](#rawdir).  |
48| [OH_ResourceManager_CloseRawDir](#oh_resourcemanager_closerawdir) ([RawDir](#rawdir) \*rawDir) | Closes an opened [RawDir](#rawdir) and releases all associated resources.  |
49| [OH_ResourceManager_ReadRawFile](#oh_resourcemanager_readrawfile) (const [RawFile](#rawfile) \*rawFile, void \*buf, size_t length) |Reads a rawfile.  |
50| [OH_ResourceManager_SeekRawFile](#oh_resourcemanager_seekrawfile) (const [RawFile](#rawfile) \*rawFile, long offset, int whence) |Seeks for the data read/write position in the rawfile based on the specified offset.  |
51| [OH_ResourceManager_GetRawFileSize](#oh_resourcemanager_getrawfilesize) ([RawFile](#rawfile) \*rawFile) | Obtains the length of a rawfile in int32_t.  |
52| [OH_ResourceManager_CloseRawFile](#oh_resourcemanager_closerawfile) ([RawFile](#rawfile) \*rawFile) | Closes an opened [RawFile](#rawfile) and releases all associated resources.  |
53| [OH_ResourceManager_GetRawFileOffset](#oh_resourcemanager_getrawfileoffset) (const [RawFile](#rawfile) \*rawFile) | Obtains the current offset of the rawfile in int32_t.  |
54| [OH_ResourceManager_GetRawFileDescriptor](#oh_resourcemanager_getrawfiledescriptor) (const [RawFile](#rawfile) \*rawFile, [RawFileDescriptor](_raw_file_descriptor.md) &amp;descriptor) | Opens a rawfile descriptor.  |
55| [OH_ResourceManager_ReleaseRawFileDescriptor](#oh_resourcemanager_releaserawfiledescriptor) (const [RawFileDescriptor](_raw_file_descriptor.md) &amp;descriptor) | Closes a rawfile descriptor.  |
56| [OH_ResourceManager_InitNativeResourceManager](#oh_resourcemanager_initnativeresourcemanager) (napi_env env, napi_value jsResMgr) | Obtains the native resource manager based on JavaScipt resource manager.  |
57| [OH_ResourceManager_ReleaseNativeResourceManager](#oh_resourcemanager_releasenativeresourcemanager) ([NativeResourceManager](#nativeresourcemanager) \*resMgr) | Releases a native resource manager.  |
58| [OH_ResourceManager_OpenRawDir](#oh_resourcemanager_openrawdir) (const [NativeResourceManager](#nativeresourcemanager) \*mgr, const char \*dirName) | Opens a rawfile directory.  |
59| [OH_ResourceManager_OpenRawFile](#oh_resourcemanager_openrawfile) (const [NativeResourceManager](#nativeresourcemanager) \*mgr, const char \*fileName) | Opens a rawfile.  |
60
61
62## Type Description
63
64
65### NativeResourceManager
66
67
68```
69typedef struct NativeResourceManagerNativeResourceManager
70```
71**Description**<br>
72Implements the resource manager.
73
74This class encapsulates the native implementation of the JavaScript resource manager. You can obtain the pointer to **ResourceManager** by calling [OH_ResourceManager_InitNativeResourceManager](#oh_resourcemanager_initnativeresourcemanager).
75
76
77### RawDir
78
79
80```
81typedef struct RawDirRawDir
82```
83**Description**<br>
84Provides the function of accessing rawfile directories.
85
86
87### RawFile
88
89
90```
91typedef struct RawFileRawFile
92```
93**Description**<br>
94Provides the function of accessing rawfiles.
95
96
97## Function Description
98
99
100### OH_ResourceManager_CloseRawDir()
101
102
103```
104void OH_ResourceManager_CloseRawDir (RawDir * rawDir)
105```
106**Description**<br>
107Closes an opened [RawDir](#rawdir) and releases all associated resources.
108
109 **Parameters**
110
111| Name | Description |
112| -------- | -------- |
113| rawDir | Indicates the pointer to [RawDir](#rawdir).  |
114
115 **See**
116
117[OH_ResourceManager_OpenRawDir](#oh_resourcemanager_openrawdir)
118
119
120### OH_ResourceManager_CloseRawFile()
121
122
123```
124void OH_ResourceManager_CloseRawFile (RawFile * rawFile)
125```
126**Description**<br>
127Closes an opened [RawFile](#rawfile) and releases all associated resources.
128
129 **Parameters**
130
131| Name | Description |
132| -------- | -------- |
133| rawFile | Indicates the pointer to [RawFile](#rawfile).  |
134
135 **See**
136
137[OH_ResourceManager_OpenRawFile](#oh_resourcemanager_openrawfile)
138
139
140### OH_ResourceManager_GetRawFileCount()
141
142
143```
144int OH_ResourceManager_GetRawFileCount (RawDir * rawDir)
145```
146**Description**<br>
147Obtains the number of rawfiles in [RawDir](#rawdir).
148
149You can use this function to obtain available indexes in [OH_ResourceManager_GetRawFileName](#oh_resourcemanager_getrawfilename).
150
151 **Parameters**
152
153| Name | Description |
154| -------- | -------- |
155| rawDir | Indicates the pointer to [RawDir](#rawdir).  |
156
157 **See**
158
159[OH_ResourceManager_GetRawFileName](#oh_resourcemanager_getrawfilename)
160
161
162### OH_ResourceManager_GetRawFileDescriptor()
163
164
165```
166bool OH_ResourceManager_GetRawFileDescriptor (const RawFile * rawFile, RawFileDescriptor & descriptor )
167```
168**Description**<br>
169Opens a rawfile descriptor.
170
171After the descriptor is opened, you can use it to read the rawfile based on the offset (in int32_t) and file length.
172
173 **Parameters**
174
175| Name | Description |
176| -------- | -------- |
177| rawFile | Indicates the pointer to [RawFile](#rawfile).  |
178| descriptor | Indicates the rawfile descriptor, and the start position and length of the rawfile file in the HAP package.  |
179
180**Returns**
181
182Returns **true** if the rawfile descriptor is opened successfully; returns **false** if the rawfile cannot be accessed.
183
184
185### OH_ResourceManager_GetRawFileName()
186
187
188```
189const char* OH_ResourceManager_GetRawFileName (RawDir * rawDir, int index )
190```
191**Description**<br>
192Obtains the rawfile name via an index.
193
194You can use this function to traverse a rawfile directory.
195
196 **Parameters**
197
198| Name | Description |
199| -------- | -------- |
200| rawDir | Indicates the pointer to [RawDir](#rawdir).  |
201| index | Indicates the index of the file in [RawDir](#rawdir).  |
202
203**Returns**
204
205Returns the rawfile name via an index. The return value can be used as the input parameter of [OH_ResourceManager_OpenRawFile](#oh_resourcemanager_openrawfile). If no rawfile is found after all rawfiles are traversed, **NULL** will be returned.
206
207 **See**
208
209[OH_ResourceManager_OpenRawFile](#oh_resourcemanager_openrawfile)
210
211
212### OH_ResourceManager_GetRawFileOffset()
213
214
215```
216long OH_ResourceManager_GetRawFileOffset (const RawFile * rawFile)
217```
218**Description**<br>
219Obtains the current offset of the rawfile in int32_t.
220
221 **Parameters**
222
223| Name | Description |
224| -------- | -------- |
225| rawFile | Indicates the pointer to [RawFile](#rawfile).  |
226
227**Returns**
228
229Returns the current offset of the rawfile.
230
231
232### OH_ResourceManager_GetRawFileSize()
233
234
235```
236long OH_ResourceManager_GetRawFileSize (RawFile * rawFile)
237```
238**Description**<br>
239Obtains the length of a rawfile in int32_t.
240
241 **Parameters**
242
243| Name | Description |
244| -------- | -------- |
245| rawFile | Indicates the pointer to [RawFile](#rawfile).  |
246
247**Returns**
248
249Returns the total length of the rawfile.
250
251
252### OH_ResourceManager_InitNativeResourceManager()
253
254
255```
256NativeResourceManager* OH_ResourceManager_InitNativeResourceManager (napi_env env, napi_value jsResMgr )
257```
258**Description**<br>
259Obtains the native resource manager based on JavaScipt resource manager.
260
261After obtaining a resource manager, you can use it complete various rawfile operations.
262
263 **Parameters**
264
265| Name | Description |
266| -------- | -------- |
267| env | Indicates the pointer to the JavaScipt Native Interface (napi) environment.  |
268| jsResMgr | Indicates the JavaScipt resource manager.  |
269
270**Returns**
271
272Returns the pointer to [NativeResourceManager](#nativeresourcemanager).
273
274
275### OH_ResourceManager_OpenRawDir()
276
277
278```
279RawDir* OH_ResourceManager_OpenRawDir (const NativeResourceManager * mgr, const char * dirName )
280```
281**Description**<br>
282Opens a rawfile directory.
283
284After opening a rawfile directory, you can traverse all the rawfile files in it.
285
286 **Parameters**
287
288| Name | Description |
289| -------- | -------- |
290| mgr | Indicates the pointer to [NativeResourceManager](#nativeresourcemanager). You can obtain this pointer by calling [OH_ResourceManager_InitNativeResourceManager](#oh_resourcemanager_initnativeresourcemanager).  |
291| dirName | Indicates the name of the rawfile directory to open. If this field is left empty, the root directory of rawfile will be opened.  |
292
293**Returns**
294
295Returns the pointer to [RawDir](#rawdir). If this pointer is no longer needed after use, call [OH_ResourceManager_CloseRawDir](#oh_resourcemanager_closerawdir) to release it.
296
297 **See**
298
299[OH_ResourceManager_InitNativeResourceManager](#oh_resourcemanager_initnativeresourcemanager)
300
301[OH_ResourceManager_CloseRawDir](#oh_resourcemanager_closerawdir)
302
303
304### OH_ResourceManager_OpenRawFile()
305
306
307```
308RawFile* OH_ResourceManager_OpenRawFile (const NativeResourceManager * mgr, const char * fileName )
309```
310**Description**<br>
311Opens a rawfile.
312
313After a rawfile is opened, you can read the data in it.
314
315 **Parameters**
316
317| Name | Description |
318| -------- | -------- |
319| mgr | Indicates the pointer to [NativeResourceManager](#nativeresourcemanager). You can obtain this pointer by calling [OH_ResourceManager_InitNativeResourceManager](#oh_resourcemanager_initnativeresourcemanager).  |
320| fileName | Indicates the file name in the relative path of the rawfile root directory.  |
321
322**Returns**
323
324Returns the pointer to [RawFile](#rawfile). If this pointer is no longer needed after use, call [OH_ResourceManager_CloseRawFile](#oh_resourcemanager_closerawfile) to release it.
325
326 **See**
327
328[OH_ResourceManager_InitNativeResourceManager](#oh_resourcemanager_initnativeresourcemanager)
329
330[OH_ResourceManager_CloseRawFile](#oh_resourcemanager_closerawfile)
331
332
333### OH_ResourceManager_ReadRawFile()
334
335
336```
337int OH_ResourceManager_ReadRawFile (const RawFile * rawFile, void * buf, size_t length )
338```
339**Description**<br>
340Reads a rawfile.
341
342You can use this function to read data of the specified length from the current position.
343
344 **Parameters**
345
346| Name | Description |
347| -------- | -------- |
348| rawFile | Indicates the pointer to [RawFile](#rawfile).  |
349| buf | Indicates the pointer to the buffer for storing the read data.  |
350| length | Indicates the length of the read data, in bytes.  |
351
352**Returns**
353
354Returns the length of the read data in bytes. If the length is beyond the end of the rawfile, **0** will be returned.
355
356
357### OH_ResourceManager_ReleaseNativeResourceManager()
358
359
360```
361void OH_ResourceManager_ReleaseNativeResourceManager (NativeResourceManager * resMgr)
362```
363**Description**<br>
364Releases a native resource manager.
365
366 **Parameters**
367
368| Name | Description |
369| -------- | -------- |
370| resMgr | Indicates the pointer to [NativeResourceManager](#nativeresourcemanager).  |
371
372
373### OH_ResourceManager_ReleaseRawFileDescriptor()
374
375
376```
377bool OH_ResourceManager_ReleaseRawFileDescriptor (const RawFileDescriptor & descriptor)
378```
379**Description**<br>
380Closes a rawfile descriptor.
381
382To prevent file descriptor leakage, you are advised to release a rawfile descriptor after use.
383
384 **Parameters**
385
386| Name | Description |
387| -------- | -------- |
388| descriptor | Indicates the rawfile descriptor, and the start position and length of the rawfile file in the HAP package.  |
389
390**Returns**
391
392Returns **true** if the rawfile descriptor is closed successfully; returns **false** otherwise.
393
394
395### OH_ResourceManager_SeekRawFile()
396
397
398```
399int OH_ResourceManager_SeekRawFile (const RawFile * rawFile, long offset, int whence )
400```
401**Description**<br>
402Seeks for the data read/write position in the rawfile based on the specified offset.
403
404 **Parameters**
405
406| Name | Description |
407| -------- | -------- |
408| rawFile | Indicates the pointer to [RawFile](#rawfile).  |
409| offset | Indicates the specified offset.  |
410| whence | Indicates the data read/write position. The options are as follows:<br/>**0**: The read/write position is **offset**.<br/>**1**: The read/write position is the current position plus **offset**.<br/>**2**: The read/write position is the end of the file (EOF) plus **offset**. |
411
412**Returns**
413
414Returns the new data read/write position if the operation is successful; returns **(long) -1** otherwise.
415