• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Rawfile
2
3
4## **Overview**
5
6**Description:**
7
8提供操作rawfile目录和rawfile文件的功能
9
10提供操作rawfile目录和rawfile文件功能
11
12功能包括遍历、打开、搜索、读取和关闭rawfile
13
14**Since:**
15
168
17
18**Version:**
19
201.0
21
22
23## **Summary**
24
25
26### Files
27
28  | File Name | Description |
29| -------- | -------- |
30| [raw_dir.h](raw__dir_8h.md) | 提供rawfile目录相关功能 |
31| [raw_file.h](raw__file_8h.md) | 提供rawfile文件相关功能 |
32
33
34### Classes
35
36  | Classe Name | Description |
37| -------- | -------- |
38| [RawFileDescriptor](_raw_file_descriptor.md) | 提供rawfile文件描述符信息 |
39
40
41### Typedefs
42
43  | Typedef Name | Description |
44| -------- | -------- |
45| RawDir | typedef&nbsp;struct&nbsp;RawDir<br/>提供对rawfile目录的访问 |
46| RawFile | typedef&nbsp;struct&nbsp;RawFile<br/>提供对rawfile的访问功能 |
47| NativeResourceManager | typedef&nbsp;struct&nbsp;NativeResourceManager<br/>代表resource&nbsp;manager |
48
49
50### Functions
51
52  | Function | Description |
53| -------- | -------- |
54| OH_ResourceManager_GetRawFileName&nbsp;(RawDir&nbsp;\*rawDir,&nbsp;int&nbsp;index) | const&nbsp;char&nbsp;\*<br/>通过索引获取rawfile文件名称 |
55| OH_ResourceManager_GetRawFileCount&nbsp;(RawDir&nbsp;\*rawDir) | int<br/>获取RawDir中的rawfile数量 |
56| OH_ResourceManager_CloseRawDir&nbsp;(RawDir&nbsp;\*rawDir) | void<br/>关闭已打开的RawDir并释放所有相关联资源 |
57| OH_ResourceManager_ReadRawFile&nbsp;(const&nbsp;RawFile&nbsp;\*rawFile,&nbsp;void&nbsp;\*buf,&nbsp;size_t&nbsp;length) | int<br/>读取rawfile |
58| OH_ResourceManager_SeekRawFile&nbsp;(const&nbsp;RawFile&nbsp;\*rawFile,&nbsp;long&nbsp;offset,&nbsp;int&nbsp;whence) | int<br/>基于指定的offset,在rawfile文件内搜索读写数据的位置 |
59| OH_ResourceManager_GetRawFileSize&nbsp;(RawFile&nbsp;\*rawFile) | long<br/>获取rawfile长度,单位为int32_t |
60| OH_ResourceManager_CloseRawFile&nbsp;(RawFile&nbsp;\*rawFile) | void<br/>关闭已打开的RawFile&nbsp;以及释放所有相关联资源 |
61| OH_ResourceManager_GetRawFileOffset&nbsp;(const&nbsp;RawFile&nbsp;\*rawFile) | long<br/>获取rawfile当前的offset,单位为int32_t |
62| OH_ResourceManager_GetRawFileDescriptor&nbsp;(const&nbsp;RawFile&nbsp;\*rawFile,&nbsp;RawFileDescriptor&nbsp;&amp;descriptor) | bool<br/>基于offset(单位为int32_t)和文件长度打开rawfile,并获取rawfile文件描述符 |
63| OH_ResourceManager_ReleaseRawFileDescriptor&nbsp;(const&nbsp;RawFileDescriptor&nbsp;&amp;descriptor) | bool<br/>关闭rawfile文件描述符 |
64| OH_ResourceManager_InitNativeResourceManager&nbsp;(napi_env&nbsp;env,&nbsp;napi_value&nbsp;jsResMgr) | NativeResourceManager&nbsp;\*<br/>基于JavaScipt&nbsp;resource&nbsp;manager获取native&nbsp;resource&nbsp;manager |
65| OH_ResourceManager_ReleaseNativeResourceManager&nbsp;(NativeResourceManager&nbsp;\*resMgr) | void<br/>释放native&nbsp;resource&nbsp;manager |
66| OH_ResourceManager_OpenRawDir&nbsp;(const&nbsp;NativeResourceManager&nbsp;\*mgr,&nbsp;const&nbsp;char&nbsp;\*dirName) | RawDir&nbsp;\*<br/>打开rawfile目录 |
67| OH_ResourceManager_OpenRawFile&nbsp;(const&nbsp;NativeResourceManager&nbsp;\*mgr,&nbsp;const&nbsp;char&nbsp;\*fileName) | RawFile&nbsp;\*<br/>打开rawfile文件 |
68
69
70## **Details**
71
72
73## **Typedef**
74
75
76### NativeResourceManager
77
78
79```
80typedef struct NativeResourceManager NativeResourceManager
81```
82
83**Description:**
84
85代表resource manager
86
87此类封装了JavaScript resource manager的native实现 **ResourceManager**指针可以通过调用OH_ResourceManager_InitNativeResourceManager方法获取
88
89
90### RawDir
91
92
93```
94typedef struct RawDir RawDir
95```
96
97**Description:**
98
99提供对rawfile目录的访问
100
101
102### RawFile
103
104
105```
106typedef struct RawFile RawFile
107```
108
109**Description:**
110
111提供对rawfile的访问功能
112
113
114## **Function**
115
116
117### OH_ResourceManager_CloseRawDir()
118
119
120```
121void OH_ResourceManager_CloseRawDir (RawDir * rawDir)
122```
123
124**Description:**
125
126关闭已打开的RawDir并释放所有相关联资源
127
128**Parameters:**
129
130  | Name | Description |
131| -------- | -------- |
132| rawDir | 表示指向RawDir的指针 |
133
134**See also:**
135
136OH_ResourceManager_OpenRawDir
137
138
139### OH_ResourceManager_CloseRawFile()
140
141
142```
143void OH_ResourceManager_CloseRawFile (RawFile * rawFile)
144```
145
146**Description:**
147
148关闭已打开的RawFile 以及释放所有相关联资源
149
150**Parameters:**
151
152  | Name | Description |
153| -------- | -------- |
154| rawFile | 表示指向RawFile的指针 |
155
156**See also:**
157
158OH_ResourceManager_OpenRawFile
159
160
161### OH_ResourceManager_GetRawFileCount()
162
163
164```
165int OH_ResourceManager_GetRawFileCount (RawDir * rawDir)
166```
167
168**Description:**
169
170获取RawDir中的rawfile数量
171
172通过此方法可以获取OH_ResourceManager_GetRawFileName中可用的索引
173
174**Parameters:**
175
176  | Name | Description |
177| -------- | -------- |
178| rawDir | 表示指向RawDir的指针 |
179
180**See also:**
181
182OH_ResourceManager_GetRawFileName
183
184
185### OH_ResourceManager_GetRawFileDescriptor()
186
187
188```
189bool OH_ResourceManager_GetRawFileDescriptor (const RawFile * rawFile, RawFileDescriptor & descriptor )
190```
191
192**Description:**
193
194基于offset(单位为int32_t)和文件长度打开rawfile,并获取rawfile文件描述符
195
196打开的文件描述符被用于读取rawfile
197
198**Parameters:**
199
200  | Name | Description |
201| -------- | -------- |
202| rawFile | 表示指向RawFile的指针 |
203| descriptor | 显示rawfile文件描述符,以及在HAP包中的起始位置和长度 |
204
205**Returns:**
206
207返回true表示打开rawfile文件描述符成功,返回false表示rawfile不允许被访问
208
209
210### OH_ResourceManager_GetRawFileName()
211
212
213```
214const char* OH_ResourceManager_GetRawFileName (RawDir * rawDir, int index )
215```
216
217**Description:**
218
219通过索引获取rawfile文件名称
220
221可以使用此方法遍历rawfile目录
222
223**Parameters:**
224
225  | Name | Description |
226| -------- | -------- |
227| rawDir | 表示指向RawDir的指针 |
228| index | 表示文件在RawDir中的索引位置 |
229
230**Returns:**
231
232通过索引返回文件名称,此返回值可以作为OH_ResourceManager_OpenRawFile的输入参数, 如果遍历完所有文件仍未找到,则返回**NULL**
233
234**See also:**
235
236OH_ResourceManager_OpenRawFile
237
238
239### OH_ResourceManager_GetRawFileOffset()
240
241
242```
243long OH_ResourceManager_GetRawFileOffset (const RawFile * rawFile)
244```
245
246**Description:**
247
248获取rawfile当前的offset,单位为int32_t
249
250rawfile当前的offset
251
252**Parameters:**
253
254  | Name | Description |
255| -------- | -------- |
256| rawFile | 表示指向RawFile的指针 |
257
258**Returns:**
259
260返回rawfile当前的offset
261
262
263### OH_ResourceManager_GetRawFileSize()
264
265
266```
267long OH_ResourceManager_GetRawFileSize (RawFile * rawFile)
268```
269
270**Description:**
271
272获取rawfile长度,单位为int32_t
273
274**Parameters:**
275
276  | Name | Description |
277| -------- | -------- |
278| rawFile | 表示指向RawFile的指针 |
279
280**Returns:**
281
282Returns rawfile整体长度
283
284
285### OH_ResourceManager_InitNativeResourceManager()
286
287
288```
289NativeResourceManager* OH_ResourceManager_InitNativeResourceManager (napi_env env, napi_value jsResMgr )
290```
291
292**Description:**
293
294基于JavaScipt resource manager获取native resource manager
295
296通过获取resource manager来完成rawfile相关功能
297
298**Parameters:**
299
300  | Name | Description |
301| -------- | -------- |
302| env | 表示JavaScipt&nbsp;Native&nbsp;Interface&nbsp;(napi)环境指针 |
303| jsResMgr | 表示JavaScipt&nbsp;resource&nbsp;manager |
304
305**Returns:**
306
307返回NativeResourceManager指针
308
309
310### OH_ResourceManager_OpenRawDir()
311
312
313```
314RawDir* OH_ResourceManager_OpenRawDir (const NativeResourceManager * mgr, const char * dirName )
315```
316
317**Description:**
318
319打开rawfile目录
320
321打开rawfile目录后,可以遍历对应目录下的rawfile文件
322
323**Parameters:**
324
325  | Name | Description |
326| -------- | -------- |
327| mgr | 表示指向NativeResourceManager的指针,此指针是通过调用&nbsp;OH_ResourceManager_InitNativeResourceManager方法获取的 |
328| dirName | 表示要打开的rawfile目录名称,当传递一个空字符串时表示打开rawfile根目录 |
329
330**Returns:**
331
332返回RawDir指针。使用完此指针后,调用OH_ResourceManager_CloseRawDir释放。
333
334**See also:**
335
336OH_ResourceManager_InitNativeResourceManager
337
338OH_ResourceManager_CloseRawDir
339
340
341### OH_ResourceManager_OpenRawFile()
342
343
344```
345RawFile* OH_ResourceManager_OpenRawFile (const NativeResourceManager * mgr, const char * fileName )
346```
347
348**Description:**
349
350打开rawfile文件
351
352当打开rawfile以后,可以读取它的数据
353
354**Parameters:**
355
356  | Name | Description |
357| -------- | -------- |
358| mgr | 表示指向NativeResourceManager的指针,此指针是通过调用&nbsp;OH_ResourceManager_InitNativeResourceManager方法获取的 |
359| fileName | 表示基于rawfile根目录的相对路径下的文件名称 |
360
361**Returns:**
362
363返回RawFile指针。当使用完此指针,调用OH_ResourceManager_CloseRawFile释放。
364
365**See also:**
366
367OH_ResourceManager_InitNativeResourceManager
368
369OH_ResourceManager_CloseRawFile
370
371
372### OH_ResourceManager_ReadRawFile()
373
374
375```
376int OH_ResourceManager_ReadRawFile (const RawFile * rawFile, void * buf, size_t length )
377```
378
379**Description:**
380
381读取rawfile
382
383从当前位置读取**指定长度**的数据
384
385**Parameters:**
386
387  | Name | Description |
388| -------- | -------- |
389| rawFile | 表示指向RawFile的指针 |
390| buf | 用于接收读取数据的缓冲区指针 |
391| length | 读取数据的字节长度 |
392
393**Returns:**
394
395返回读取的字节数,如果读取长度超过文件末尾长度,则返回**0**
396
397
398### OH_ResourceManager_ReleaseNativeResourceManager()
399
400
401```
402void OH_ResourceManager_ReleaseNativeResourceManager (NativeResourceManager * resMgr)
403```
404
405**Description:**
406
407释放native resource manager
408
409**Parameters:**
410
411  | Name | Description |
412| -------- | -------- |
413| resMgr | 表示NativeResourceManager指针 |
414
415
416### OH_ResourceManager_ReleaseRawFileDescriptor()
417
418
419```
420bool OH_ResourceManager_ReleaseRawFileDescriptor (const RawFileDescriptor & descriptor)
421```
422
423**Description:**
424
425关闭rawfile文件描述符
426
427已打开的文件描述符在使用完以后必须释放,防止文件描述符泄露
428
429**Parameters:**
430
431  | Name | Description |
432| -------- | -------- |
433| descriptor | 包含rawfile文件描述符,以及在HAP包中的起始位置和长度 |
434
435**Returns:**
436
437返回true表示关闭文件描述符成功,返回false表示关闭文件描述符失败
438
439
440### OH_ResourceManager_SeekRawFile()
441
442
443```
444int OH_ResourceManager_SeekRawFile (const RawFile * rawFile, long offset, int whence )
445```
446
447**Description:**
448
449基于指定的offset,在rawfile文件内搜索读写数据的位置
450
451**Parameters:**
452
453  | Name | Description |
454| -------- | -------- |
455| rawFile | 表示指向RawFile的指针 |
456| offset | 表示指定的offset |
457| whence | 读写位置,有以下场景:&nbsp;**0**:&nbsp;读写位置为**offset1**:&nbsp;读写位置为当前位置加上**offset2**:&nbsp;读写位置为文件末尾(EOF)加上**offset** |
458
459**Returns:**
460
461如果搜索成功返回新的读写位置,如果发生错误返回 **(long) -1**
462