• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Rawfile
2
3
4Provides 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.
5
6**Since**
7
8
98
10
11
12## Summary
13
14
15### Files
16
17| Name                                    | Description                |
18| ---------------------------------------- | ------------------ |
19| [raw_dir.h](raw__dir_8h.md)              | Provides functions related to the **rawfile** directory.<br>File to include: \<rawfile/raw_dir.h>  |
20| [raw_file.h](raw__file_8h.md)            | Provides functions related to the files in the **rawfile** directory.<br>File to include: \<rawfile/raw_file.h> |
21| [raw_file_manager.h](raw__file__manager_8h.md) | Provides file management functions for the **rawfile** directory.<br>File to import: \<rawfile/raw_file_manager.h>|
22
23
24### Structs
25
26| Name                                   | Description               |
27| ---------------------------------------- | ----------------- |
28| [RawFileDescriptor](_raw_file_descriptor.md) | Defines the file descriptor (FD) information of a file in the **rawfile** directory. |
29
30
31### Types
32
33| Name                                  | Description                 |
34| ---------------------------------------- | ------------------- |
35| [RawDir](#rawdir)                        | Provides access to the **rawfile** directory.   |
36| [RawFile](#rawfile)                      | Provides access to the files in **rawfile**.   |
37| [NativeResourceManager](#nativeresourcemanager) | Represents the resource manager.|
38
39
40### Functions
41
42| Name                                                         | Description                                                  |
43| ------------------------------------------------------------ | ------------------------------------------------------------ |
44| [OH_ResourceManager_GetRawFileName](#oh_resourcemanager_getrawfilename) ([RawDir](#rawdir) \*rawDir, int index) | Obtains the name of a file in **rawfile** based on the index. |
45| [OH_ResourceManager_GetRawFileCount](#oh_resourcemanager_getrawfilecount) ([RawDir](#rawdir) \*rawDir) | Obtains the number of files in a [RawDir](#rawdir).          |
46| [OH_ResourceManager_CloseRawDir](#oh_resourcemanager_closerawdir) ([RawDir](#rawdir) \*rawDir) | Closes a [RawDir](#rawdir) and releases all associated resources. |
47| [OH_ResourceManager_ReadRawFile](#oh_resourcemanager_readrawfile) (const [RawFile](#rawfile) \*rawFile, void \*buf, size_t length) | Reads data from a file in **rawfile**.                       |
48| [OH_ResourceManager_SeekRawFile](#oh_resourcemanager_seekrawfile) (const [RawFile](#rawfile) \*rawFile, long offset, int whence) | Seeks for the data read/write position in a file in **rawfile** based on the specified offset. |
49| [OH_ResourceManager_GetRawFileSize](#oh_resourcemanager_getrawfilesize) ([RawFile](#rawfile) \*rawFile) | Obtains the size of a file in **rawfile**.                   |
50| [OH_ResourceManager_CloseRawFile](#oh_resourcemanager_closerawfile) ([RawFile](#rawfile) \*rawFile) | Closes a [RawFile](#rawfile) and releases all associated resources. |
51| [OH_ResourceManager_GetRawFileOffset](#oh_resourcemanager_getrawfileoffset) (const [RawFile](#rawfile) \*rawFile) | Obtains the current offset of a file in **rawfile**.         |
52| [OH_ResourceManager_GetRawFileDescriptor](#oh_resourcemanager_getrawfiledescriptor) (const [RawFile](#rawfile) \*rawFile, [RawFileDescriptor](_raw_file_descriptor.md) &amp;descriptor) | Opens a file in **rawfile** based on the offset and file length and obtains the FD. |
53| [OH_ResourceManager_ReleaseRawFileDescriptor](#oh_resourcemanager_releaserawfiledescriptor) (const [RawFileDescriptor](_raw_file_descriptor.md) &amp;descriptor) | Releases an FD.                                               |
54| [OH_ResourceManager_InitNativeResourceManager](#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**. |
55| [OH_ResourceManager_ReleaseNativeResourceManager](#oh_resourcemanager_releasenativeresourcemanager) ([NativeResourceManager](#nativeresourcemanager) \*resMgr) | Releases a Native resource manager instance.                 |
56| [OH_ResourceManager_OpenRawDir](#oh_resourcemanager_openrawdir) (const [NativeResourceManager](#nativeresourcemanager) \*mgr, const char \*dirName) | Opens a directory in the **rawfile** directory.              |
57| [OH_ResourceManager_OpenRawFile](#oh_resourcemanager_openrawfile) (const [NativeResourceManager](#nativeresourcemanager) \*mgr, const char \*fileName) | Opens a file in the **rawfile** directory.                   |
58
59
60## Description
61
62
63### Type Description
64
65
66#### NativeResourceManager
67
68
69```
70typedef struct NativeResourceManager NativeResourceManager
71```
72
73**Description**
74
75Represents the resource manager.
76
77This class encapsulates the native implementation of the JavaScript resource manager. The **ResourceManager** pointer can be obtained by using [OH_ResourceManager_InitNativeResourceManager](#oh_resourcemanager_initnativeresourcemanager).
78
79**Since**
80
818
82
83
84#### RawDir
85
86
87```
88typedef struct RawDir RawDir
89```
90
91**Description**
92
93Provides access to the **rawfile** directory.
94
95**Since**
96
978
98
99
100#### RawFile
101
102
103```
104typedef struct RawFile RawFile
105```
106
107**Description**
108
109Provides access to the files in **rawfile**.
110
111**Since**
112
1138
114
115
116### Function Description
117
118
119#### OH_ResourceManager_CloseRawDir()
120
121
122```
123void OH_ResourceManager_CloseRawDir (RawDir * rawDir)
124```
125
126**Description**
127
128Closes a [RawDir](#rawdir) opened and releases all associated resources.
129
130**Parameters**
131
132| Name   | Description                       |
133| ------ | ------------------------- |
134| rawDir | Pointer to the [RawDir](#rawdir) to close.|
135
136**See**
137
138[OH_ResourceManager_OpenRawDir](#oh_resourcemanager_openrawdir)
139
140**Since**
141
1428
143
144
145#### OH_ResourceManager_CloseRawFile()
146
147
148```
149void OH_ResourceManager_CloseRawFile (RawFile * rawFile)
150```
151
152**Description**
153
154Closes a [RawFile](#rawfile) and releases all associated resources.
155
156**Parameters**
157
158| Name    | Description                         |
159| ------- | --------------------------- |
160| rawFile | Pointer to the [RawFile](#rawfile) to close.|
161
162**See**
163
164[OH_ResourceManager_OpenRawFile](#oh_resourcemanager_openrawfile)
165
166**Since**
167
1688
169
170
171#### OH_ResourceManager_GetRawFileCount()
172
173
174```
175int OH_ResourceManager_GetRawFileCount (RawDir * rawDir)
176```
177
178**Description**
179
180Obtains the number of files in a [RawDir](#rawdir).
181
182You can use this function to obtain available indexes in [OH_ResourceManager_GetRawFileName](#oh_resourcemanager_getrawfilename).
183
184**Parameters**
185
186| Name   | Description                       |
187| ------ | ------------------------- |
188| rawDir | Pointer to the target [RawDir](#rawdir).|
189
190**See**
191
192[OH_ResourceManager_GetRawFileName](#oh_resourcemanager_getrawfilename)
193
194**Since**
195
1968
197
198
199#### OH_ResourceManager_GetRawFileDescriptor()
200
201
202```
203bool OH_ResourceManager_GetRawFileDescriptor (const RawFile * rawFile, RawFileDescriptor & descriptor )
204```
205
206**Description**
207
208Opens a file in the **rawfile** directory based on the offset and file length and obtains the FD.
209
210The FD obtained can be used to read the file.
211
212**Parameters**
213
214| Name       | Description                                                |
215| ---------- | ---------------------------------------------------- |
216| rawFile    | Pointer to the [RawFile](#rawfile).                 |
217| descriptor | File descriptor of the file, start position of the file in the hAP, and length of the file.|
218
219**Returns**
220
221Returns <b>true</b> if the file is opened; returns <b>false</b> if the access to the file is rejected.
222
223**Since**
224
2258
226
227
228#### OH_ResourceManager_GetRawFileName()
229
230
231```
232const char* OH_ResourceManager_GetRawFileName (RawDir * rawDir, int index )
233```
234
235**Description**
236
237Obtains the name of a file in **rawfile** based on the index.
238
239You can use this function to traverse the **rawfile** directory.
240
241**Parameters**
242
243| Name   | Description                           |
244| ------ | ----------------------------- |
245| rawDir | Pointer to the [RawDir](#rawdir).    |
246| index  | Index of the file in the [RawDir](#rawdir).|
247
248**Returns**
249
250Returns 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](#oh_resourcemanager_openrawfile).
251
252**See**
253
254[OH_ResourceManager_OpenRawFile](#oh_resourcemanager_openrawfile)
255
256**Since**
257
2588
259
260
261#### OH_ResourceManager_GetRawFileOffset()
262
263
264```
265long OH_ResourceManager_GetRawFileOffset (const RawFile * rawFile)
266```
267
268**Description**
269
270Obtains the current offset of a file in **rawfile**.
271
272The offset indicates the position of the file in the HAP.
273
274**Parameters**
275
276| Name    | Description                         |
277| ------- | --------------------------- |
278| rawFile | Pointer to the target [RawFile](#rawfile).|
279
280**Returns**
281
282Returns the file offset obtained.
283
284**Since**
285
2868
287
288
289#### OH_ResourceManager_GetRawFileSize()
290
291
292```
293long OH_ResourceManager_GetRawFileSize (RawFile * rawFile)
294```
295
296**Description**
297
298Obtains the size of a file in **rawfile**.
299
300**Parameters**
301
302| Name    | Description                         |
303| ------- | --------------------------- |
304| rawFile | Pointer to the target [RawFile](#rawfile).|
305
306**Returns**
307
308Returns the file size obtained.
309
310**Since**
311
3128
313
314
315#### OH_ResourceManager_InitNativeResourceManager()
316
317
318```
319NativeResourceManager* OH_ResourceManager_InitNativeResourceManager (napi_env env, napi_value jsResMgr )
320```
321
322**Description**
323
324Initializes a Native resource manager using the JavaScript resource manager.
325
326You can use the resource manager obtained to implement **rawfile** operations.
327
328**Parameters**
329
330| Name     | Description                                      |
331| -------- | ---------------------------------------- |
332| env      | Pointer to the JavaScript Native API (napi) environment.|
333| jsResMgr | JavaScript resource manager.          |
334
335**Returns**
336
337Returns the pointer to the [NativeResourceManager](#nativeresourcemanager) obtained.
338
339**Since**
340
3418
342
343
344#### OH_ResourceManager_OpenRawDir()
345
346
347```
348RawDir* OH_ResourceManager_OpenRawDir (const NativeResourceManager * mgr, const char * dirName )
349```
350
351**Description**
352
353Opens a directory in **rawfile**.
354
355After opening the directory, you can traverse all files in it.
356
357**Parameters**
358
359| Name    | Description                                      |
360| ------- | ---------------------------------------- |
361| mgr     | Pointer to the [NativeResourceManager](#nativeresourcemanager), which is obtained by using [OH_ResourceManager_InitNativeResourceManager](#oh_resourcemanager_initnativeresourcemanager).|
362| dirName | Pointer to the name of the directory to open. If this field is left empty, the root directory will be opened.|
363
364**Returns**
365
366Returns the pointer to the [RawDir](#rawdir) opened. You can use [OH_ResourceManager_CloseRawDir](#oh_resourcemanager_closerawdir) to close the directory and release resources.
367
368**See**
369
370[OH_ResourceManager_InitNativeResourceManager](#oh_resourcemanager_initnativeresourcemanager)
371
372[OH_ResourceManager_CloseRawDir](#oh_resourcemanager_closerawdir)
373
374**Since**
375
3768
377
378
379#### OH_ResourceManager_OpenRawFile()
380
381
382```
383RawFile* OH_ResourceManager_OpenRawFile (const NativeResourceManager * mgr, const char * fileName )
384```
385
386**Description**
387
388Opens a file in **rawfile**.
389
390After the file is opened, you can read data in it.
391
392**Parameters**
393
394| Name     | Description                                      |
395| -------- | ---------------------------------------- |
396| mgr      | Pointer to the [NativeResourceManager](#nativeresourcemanager), which is obtained by using [OH_ResourceManager_InitNativeResourceManager](#oh_resourcemanager_initnativeresourcemanager).|
397| fileName | Pointer to the name of the file in the relative path of the **rawfile** root directory.              |
398
399**Returns**
400
401Returns the pointer to the [RawFile](#rawfile) opened. You can use [OH_ResourceManager_CloseRawFile](#oh_resourcemanager_closerawfile) to close the file and release resources.
402
403**See**
404
405[OH_ResourceManager_InitNativeResourceManager](#oh_resourcemanager_initnativeresourcemanager)
406
407[OH_ResourceManager_CloseRawFile](#oh_resourcemanager_closerawfile)
408
409**Since**
410
4118
412
413
414#### OH_ResourceManager_ReadRawFile()
415
416
417```
418int OH_ResourceManager_ReadRawFile (const RawFile * rawFile, void * buf, size_t length )
419```
420
421**Description**
422
423Reads a file in **rawfile**.
424
425You can use this function to read data of the specified length from the current position.
426
427**Parameters**
428
429| Name    | Description                         |
430| ------- | --------------------------- |
431| rawFile | Pointer to the [RawFile](#rawfile) to read.|
432| buf     | Pointer to the buffer for receiving the read data.            |
433| length  | Length of the data to read.                 |
434
435**Returns**
436
437Returns the number of bytes read. If the read length exceeds the length of the file end, **0** will be returned.
438
439**Since**
440
4418
442
443
444#### OH_ResourceManager_ReleaseNativeResourceManager()
445
446
447```
448void OH_ResourceManager_ReleaseNativeResourceManager (NativeResourceManager * resMgr)
449```
450
451**Description**
452
453Releases a Native resource manager instance.
454
455**Parameters**
456
457| Name   | Description                                      |
458| ------ | ---------------------------------------- |
459| resMgr | Pointer to the [NativeResourceManager](#nativeresourcemanager) instance to release.|
460
461**Since**
462
4638
464
465
466#### OH_ResourceManager_ReleaseRawFileDescriptor()
467
468
469```
470bool OH_ResourceManager_ReleaseRawFileDescriptor (const RawFileDescriptor & descriptor)
471```
472
473**Description**
474
475Releases the FD of a file in **rawfile**.
476
477To prevent FD leakage, you are advised to release an FD immediately after use.
478
479**Parameters**
480
481| Name       | Description                                                  |
482| ---------- | ------------------------------------------------------------ |
483| descriptor | File descriptor to close. It contains the FD, start position in the HAP, and file length. |
484
485**Returns**
486
487Returns <b>true</b> if the FD is released; returns <b>false</b> otherwise.
488
489**Since**
490
4918
492
493
494#### OH_ResourceManager_SeekRawFile()
495
496
497```
498int OH_ResourceManager_SeekRawFile (const RawFile * rawFile, long offset, int whence )
499```
500
501**Description**
502
503Seeks for the data read/write position in a file in **rawfile** based on the specified offset.
504
505**Parameters**
506
507| Name    | Description                                      |
508| ------- | ---------------------------------------- |
509| rawFile | Pointer to the target [RawFile](#rawfile).             |
510| offset  | Offset.                            |
511| whence  | Read/Write position. The options are as follows:<br>**0**: The read/write position is the offset.<br>**1**: The read/write position is the current position plus the offset.<br>**2**: The read/write position is the end of the file (EOF) plus the offset.|
512
513**Returns**
514
515Returns the read/write position if the operation is successful; returns **(long) -1** otherwise.
516
517**Since**
518
5198
520