• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# raw_file.h
2
3## 概述
4
5提供rawfile文件相关功能,功能包括搜索、读取和关闭。
6
7**引用文件:** <rawfile/raw_file.h>
8
9**库:** librawfile.z.so
10
11**系统能力:** SystemCapability.Global.ResourceManager
12
13**起始版本:** 8
14
15**相关模块:** [rawfile](capi-rawfile.md)
16
17## 汇总
18
19### 结构体
20
21| 名称 | typedef关键字 | 描述                                                                                                                                                                      |
22| -- | -- |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
23| [RawFileDescriptor](capi-rawfile-rawfiledescriptor.md) | RawFileDescriptor | 提供rawfile文件描述符信息。RawFileDescriptor是[OH_ResourceManager_GetRawFileDescriptor](#oh_resourcemanager_getrawfiledescriptor)的输出参数,涵盖了rawfile文件的文件描述符以及在HAP包中的起始位置和长度。         |
24| [RawFileDescriptor64](capi-rawfile-rawfiledescriptor64.md) | RawFileDescriptor64 | 提供较大rawfile文件描述符信息。RawFileDescriptor64是[OH_ResourceManager_GetRawFileDescriptor64](#oh_resourcemanager_getrawfiledescriptor64)的输出参数,涵盖了rawfile文件的文件描述符以及在HAP包中的起始位置和长度。 |
25| [RawFile](capi-rawfile-rawfile.md) | RawFile | 提供对rawfile的访问功能。                                                                                                                                                        |
26| [RawFile64](capi-rawfile-rawfile64.md) | RawFile64 | 提供对较大rawfile的访问功能。                                                                                                                                                      |
27
28### 函数
29
30| 名称 | 描述                                                                            |
31| -- |-------------------------------------------------------------------------------|
32| [int OH_ResourceManager_ReadRawFile(const RawFile *rawFile, void *buf, size_t length)](#oh_resourcemanager_readrawfile) | 读取rawfile内容,从当前位置读取指定长度的数据。                                                   |
33| [int OH_ResourceManager_SeekRawFile(const RawFile *rawFile, long offset, int whence)](#oh_resourcemanager_seekrawfile) | 基于指定的偏移量,在rawfile文件内搜索读写数据的位置。                                                |
34| [long OH_ResourceManager_GetRawFileSize(RawFile *rawFile)](#oh_resourcemanager_getrawfilesize) | 获取rawfile长度,单位为long。                                                          |
35| [long OH_ResourceManager_GetRawFileRemainingLength(const RawFile *rawFile)](#oh_resourcemanager_getrawfileremaininglength) | 获取rawfile的剩余长度,单位为long。                                                       |
36| [void OH_ResourceManager_CloseRawFile(RawFile *rawFile)](#oh_resourcemanager_closerawfile) | 关闭已打开的[RawFile](capi-rawfile-rawfile.md) 以及释放所有相关联的资源。                        |
37| [long OH_ResourceManager_GetRawFileOffset(const RawFile *rawFile)](#oh_resourcemanager_getrawfileoffset) | 获取rawfile当前的偏移量,单位为long。rawfile当前的偏移量。                                        |
38| [bool OH_ResourceManager_GetRawFileDescriptor(const RawFile *rawFile, RawFileDescriptor &descriptor)](#oh_resourcemanager_getrawfiledescriptor) | 基于偏移量(单位为long)和文件长度(单位为long)打开rawfile,并获取rawfile文件描述符。打开的文件描述符被用于读取rawfile。   |
39| [bool OH_ResourceManager_ReleaseRawFileDescriptor(const RawFileDescriptor &descriptor)](#oh_resourcemanager_releaserawfiledescriptor) | 关闭rawfile文件描述符。已打开的文件描述符在使用完以后必须释放,防止文件描述符泄露。                                 |
40| [bool OH_ResourceManager_ReleaseRawFileDescriptorData(const RawFileDescriptor *descriptor)](#oh_resourcemanager_releaserawfiledescriptordata) | 关闭rawfile文件描述符。已打开的文件描述符在使用完以后必须释放,防止文件描述符泄露。                                 |
41| [int64_t OH_ResourceManager_ReadRawFile64(const RawFile64 *rawFile, void *buf, int64_t length)](#oh_resourcemanager_readrawfile64) | 读取较大的rawfile文件内容,从当前位置读取指定长度的数据。                                              |
42| [int OH_ResourceManager_SeekRawFile64(const RawFile64 *rawFile, int64_t offset, int whence)](#oh_resourcemanager_seekrawfile64) | 基于指定的偏移量,在较大的rawfile文件内搜索读写数据的位置。                                             |
43| [int64_t OH_ResourceManager_GetRawFileSize64(RawFile64 *rawFile)](#oh_resourcemanager_getrawfilesize64) | 获取较大rawfile文件的长度,单位为int64_t。                                                  |
44| [int64_t OH_ResourceManager_GetRawFileRemainingLength64(const RawFile64 *rawFile)](#oh_resourcemanager_getrawfileremaininglength64) | 获取较大rawfile的剩余长度,单位为int64_t。                                                  |
45| [void OH_ResourceManager_CloseRawFile64(RawFile64 *rawFile)](#oh_resourcemanager_closerawfile64) | 关闭已打开的[RawFile64](capi-rawfile-rawfile64.md) 以及释放所有相关联的资源。                                      |
46| [int64_t OH_ResourceManager_GetRawFileOffset64(const RawFile64 *rawFile)](#oh_resourcemanager_getrawfileoffset64) | 获取较大rawfile文件的偏移量,单位为int64_t。                                                 |
47| [bool OH_ResourceManager_GetRawFileDescriptor64(const RawFile64 *rawFile, RawFileDescriptor64 *descriptor)](#oh_resourcemanager_getrawfiledescriptor64) | 基于偏移量(单位为int64_t)和文件长度(单位为int64_t)打开较大的rawfile,并获取文件描述符。打开的文件描述符被用于读取rawfile。 |
48| [bool OH_ResourceManager_ReleaseRawFileDescriptor64(const RawFileDescriptor64 *descriptor)](#oh_resourcemanager_releaserawfiledescriptor64) | 关闭rawfile文件描述符。已打开的文件描述符在使用完以后必须释放,防止文件描述符泄露。                                 |
49
50## 函数说明
51
52### OH_ResourceManager_ReadRawFile()
53
54```
55int OH_ResourceManager_ReadRawFile(const RawFile *rawFile, void *buf, size_t length)
56```
57
58**描述**
59
60读取rawfile内容,从当前位置读取指定长度的数据。
61
62**起始版本:** 8
63
64
65**参数:**
66
67| 参数项 | 描述 |
68| -- | -- |
69| const [RawFile](capi-rawfile-rawfile.md) *rawFile | 表示指向[RawFile](capi-rawfile-rawfile.md)的指针。 |
70| void *buf | 用于接收读取数据的缓冲区指针。 |
71| size_t length | 读取数据的字节长度。 |
72
73**返回:**
74
75| 类型 | 说明 |
76| -- | -- |
77| int | 返回读取的字节数,如果读取长度超过文件末尾长度或者rawfile为空时,则返回0。 |
78
79### OH_ResourceManager_SeekRawFile()
80
81```
82int OH_ResourceManager_SeekRawFile(const RawFile *rawFile, long offset, int whence)
83```
84
85**描述**
86
87基于指定的偏移量,在rawfile文件内搜索读写数据的位置。
88
89**起始版本:** 8
90
91
92**参数:**
93
94| 参数项 | 描述 |
95| -- | -- |
96| const [RawFile](capi-rawfile-rawfile.md) *rawFile | 表示指向[RawFile](capi-rawfile-rawfile.md)的指针。 |
97| long offset | 表示指定的偏移量。 |
98| int whence | 读写位置,有以下场景: <br> 0: 读写位置为文件起始位置加上offset。 <br> 1: 读写位置为当前位置加上offset。 <br> 2: 读写位置为文件末尾加上offset。 |
99
100**返回:**
101
102| 类型 | 说明 |
103| -- | -- |
104| int | 如果搜索成功返回0,如果发生错误返回-1。 |
105
106### OH_ResourceManager_GetRawFileSize()
107
108```
109long OH_ResourceManager_GetRawFileSize(RawFile *rawFile)
110```
111
112**描述**
113
114获取rawfile长度,单位为long。
115
116**起始版本:** 8
117
118
119**参数:**
120
121| 参数项 | 描述 |
122| -- | -- |
123| [RawFile](capi-rawfile-rawfile.md) *rawFile | 表示指向[RawFile](capi-rawfile-rawfile.md)的指针。 |
124
125**返回:**
126
127| 类型 | 说明 |
128| -- | -- |
129| long | 返回rawfile的整体长度,如果rawfile为空时返回0。 |
130
131### OH_ResourceManager_GetRawFileRemainingLength()
132
133```
134long OH_ResourceManager_GetRawFileRemainingLength(const RawFile *rawFile)
135```
136
137**描述**
138
139获取rawfile的剩余长度,单位为long。
140
141**起始版本:** 11
142
143
144**参数:**
145
146| 参数项 | 描述 |
147| -- | -- |
148| const [RawFile](capi-rawfile-rawfile.md) *rawFile | 表示指向[RawFile](capi-rawfile-rawfile.md)的指针。 |
149
150**返回:**
151
152| 类型 | 说明 |
153| -- | -- |
154| long | 返回rawfile的剩余长度,如果rawfile为空时返回0。 |
155
156### OH_ResourceManager_CloseRawFile()
157
158```
159void OH_ResourceManager_CloseRawFile(RawFile *rawFile)
160```
161
162**描述**
163
164关闭已打开的[RawFile](capi-rawfile-rawfile.md) 以及释放所有相关联的资源。
165
166**起始版本:** 8
167
168
169**参数:**
170
171| 参数项 | 描述 |
172| -- | -- |
173| [RawFile](capi-rawfile-rawfile.md) *rawFile | 表示指向[RawFile](capi-rawfile-rawfile.md)的指针。 |
174
175**参考:**
176
177[OH_ResourceManager_OpenRawFile](capi-raw-file-manager-h.md#oh_resourcemanager_openrawfile)
178
179### OH_ResourceManager_GetRawFileOffset()
180
181```
182long OH_ResourceManager_GetRawFileOffset(const RawFile *rawFile)
183```
184
185**描述**
186
187获取rawfile当前的偏移量,单位为long。rawfile当前的偏移量。
188
189**起始版本:** 8
190
191
192**参数:**
193
194| 参数项 | 描述 |
195| -- | -- |
196| const [RawFile](capi-rawfile-rawfile.md) *rawFile | 表示指向[RawFile](capi-rawfile-rawfile.md)的指针。 |
197
198**返回:**
199
200| 类型 | 说明 |
201| -- | -- |
202| long | 返回rawfile当前的偏移量,如果rawfile为空时返回0。 |
203
204### OH_ResourceManager_GetRawFileDescriptor()
205
206```
207bool OH_ResourceManager_GetRawFileDescriptor(const RawFile *rawFile, RawFileDescriptor &descriptor)
208```
209
210**描述**
211
212基于偏移量(单位为long)和文件长度(单位为long)打开rawfile,并获取rawfile文件描述符。打开的文件描述符被用于读取rawfile。
213
214**起始版本:** 8
215
216
217**参数:**
218
219| 参数项                                               | 描述 |
220|---------------------------------------------------| -- |
221| const [RawFile](capi-rawfile-rawfile.md) *rawFile | 表示指向[RawFile](capi-rawfile-rawfile.md)的指针。 |
222| [RawFileDescriptor](capi-rawfile-rawfiledescriptor.md) &descriptor                 | 显示rawfile文件描述符,以及在HAP包中的起始位置和长度。 |
223
224**返回:**
225
226| 类型 | 说明 |
227| -- | -- |
228| bool | 返回true表示打开rawfile文件描述符成功,返回false表示rawfile不允许被访问。 |
229
230### OH_ResourceManager_ReleaseRawFileDescriptor()
231
232```
233bool OH_ResourceManager_ReleaseRawFileDescriptor(const RawFileDescriptor &descriptor)
234```
235
236**描述**
237
238关闭rawfile文件描述符。已打开的文件描述符在使用完以后必须释放,防止文件描述符泄露。
239
240**起始版本:** 8
241
242
243**参数:**
244
245| 参数项 | 描述 |
246| -- | -- |
247| const [RawFileDescriptor](capi-rawfile-rawfiledescriptor.md) &descriptor | 包含rawfile文件描述符,以及在HAP包中的起始位置和长度。 |
248
249**返回:**
250
251| 类型 | 说明 |
252| -- | -- |
253| bool | 返回true表示关闭文件描述符成功,返回false表示关闭文件描述符失败。 |
254
255### OH_ResourceManager_ReleaseRawFileDescriptorData()
256
257```
258bool OH_ResourceManager_ReleaseRawFileDescriptorData(const RawFileDescriptor *descriptor)
259```
260
261**描述**
262
263关闭rawfile文件描述符。已打开的文件描述符在使用完以后必须释放,防止文件描述符泄露。
264
265**起始版本:** 12
266
267
268**参数:**
269
270| 参数项 | 描述 |
271| -- | -- |
272| [const RawFileDescriptor](capi-rawfile-rawfiledescriptor.md) *descriptor | 包含rawfile文件描述符,以及在HAP包中的起始位置和长度。 |
273
274**返回:**
275
276| 类型 | 说明 |
277| -- | -- |
278| bool | 返回true表示关闭文件描述符成功,返回false表示关闭文件描述符失败。 |
279
280### OH_ResourceManager_ReadRawFile64()
281
282```
283int64_t OH_ResourceManager_ReadRawFile64(const RawFile64 *rawFile, void *buf, int64_t length)
284```
285
286**描述**
287
288读取较大的rawfile文件内容,从当前位置读取指定长度的数据。
289
290**起始版本:** 11
291
292
293**参数:**
294
295| 参数项 | 描述 |
296| -- | -- |
297| const [RawFile64](capi-rawfile-rawfile64.md) *rawFile | 表示指向[RawFile64](capi-rawfile-rawfile64.md)的指针。 |
298| void *buf | 用于接收读取数据的缓冲区指针。 |
299| int64_t length | 读取数据的字节长度。 |
300
301**返回:**
302
303| 类型 | 说明 |
304| -- | -- |
305| int64_t | 返回读取的字节数,如果读取长度超过文件末尾长度或者rawfile为空时,则返回0。 |
306
307### OH_ResourceManager_SeekRawFile64()
308
309```
310int OH_ResourceManager_SeekRawFile64(const RawFile64 *rawFile, int64_t offset, int whence)
311```
312
313**描述**
314
315基于指定的偏移量,在较大的rawfile文件内搜索读写数据的位置。
316
317**起始版本:** 11
318
319
320**参数:**
321
322| 参数项 | 描述 |
323| -- | -- |
324| const [RawFile64](capi-rawfile-rawfile64.md) *rawFile | 表示指向[RawFile64](capi-rawfile-rawfile64.md)的指针。 |
325| int64_t offset | 表示指定的偏移量。 |
326| int whence | 读写位置,有以下场景: <br> 0: 读写位置为文件起始位置加上offset。 <br> 1: 读写位置为当前位置加上offset。 <br> 2: 读写位置为文件末尾加上offset。 |
327
328**返回:**
329
330| 类型 | 说明 |
331| -- | -- |
332| int | 如果搜索成功返回0,如果发生错误返回-1。 |
333
334### OH_ResourceManager_GetRawFileSize64()
335
336```
337int64_t OH_ResourceManager_GetRawFileSize64(RawFile64 *rawFile)
338```
339
340**描述**
341
342获取较大rawfile文件的长度,单位为int64_t。
343
344**起始版本:** 11
345
346
347**参数:**
348
349| 参数项 | 描述 |
350| -- | -- |
351| [RawFile64](capi-rawfile-rawfile64.md) *rawFile | 表示指向[RawFile64](capi-rawfile-rawfile64.md)的指针。 |
352
353**返回:**
354
355| 类型 | 说明 |
356| -- | -- |
357| int64_t | 返回rawfile的整体长度,如果rawfile为空时返回0。 |
358
359### OH_ResourceManager_GetRawFileRemainingLength64()
360
361```
362int64_t OH_ResourceManager_GetRawFileRemainingLength64(const RawFile64 *rawFile)
363```
364
365**描述**
366
367获取较大rawfile的剩余长度,单位为int64_t。
368
369**起始版本:** 11
370
371
372**参数:**
373
374| 参数项 | 描述 |
375| -- | -- |
376| const [RawFile64](capi-rawfile-rawfile64.md) *rawFile | 表示指向[RawFile64](capi-rawfile-rawfile64.md)的指针。 |
377
378**返回:**
379
380| 类型 | 说明 |
381| -- | -- |
382| int64_t | 返回rawfile的剩余长度,如果rawfile为空时返回0。 |
383
384### OH_ResourceManager_CloseRawFile64()
385
386```
387void OH_ResourceManager_CloseRawFile64(RawFile64 *rawFile)
388```
389
390**描述**
391
392关闭已打开的[RawFile64](capi-rawfile-rawfile64.md) 以及释放所有相关联的资源。
393
394**起始版本:** 11
395
396
397**参数:**
398
399| 参数项 | 描述 |
400| -- | -- |
401| [RawFile64](capi-rawfile-rawfile64.md) *rawFile | 表示指向[RawFile64](capi-rawfile-rawfile64.md)的指针。 |
402
403**参考:**
404
405[OH_ResourceManager_OpenRawFile64](capi-raw-file-manager-h.md#oh_resourcemanager_openrawfile64)
406
407### OH_ResourceManager_GetRawFileOffset64()
408
409```
410int64_t OH_ResourceManager_GetRawFileOffset64(const RawFile64 *rawFile)
411```
412
413**描述**
414
415获取较大rawfile文件的偏移量,单位为int64_t。
416
417**起始版本:** 11
418
419
420**参数:**
421
422| 参数项 | 描述 |
423| -- | -- |
424| const [RawFile64](capi-rawfile-rawfile64.md) *rawFile | 表示指向[RawFile64](capi-rawfile-rawfile64.md)的指针。 |
425
426**返回:**
427
428| 类型 | 说明 |
429| -- | -- |
430| int64_t | 返回rawfile当前的偏移量,如果rawfile为空时返回0。 |
431
432### OH_ResourceManager_GetRawFileDescriptor64()
433
434```
435bool OH_ResourceManager_GetRawFileDescriptor64(const RawFile64 *rawFile, RawFileDescriptor64 *descriptor)
436```
437
438**描述**
439
440基于偏移量(单位为int64_t)和文件长度(单位为int64_t)打开较大的rawfile,并获取文件描述符。打开的文件描述符被用于读取rawfile。
441
442**起始版本:** 11
443
444
445**参数:**
446
447| 参数项 | 描述 |
448| -- | -- |
449| const [RawFile64](capi-rawfile-rawfile64.md) *rawFile | 表示指向[RawFile64](capi-rawfile-rawfile64.md)的指针。 |
450| [RawFileDescriptor64](capi-rawfile-rawfiledescriptor64.md) *descriptor | 显示rawfile文件描述符,以及在HAP包中的起始位置和长度。 |
451
452**返回:**
453
454| 类型 | 说明 |
455| -- | -- |
456| bool | 返回true表示打开rawfile文件描述符成功,返回false表示rawfile不允许被访问。 |
457
458### OH_ResourceManager_ReleaseRawFileDescriptor64()
459
460```
461bool OH_ResourceManager_ReleaseRawFileDescriptor64(const RawFileDescriptor64 *descriptor)
462```
463
464**描述**
465
466关闭rawfile文件描述符。已打开的文件描述符在使用完以后必须释放,防止文件描述符泄露。
467
468**起始版本:** 11
469
470
471**参数:**
472
473| 参数项 | 描述 |
474| -- | -- |
475| [const RawFileDescriptor64](capi-rawfile-rawfiledescriptor64.md) *descriptor | 包含rawfile文件描述符,以及在HAP包中的起始位置和长度。 |
476
477**返回:**
478
479| 类型 | 说明 |
480| -- | -- |
481| bool | 返回true表示关闭文件描述符成功,返回false表示关闭文件描述符失败。 |
482
483
484