• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License"),
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import { AsyncCallback, Callback } from "./basic";
17import Want from './@ohos.app.ability.Want';
18import Context from './application/Context';
19import { Filter } from './@ohos.fileio';
20
21/**
22 * This module provides the capability to access user public files.
23 *
24 * @since 9
25 * @syscap SystemCapability.FileManagement.UserFileService
26 */
27declare namespace fileAccess {
28    /**
29     * Query the want information of HAP configured with fileaccess.
30     * @since 9
31     * @syscap SystemCapability.FileManagement.UserFileService
32     * @StageModelOnly
33     * @systemapi
34     * @permission ohos.permission.FILE_ACCESS_MANAGER and ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
35     * @returns {(void | Promise<Array<Want>>)} Returns the wants.
36     * @throws { BusinessError } 13900001 - Operation not permitted
37     * @throws { BusinessError } 13900002 - No such file or directory
38     * @throws { BusinessError } 13900004 - Interrupted system call
39     * @throws { BusinessError } 13900006 - No such device or address
40     * @throws { BusinessError } 13900008 - Bad file descriptor
41     * @throws { BusinessError } 13900011 - Out of memory
42     * @throws { BusinessError } 13900012 - Permission denied
43     * @throws { BusinessError } 13900013 - Bad address
44     * @throws { BusinessError } 13900014 - Device or resource busy
45     * @throws { BusinessError } 13900015 - File exists
46     * @throws { BusinessError } 13900017 - No such device
47     * @throws { BusinessError } 13900018 - Not a directory
48     * @throws { BusinessError } 13900019 - Is a directory
49     * @throws { BusinessError } 13900020 - Invalid argument
50     * @throws { BusinessError } 13900022 - Too many open files
51     * @throws { BusinessError } 13900023 - Text file busy
52     * @throws { BusinessError } 13900024 - File too large
53     * @throws { BusinessError } 13900025 - No space left on device
54     * @throws { BusinessError } 13900027 - Read-only file system
55     * @throws { BusinessError } 13900029 - Resource deadlock would occur
56     * @throws { BusinessError } 13900030 - File name too long
57     * @throws { BusinessError } 13900033 - Too many symbolic links encountered
58     * @throws { BusinessError } 13900034 - Operation would block
59     * @throws { BusinessError } 13900038 - Value too large for defined data type
60     * @throws { BusinessError } 13900041 - Quota exceeded
61     * @throws { BusinessError } 13900042 - Unknown error
62     * @throws { BusinessError } 14300001 - IPC error
63     * @throws { BusinessError } 14300002 - Invalid uri
64     * @throws { BusinessError } 14300003 - Fail to get fileextension info
65     * @throws { BusinessError } 14300004 - Get wrong result
66     */
67    function getFileAccessAbilityInfo(callback: AsyncCallback<Array<Want>>): void;
68    function getFileAccessAbilityInfo(): Promise<Array<Want>>;
69
70    /**
71     * Obtains the fileAccessHelper that connects all fileaccess servers in the system.
72     * @since 9
73     * @syscap SystemCapability.FileManagement.UserFileService
74     * @StageModelOnly
75     * @systemapi
76     * @permission ohos.permission.FILE_ACCESS_MANAGER and ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
77     * @param context Indicates the application context.
78     * @returns { FileAccessHelper } Returns the fileAccessHelper.
79     * @throws { BusinessError } 13900001 - Operation not permitted
80     * @throws { BusinessError } 13900002 - No such file or directory
81     * @throws { BusinessError } 13900004 - Interrupted system call
82     * @throws { BusinessError } 13900006 - No such device or address
83     * @throws { BusinessError } 13900008 - Bad file descriptor
84     * @throws { BusinessError } 13900011 - Out of memory
85     * @throws { BusinessError } 13900012 - Permission denied
86     * @throws { BusinessError } 13900013 - Bad address
87     * @throws { BusinessError } 13900014 - Device or resource busy
88     * @throws { BusinessError } 13900015 - File exists
89     * @throws { BusinessError } 13900017 - No such device
90     * @throws { BusinessError } 13900018 - Not a directory
91     * @throws { BusinessError } 13900019 - Is a directory
92     * @throws { BusinessError } 13900020 - Invalid argument
93     * @throws { BusinessError } 13900022 - Too many open files
94     * @throws { BusinessError } 13900023 - Text file busy
95     * @throws { BusinessError } 13900024 - File too large
96     * @throws { BusinessError } 13900025 - No space left on device
97     * @throws { BusinessError } 13900027 - Read-only file system
98     * @throws { BusinessError } 13900029 - Resource deadlock would occur
99     * @throws { BusinessError } 13900030 - File name too long
100     * @throws { BusinessError } 13900033 - Too many symbolic links encountered
101     * @throws { BusinessError } 13900034 - Operation would block
102     * @throws { BusinessError } 13900038 - Value too large for defined data type
103     * @throws { BusinessError } 13900041 - Quota exceeded
104     * @throws { BusinessError } 13900042 - Unknown error
105     * @throws { BusinessError } 14300001 - IPC error
106     * @throws { BusinessError } 14300002 - Invalid uri
107     * @throws { BusinessError } 14300003 - Fail to get fileextension info
108     * @throws { BusinessError } 14300004 - Get wrong result
109     */
110    function createFileAccessHelper(context: Context): FileAccessHelper;
111
112    /**
113     * Obtains the fileAccessHelper that connects some specified fileaccess servers in the system.
114     * @since 9
115     * @syscap SystemCapability.FileManagement.UserFileService
116     * @StageModelOnly
117     * @systemapi
118     * @permission ohos.permission.FILE_ACCESS_MANAGER and ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
119     * @param context Indicates the application context.
120     * @param want Represents the connected data provider.
121     * @returns { FileAccessHelper } Returns the fileAccessHelper.
122     * @throws { BusinessError } 13900001  - Operation not permitted
123     * @throws { BusinessError } 13900002  - No such file or directory
124     * @throws { BusinessError } 13900004  - Interrupted system call
125     * @throws { BusinessError } 13900006  - No such device or address
126     * @throws { BusinessError } 13900008  - Bad file descriptor
127     * @throws { BusinessError } 13900011  - Out of memory
128     * @throws { BusinessError } 13900012  - Permission denied
129     * @throws { BusinessError } 13900013  - Bad address
130     * @throws { BusinessError } 13900014  - Device or resource busy
131     * @throws { BusinessError } 13900015  - File exists
132     * @throws { BusinessError } 13900017  - No such device
133     * @throws { BusinessError } 13900018  - Not a directory
134     * @throws { BusinessError } 13900019  - Is a directory
135     * @throws { BusinessError } 13900020  - Invalid argument
136     * @throws { BusinessError } 13900022  - Too many open files
137     * @throws { BusinessError } 13900023  - Text file busy
138     * @throws { BusinessError } 13900024  - File too large
139     * @throws { BusinessError } 13900025  - No space left on device
140     * @throws { BusinessError } 13900027  - Read-only file system
141     * @throws { BusinessError } 13900029  - Resource deadlock would occur
142     * @throws { BusinessError } 13900030  - File name too long
143     * @throws { BusinessError } 13900033  - Too many symbolic links encountered
144     * @throws { BusinessError } 13900034  - Operation would block
145     * @throws { BusinessError } 13900038  - Value too large for defined data type
146     * @throws { BusinessError } 13900041  - Quota exceeded
147     * @throws { BusinessError } 13900042  - Unknown error
148     * @throws { BusinessError } 14300001  - IPC error
149     * @throws { BusinessError } 14300002  - Invalid uri
150     * @throws { BusinessError } 14300003  - Fail to get fileextension info
151     * @throws { BusinessError } 14300004  - Get wrong result
152     */
153    function createFileAccessHelper(context: Context, wants: Array<Want>): FileAccessHelper;
154
155    /**
156     * File Object
157     * @since 9
158     * @syscap SystemCapability.FileManagement.UserFileService
159     * @StageModelOnly
160     * @systemapi
161     * @permission ohos.permission.FILE_ACCESS_MANAGER
162     * @param uri Indicates the path of the file.
163     * @param fileName Indicates the name of the file.
164     * @param mode Indicates the mode of the file.
165     * @param size Indicates the size of the file.
166     * @param mtime Indicates the mtime of the file.
167     * @param mimeType Indicates the mimeType of the file.
168     */
169    interface FileInfo {
170        /**
171         * @type {string}
172         * @readonly
173         */
174        uri: string;
175        /**
176         * @type {string}
177         * @readonly
178         */
179        fileName: string;
180        /**
181         * @type {number}
182         * @readonly
183         */
184        mode: number;
185        /**
186         * @type {number}
187         * @readonly
188         */
189        size: number;
190        /**
191         * @type {number}
192         * @readonly
193         */
194        mtime: number;
195        /**
196         * @type {string}
197         * @readonly
198         */
199        mimeType: string;
200
201        /**
202         * List files in the current directory.
203         * @since 9
204         * @syscap SystemCapability.FileManagement.UserFileService
205         * @StageModelOnly
206         * @systemapi
207         * @permission ohos.permission.FILE_ACCESS_MANAGER
208         * @param filter Indicates the filter of file.
209         * @returns { FileIterator } Returns the FileIterator Object.
210         * @throws { BusinessError } 13900001 - Operation not permitted
211         * @throws { BusinessError } 13900002 - No such file or directory
212         * @throws { BusinessError } 13900004 - Interrupted system call
213         * @throws { BusinessError } 13900006 - No such device or address
214         * @throws { BusinessError } 13900008 - Bad file descriptor
215         * @throws { BusinessError } 13900011 - Out of memory
216         * @throws { BusinessError } 13900012 - Permission denied
217         * @throws { BusinessError } 13900013 - Bad address
218         * @throws { BusinessError } 13900014 - Device or resource busy
219         * @throws { BusinessError } 13900015 - File exists
220         * @throws { BusinessError } 13900017 - No such device
221         * @throws { BusinessError } 13900018 - Not a directory
222         * @throws { BusinessError } 13900019 - Is a directory
223         * @throws { BusinessError } 13900020 - Invalid argument
224         * @throws { BusinessError } 13900022 - Too many open files
225         * @throws { BusinessError } 13900023 - Text file busy
226         * @throws { BusinessError } 13900024 - File too large
227         * @throws { BusinessError } 13900025 - No space left on device
228         * @throws { BusinessError } 13900027 - Read-only file system
229         * @throws { BusinessError } 13900029 - Resource deadlock would occur
230         * @throws { BusinessError } 13900030 - File name too long
231         * @throws { BusinessError } 13900033 - Too many symbolic links encountered
232         * @throws { BusinessError } 13900034 - Operation would block
233         * @throws { BusinessError } 13900038 - Value too large for defined data type
234         * @throws { BusinessError } 13900041 - Quota exceeded
235         * @throws { BusinessError } 13900042 - Unknown error
236         * @throws { BusinessError } 14000001 - Invalid display name
237         * @throws { BusinessError } 14000002 - Invalid uri
238         * @throws { BusinessError } 14000003 - Invalid file extension
239         * @throws { BusinessError } 14000004 - File has been put into trash bin
240         * @throws { BusinessError } 14300001 - IPC error
241         * @throws { BusinessError } 14300002 - Invalid uri
242         * @throws { BusinessError } 14300003 - Fail to get fileextension info
243         * @throws { BusinessError } 14300004 - Get wrong result
244         */
245        listFile(filter?: Filter): FileIterator;
246
247        /**
248         * Recursively list all files in the current directory.
249         * @since 9
250         * @syscap SystemCapability.FileManagement.UserFileService
251         * @StageModelOnly
252         * @systemapi
253         * @permission ohos.permission.FILE_ACCESS_MANAGER
254         * @param filter Indicates the filter of file.
255         * @returns { FileIterator } Returns the FileIterator Object.
256         * @throws { BusinessError } 13900001 - Operation not permitted
257         * @throws { BusinessError } 13900002 - No such file or directory
258         * @throws { BusinessError } 13900004 - Interrupted system call
259         * @throws { BusinessError } 13900006 - No such device or address
260         * @throws { BusinessError } 13900008 - Bad file descriptor
261         * @throws { BusinessError } 13900011 - Out of memory
262         * @throws { BusinessError } 13900012 - Permission denied
263         * @throws { BusinessError } 13900013 - Bad address
264         * @throws { BusinessError } 13900014 - Device or resource busy
265         * @throws { BusinessError } 13900015 - File exists
266         * @throws { BusinessError } 13900017 - No such device
267         * @throws { BusinessError } 13900018 - Not a directory
268         * @throws { BusinessError } 13900019 - Is a directory
269         * @throws { BusinessError } 13900020 - Invalid argument
270         * @throws { BusinessError } 13900022 - Too many open files
271         * @throws { BusinessError } 13900023 - Text file busy
272         * @throws { BusinessError } 13900024 - File too large
273         * @throws { BusinessError } 13900025 - No space left on device
274         * @throws { BusinessError } 13900027 - Read-only file system
275         * @throws { BusinessError } 13900029 - Resource deadlock would occur
276         * @throws { BusinessError } 13900030 - File name too long
277         * @throws { BusinessError } 13900033 - Too many symbolic links encountered
278         * @throws { BusinessError } 13900034 - Operation would block
279         * @throws { BusinessError } 13900038 - Value too large for defined data type
280         * @throws { BusinessError } 13900041 - Quota exceeded
281         * @throws { BusinessError } 13900042 - Unknown error
282         * @throws { BusinessError } 14000001 - Invalid display name
283         * @throws { BusinessError } 14000002 - Invalid uri
284         * @throws { BusinessError } 14000003 - Invalid file extension
285         * @throws { BusinessError } 14000004 - File has been put into trash bin
286         * @throws { BusinessError } 14300001 - IPC error
287         * @throws { BusinessError } 14300002 - Invalid uri
288         * @throws { BusinessError } 14300003 - Fail to get fileextension info
289         * @throws { BusinessError } 14300004 - Get wrong result
290         */
291        scanFile(filter?: Filter): FileIterator;
292    }
293
294    /**
295     * FileIterator Object
296     * @since 9
297     * @syscap SystemCapability.FileManagement.UserFileService
298     * @StageModelOnly
299     * @systemapi
300     * @permission ohos.permission.FILE_ACCESS_MANAGER
301     */
302    interface FileIterator {
303        /**
304         * Get the next fileInfo.
305         * @since 9
306         * @syscap SystemCapability.FileManagement.UserFileService
307         * @StageModelOnly
308         * @systemapi
309         * @permission ohos.permission.FILE_ACCESS_MANAGER
310         * @returns { FileInfo } Returns the FileInfo Object.
311         * @throws { BusinessError } 13900001 - Operation not permitted
312         * @throws { BusinessError } 13900002 - No such file or directory
313         * @throws { BusinessError } 13900004 - Interrupted system call
314         * @throws { BusinessError } 13900006 - No such device or address
315         * @throws { BusinessError } 13900008 - Bad file descriptor
316         * @throws { BusinessError } 13900011 - Out of memory
317         * @throws { BusinessError } 13900012 - Permission denied
318         * @throws { BusinessError } 13900013 - Bad address
319         * @throws { BusinessError } 13900014 - Device or resource busy
320         * @throws { BusinessError } 13900015 - File exists
321         * @throws { BusinessError } 13900017 - No such device
322         * @throws { BusinessError } 13900018 - Not a directory
323         * @throws { BusinessError } 13900019 - Is a directory
324         * @throws { BusinessError } 13900020 - Invalid argument
325         * @throws { BusinessError } 13900022 - Too many open files
326         * @throws { BusinessError } 13900023 - Text file busy
327         * @throws { BusinessError } 13900024 - File too large
328         * @throws { BusinessError } 13900025 - No space left on device
329         * @throws { BusinessError } 13900027 - Read-only file system
330         * @throws { BusinessError } 13900029 - Resource deadlock would occur
331         * @throws { BusinessError } 13900030 - File name too long
332         * @throws { BusinessError } 13900033 - Too many symbolic links encountered
333         * @throws { BusinessError } 13900034 - Operation would block
334         * @throws { BusinessError } 13900038 - Value too large for defined data type
335         * @throws { BusinessError } 13900041 - Quota exceeded
336         * @throws { BusinessError } 13900042 - Unknown error
337         * @throws { BusinessError } 14000001 - Invalid display name
338         * @throws { BusinessError } 14000002 - Invalid uri
339         * @throws { BusinessError } 14000003 - Invalid file extension
340         * @throws { BusinessError } 14000004 - File has been put into trash bin
341         * @throws { BusinessError } 14300001 - IPC error
342         * @throws { BusinessError } 14300002 - Invalid uri
343         * @throws { BusinessError } 14300003 - Fail to get fileextension info
344         * @throws { BusinessError } 14300004 - Get wrong result
345         */
346        next(): {value: FileInfo, done: boolean}
347    }
348
349    /**
350     * Root Object
351     * @since 9
352     * @syscap SystemCapability.FileManagement.UserFileService
353     * @StageModelOnly
354     * @systemapi
355     * @permission ohos.permission.FILE_ACCESS_MANAGER
356     */
357    interface RootInfo {
358        /**
359         * @type {number}
360         * @readonly
361         */
362        deviceType: number;
363        /**
364         * @type {string}
365         * @readonly
366         */
367        uri: string;
368        /**
369         * @type {string}
370         * @readonly
371         */
372        displayName: string;
373        /**
374         * @type {number}
375         * @readonly
376         */
377        deviceFlags: number;
378
379        /**
380         * List files in the current directory.
381         * @since 9
382         * @syscap SystemCapability.FileManagement.UserFileService
383         * @StageModelOnly
384         * @systemapi
385         * @permission ohos.permission.FILE_ACCESS_MANAGER
386         * @param filter Indicates the filter of file.
387         * @returns { FileIterator } Returns the FileIterator Object.
388         * @throws { BusinessError } 13900001 - Operation not permitted
389         * @throws { BusinessError } 13900002 - No such file or directory
390         * @throws { BusinessError } 13900004 - Interrupted system call
391         * @throws { BusinessError } 13900006 - No such device or address
392         * @throws { BusinessError } 13900008 - Bad file descriptor
393         * @throws { BusinessError } 13900011 - Out of memory
394         * @throws { BusinessError } 13900012 - Permission denied
395         * @throws { BusinessError } 13900013 - Bad address
396         * @throws { BusinessError } 13900014 - Device or resource busy
397         * @throws { BusinessError } 13900015 - File exists
398         * @throws { BusinessError } 13900017 - No such device
399         * @throws { BusinessError } 13900018 - Not a directory
400         * @throws { BusinessError } 13900019 - Is a directory
401         * @throws { BusinessError } 13900020 - Invalid argument
402         * @throws { BusinessError } 13900022 - Too many open files
403         * @throws { BusinessError } 13900023 - Text file busy
404         * @throws { BusinessError } 13900024 - File too large
405         * @throws { BusinessError } 13900025 - No space left on device
406         * @throws { BusinessError } 13900027 - Read-only file system
407         * @throws { BusinessError } 13900029 - Resource deadlock would occur
408         * @throws { BusinessError } 13900030 - File name too long
409         * @throws { BusinessError } 13900033 - Too many symbolic links encountered
410         * @throws { BusinessError } 13900034 - Operation would block
411         * @throws { BusinessError } 13900038 - Value too large for defined data type
412         * @throws { BusinessError } 13900041 - Quota exceeded
413         * @throws { BusinessError } 13900042 - Unknown error
414         * @throws { BusinessError } 14000001 - Invalid display name
415         * @throws { BusinessError } 14000002 - Invalid uri
416         * @throws { BusinessError } 14000003 - Invalid file extension
417         * @throws { BusinessError } 14000004 - File has been put into trash bin
418         * @throws { BusinessError } 14300001 - IPC error
419         * @throws { BusinessError } 14300002 - Invalid uri
420         * @throws { BusinessError } 14300003 - Fail to get fileextension info
421         * @throws { BusinessError } 14300004 - Get wrong result
422         */
423        listFile(filter?: Filter): FileIterator;
424
425        /**
426         * Recursively list all files in the current directory.
427         * @since 9
428         * @syscap SystemCapability.FileManagement.UserFileService
429         * @StageModelOnly
430         * @systemapi
431         * @permission ohos.permission.FILE_ACCESS_MANAGER
432         * @param filter Indicates the filter of file.
433         * @returns { FileIterator } Returns the RootIterator Object.
434         * @throws { BusinessError } 13900001 - Operation not permitted
435         * @throws { BusinessError } 13900002 - No such file or directory
436         * @throws { BusinessError } 13900004 - Interrupted system call
437         * @throws { BusinessError } 13900006 - No such device or address
438         * @throws { BusinessError } 13900008 - Bad file descriptor
439         * @throws { BusinessError } 13900011 - Out of memory
440         * @throws { BusinessError } 13900012 - Permission denied
441         * @throws { BusinessError } 13900013 - Bad address
442         * @throws { BusinessError } 13900014 - Device or resource busy
443         * @throws { BusinessError } 13900015 - File exists
444         * @throws { BusinessError } 13900017 - No such device
445         * @throws { BusinessError } 13900018 - Not a directory
446         * @throws { BusinessError } 13900019 - Is a directory
447         * @throws { BusinessError } 13900020 - Invalid argument
448         * @throws { BusinessError } 13900022 - Too many open files
449         * @throws { BusinessError } 13900023 - Text file busy
450         * @throws { BusinessError } 13900024 - File too large
451         * @throws { BusinessError } 13900025 - No space left on device
452         * @throws { BusinessError } 13900027 - Read-only file system
453         * @throws { BusinessError } 13900029 - Resource deadlock would occur
454         * @throws { BusinessError } 13900030 - File name too long
455         * @throws { BusinessError } 13900033 - Too many symbolic links encountered
456         * @throws { BusinessError } 13900034 - Operation would block
457         * @throws { BusinessError } 13900038 - Value too large for defined data type
458         * @throws { BusinessError } 13900041 - Quota exceeded
459         * @throws { BusinessError } 13900042 - Unknown error
460         * @throws { BusinessError } 14000001 - Invalid display name
461         * @throws { BusinessError } 14000002 - Invalid uri
462         * @throws { BusinessError } 14000003 - Invalid file extension
463         * @throws { BusinessError } 14000004 - File has been put into trash bin
464         * @throws { BusinessError } 14300001 - IPC error
465         * @throws { BusinessError } 14300002 - Invalid uri
466         * @throws { BusinessError } 14300003 - Fail to get fileextension info
467         * @throws { BusinessError } 14300004 - Get wrong result
468         */
469        scanFile(filter?: Filter): FileIterator;
470    }
471
472    /**
473     * RootIterator Object
474     * @since 9
475     * @syscap SystemCapability.FileManagement.UserFileService
476     * @StageModelOnly
477     * @systemapi
478     * @permission ohos.permission.FILE_ACCESS_MANAGER
479     */
480    interface RootIterator {
481        /**
482         * Get a next RootInfo.
483         * @since 9
484         * @syscap SystemCapability.FileManagement.UserFileService
485         * @StageModelOnly
486         * @systemapi
487         * @permission ohos.permission.FILE_ACCESS_MANAGER
488         * @returns { FileInfo } Returns the RootInfo Object.
489         * @throws { BusinessError } 13900001 - Operation not permitted
490         * @throws { BusinessError } 13900002 - No such file or directory
491         * @throws { BusinessError } 13900004 - Interrupted system call
492         * @throws { BusinessError } 13900006 - No such device or address
493         * @throws { BusinessError } 13900008 - Bad file descriptor
494         * @throws { BusinessError } 13900011 - Out of memory
495         * @throws { BusinessError } 13900012 - Permission denied
496         * @throws { BusinessError } 13900013 - Bad address
497         * @throws { BusinessError } 13900014 - Device or resource busy
498         * @throws { BusinessError } 13900015 - File exists
499         * @throws { BusinessError } 13900017 - No such device
500         * @throws { BusinessError } 13900018 - Not a directory
501         * @throws { BusinessError } 13900019 - Is a directory
502         * @throws { BusinessError } 13900020 - Invalid argument
503         * @throws { BusinessError } 13900022 - Too many open files
504         * @throws { BusinessError } 13900023 - Text file busy
505         * @throws { BusinessError } 13900024 - File too large
506         * @throws { BusinessError } 13900025 - No space left on device
507         * @throws { BusinessError } 13900027 - Read-only file system
508         * @throws { BusinessError } 13900029 - Resource deadlock would occur
509         * @throws { BusinessError } 13900030 - File name too long
510         * @throws { BusinessError } 13900033 - Too many symbolic links encountered
511         * @throws { BusinessError } 13900034 - Operation would block
512         * @throws { BusinessError } 13900038 - Value too large for defined data type
513         * @throws { BusinessError } 13900041 - Quota exceeded
514         * @throws { BusinessError } 13900042 - Unknown error
515         * @throws { BusinessError } 14000001 - Invalid display name
516         * @throws { BusinessError } 14000002 - Invalid uri
517         * @throws { BusinessError } 14000003 - Invalid file extension
518         * @throws { BusinessError } 14000004 - File has been put into trash bin
519         * @throws { BusinessError } 14300001 - IPC error
520         * @throws { BusinessError } 14300002 - Invalid uri
521         * @throws { BusinessError } 14300003 - Fail to get fileextension info
522         * @throws { BusinessError } 14300004 - Get wrong result
523         */
524        next(): {value: RootInfo, done: boolean}
525    }
526
527    /**
528     * OPENFLAGS represents the way to open the file.
529     * @since 9
530     * @syscap SystemCapability.FileManagement.UserFileService
531     * @StageModelOnly
532     * @systemapi
533     */
534    enum OPENFLAGS {
535        /** file is openFile only_read */
536        READ = 0o0,
537        /** file is openFile only_write */
538        WRITE = 0o1,
539        /** file is openFile write_read */
540        WRITE_READ = 0o2
541    }
542
543    /**
544     * FileAccessHelper Object
545     * @since 9
546     * @syscap SystemCapability.FileManagement.UserFileService
547     * @StageModelOnly
548     * @systemapi
549     * @permission ohos.permission.FILE_ACCESS_MANAGER
550     */
551    interface FileAccessHelper {
552        /**
553         * Open a file.
554         *
555         * @since 9
556         * @syscap SystemCapability.FileManagement.UserFileService
557         * @StageModelOnly
558         * @systemapi
559         * @permission ohos.permission.FILE_ACCESS_MANAGER
560         * @param uri Indicates the path of the file to open.
561         * @param flags Indicate options of opening a file. The default value is read-only.
562         * @returns {(void | Promise<number>)} Returns the file descriptor.
563         * @throws { BusinessError } 13900001 - Operation not permitted
564         * @throws { BusinessError } 13900002 - No such file or directory
565         * @throws { BusinessError } 13900004 - Interrupted system call
566         * @throws { BusinessError } 13900006 - No such device or address
567         * @throws { BusinessError } 13900008 - Bad file descriptor
568         * @throws { BusinessError } 13900011 - Out of memory
569         * @throws { BusinessError } 13900012 - Permission denied
570         * @throws { BusinessError } 13900013 - Bad address
571         * @throws { BusinessError } 13900014 - Device or resource busy
572         * @throws { BusinessError } 13900015 - File exists
573         * @throws { BusinessError } 13900017 - No such device
574         * @throws { BusinessError } 13900018 - Not a directory
575         * @throws { BusinessError } 13900019 - Is a directory
576         * @throws { BusinessError } 13900020 - Invalid argument
577         * @throws { BusinessError } 13900022 - Too many open files
578         * @throws { BusinessError } 13900023 - Text file busy
579         * @throws { BusinessError } 13900024 - File too large
580         * @throws { BusinessError } 13900025 - No space left on device
581         * @throws { BusinessError } 13900027 - Read-only file system
582         * @throws { BusinessError } 13900029 - Resource deadlock would occur
583         * @throws { BusinessError } 13900030 - File name too long
584         * @throws { BusinessError } 13900033 - Too many symbolic links encountered
585         * @throws { BusinessError } 13900034 - Operation would block
586         * @throws { BusinessError } 13900038 - Value too large for defined data type
587         * @throws { BusinessError } 13900041 - Quota exceeded
588         * @throws { BusinessError } 13900042 - Unknown error
589         * @throws { BusinessError } 14000001 - Invalid display name
590         * @throws { BusinessError } 14000002 - Invalid uri
591         * @throws { BusinessError } 14000003 - Invalid file extension
592         * @throws { BusinessError } 14000004 - File has been put into trash bin
593         * @throws { BusinessError } 14300001 - IPC error
594         * @throws { BusinessError } 14300002 - Invalid uri
595         * @throws { BusinessError } 14300003 - Fail to get fileextension info
596         * @throws { BusinessError } 14300004 - Get wrong result
597         */
598        openFile(uri: string, flags: OPENFLAGS) : Promise<number>;
599        openFile(uri: string, flags: OPENFLAGS, callback: AsyncCallback<number>) : void;
600
601        /**
602         * Create a file.
603         *
604         * @since 9
605         * @syscap SystemCapability.FileManagement.UserFileService
606         * @StageModelOnly
607         * @systemapi
608         * @permission ohos.permission.FILE_ACCESS_MANAGER
609         * @param uri Represents a specific parent directory.
610         * @param displayName Indicates the new file name, and supports with suffix.
611         * @returns {(void | Promise<string>)} Returns the new file's URI.
612         * @throws { BusinessError } 13900001 - Operation not permitted
613         * @throws { BusinessError } 13900002 - No such file or directory
614         * @throws { BusinessError } 13900004 - Interrupted system call
615         * @throws { BusinessError } 13900006 - No such device or address
616         * @throws { BusinessError } 13900008 - Bad file descriptor
617         * @throws { BusinessError } 13900011 - Out of memory
618         * @throws { BusinessError } 13900012 - Permission denied
619         * @throws { BusinessError } 13900013 - Bad address
620         * @throws { BusinessError } 13900014 - Device or resource busy
621         * @throws { BusinessError } 13900015 - File exists
622         * @throws { BusinessError } 13900017 - No such device
623         * @throws { BusinessError } 13900018 - Not a directory
624         * @throws { BusinessError } 13900019 - Is a directory
625         * @throws { BusinessError } 13900020 - Invalid argument
626         * @throws { BusinessError } 13900022 - Too many open files
627         * @throws { BusinessError } 13900023 - Text file busy
628         * @throws { BusinessError } 13900024 - File too large
629         * @throws { BusinessError } 13900025 - No space left on device
630         * @throws { BusinessError } 13900027 - Read-only file system
631         * @throws { BusinessError } 13900029 - Resource deadlock would occur
632         * @throws { BusinessError } 13900030 - File name too long
633         * @throws { BusinessError } 13900033 - Too many symbolic links encountered
634         * @throws { BusinessError } 13900034 - Operation would block
635         * @throws { BusinessError } 13900038 - Value too large for defined data type
636         * @throws { BusinessError } 13900041 - Quota exceeded
637         * @throws { BusinessError } 13900042 - Unknown error
638         * @throws { BusinessError } 14000001 - Invalid display name
639         * @throws { BusinessError } 14000002 - Invalid uri
640         * @throws { BusinessError } 14000003 - Invalid file extension
641         * @throws { BusinessError } 14000004 - File has been put into trash bin
642         * @throws { BusinessError } 14300001 - IPC error
643         * @throws { BusinessError } 14300002 - Invalid uri
644         * @throws { BusinessError } 14300003 - Fail to get fileextension info
645         * @throws { BusinessError } 14300004 - Get wrong result
646         */
647        createFile(uri: string, displayName: string) : Promise<string>;
648        createFile(uri: string, displayName: string, callback: AsyncCallback<string>) : void;
649
650        /**
651         * Create a Directory.
652         *
653         * @since 9
654         * @syscap SystemCapability.FileManagement.UserFileService
655         * @StageModelOnly
656         * @systemapi
657         * @permission ohos.permission.FILE_ACCESS_MANAGER
658         * @param parentUri Represents a specific parent directory.
659         * @param displayName Indicates the new directory name.
660         * @returns {(void | Promise<string>)} Returns the new directory's URI.
661         * @throws { BusinessError } 13900001 - Operation not permitted
662         * @throws { BusinessError } 13900002 - No such file or directory
663         * @throws { BusinessError } 13900004 - Interrupted system call
664         * @throws { BusinessError } 13900006 - No such device or address
665         * @throws { BusinessError } 13900008 - Bad file descriptor
666         * @throws { BusinessError } 13900011 - Out of memory
667         * @throws { BusinessError } 13900012 - Permission denied
668         * @throws { BusinessError } 13900013 - Bad address
669         * @throws { BusinessError } 13900014 - Device or resource busy
670         * @throws { BusinessError } 13900015 - File exists
671         * @throws { BusinessError } 13900017 - No such device
672         * @throws { BusinessError } 13900018 - Not a directory
673         * @throws { BusinessError } 13900019 - Is a directory
674         * @throws { BusinessError } 13900020 - Invalid argument
675         * @throws { BusinessError } 13900022 - Too many open files
676         * @throws { BusinessError } 13900023 - Text file busy
677         * @throws { BusinessError } 13900024 - File too large
678         * @throws { BusinessError } 13900025 - No space left on device
679         * @throws { BusinessError } 13900027 - Read-only file system
680         * @throws { BusinessError } 13900029 - Resource deadlock would occur
681         * @throws { BusinessError } 13900030 - File name too long
682         * @throws { BusinessError } 13900033 - Too many symbolic links encountered
683         * @throws { BusinessError } 13900034 - Operation would block
684         * @throws { BusinessError } 13900038 - Value too large for defined data type
685         * @throws { BusinessError } 13900041 - Quota exceeded
686         * @throws { BusinessError } 13900042 - Unknown error
687         * @throws { BusinessError } 14000001 - Invalid display name
688         * @throws { BusinessError } 14000002 - Invalid uri
689         * @throws { BusinessError } 14000003 - Invalid file extension
690         * @throws { BusinessError } 14000004 - File has been put into trash bin
691         * @throws { BusinessError } 14300001 - IPC error
692         * @throws { BusinessError } 14300002 - Invalid uri
693         * @throws { BusinessError } 14300003 - Fail to get fileextension info
694         * @throws { BusinessError } 14300004 - Get wrong result
695         */
696        mkDir(parentUri: string, displayName: string) : Promise<string>;
697        mkDir(parentUri: string, displayName: string, callback: AsyncCallback<string>) : void;
698
699        /**
700         * Delete a file or delete a directory recursively.
701         *
702         * @since 9
703         * @syscap SystemCapability.FileManagement.UserFileService
704         * @StageModelOnly
705         * @systemapi
706         * @permission ohos.permission.FILE_ACCESS_MANAGER
707         * @param uri Indicates the file or directory to be deleted.
708         * @throws { BusinessError } 13900001 - Operation not permitted
709         * @throws { BusinessError } 13900002 - No such file or directory
710         * @throws { BusinessError } 13900004 - Interrupted system call
711         * @throws { BusinessError } 13900006 - No such device or address
712         * @throws { BusinessError } 13900008 - Bad file descriptor
713         * @throws { BusinessError } 13900011 - Out of memory
714         * @throws { BusinessError } 13900012 - Permission denied
715         * @throws { BusinessError } 13900013 - Bad address
716         * @throws { BusinessError } 13900014 - Device or resource busy
717         * @throws { BusinessError } 13900015 - File exists
718         * @throws { BusinessError } 13900017 - No such device
719         * @throws { BusinessError } 13900018 - Not a directory
720         * @throws { BusinessError } 13900019 - Is a directory
721         * @throws { BusinessError } 13900020 - Invalid argument
722         * @throws { BusinessError } 13900022 - Too many open files
723         * @throws { BusinessError } 13900023 - Text file busy
724         * @throws { BusinessError } 13900024 - File too large
725         * @throws { BusinessError } 13900025 - No space left on device
726         * @throws { BusinessError } 13900027 - Read-only file system
727         * @throws { BusinessError } 13900029 - Resource deadlock would occur
728         * @throws { BusinessError } 13900030 - File name too long
729         * @throws { BusinessError } 13900033 - Too many symbolic links encountered
730         * @throws { BusinessError } 13900034 - Operation would block
731         * @throws { BusinessError } 13900038 - Value too large for defined data type
732         * @throws { BusinessError } 13900041 - Quota exceeded
733         * @throws { BusinessError } 13900042 - Unknown error
734         * @throws { BusinessError } 14000001 - Invalid display name
735         * @throws { BusinessError } 14000002 - Invalid uri
736         * @throws { BusinessError } 14000003 - Invalid file extension
737         * @throws { BusinessError } 14000004 - File has been put into trash bin
738         * @throws { BusinessError } 14300001 - IPC error
739         * @throws { BusinessError } 14300002 - Invalid uri
740         * @throws { BusinessError } 14300003 - Fail to get fileextension info
741         * @throws { BusinessError } 14300004 - Get wrong result
742         */
743        delete(uri: string) : Promise<number>;
744        delete(uri: string, callback: AsyncCallback<number>) : void;
745
746        /**
747         * Move a file or move a directory recursively.
748         *
749         * @since 9
750         * @syscap SystemCapability.FileManagement.UserFileService
751         * @StageModelOnly
752         * @systemapi
753         * @permission ohos.permission.FILE_ACCESS_MANAGER
754         * @param sourceFile Indicates the file or directory to be moved.
755         * @param destFile Represents the destination folder.
756         * @returns {(void | Promise<string>)} Returns the generated new file or directory.
757         * @throws { BusinessError } 13900001 - Operation not permitted
758         * @throws { BusinessError } 13900002 - No such file or directory
759         * @throws { BusinessError } 13900004 - Interrupted system call
760         * @throws { BusinessError } 13900006 - No such device or address
761         * @throws { BusinessError } 13900008 - Bad file descriptor
762         * @throws { BusinessError } 13900011 - Out of memory
763         * @throws { BusinessError } 13900012 - Permission denied
764         * @throws { BusinessError } 13900013 - Bad address
765         * @throws { BusinessError } 13900014 - Device or resource busy
766         * @throws { BusinessError } 13900015 - File exists
767         * @throws { BusinessError } 13900017 - No such device
768         * @throws { BusinessError } 13900018 - Not a directory
769         * @throws { BusinessError } 13900019 - Is a directory
770         * @throws { BusinessError } 13900020 - Invalid argument
771         * @throws { BusinessError } 13900022 - Too many open files
772         * @throws { BusinessError } 13900023 - Text file busy
773         * @throws { BusinessError } 13900024 - File too large
774         * @throws { BusinessError } 13900025 - No space left on device
775         * @throws { BusinessError } 13900027 - Read-only file system
776         * @throws { BusinessError } 13900029 - Resource deadlock would occur
777         * @throws { BusinessError } 13900030 - File name too long
778         * @throws { BusinessError } 13900033 - Too many symbolic links encountered
779         * @throws { BusinessError } 13900034 - Operation would block
780         * @throws { BusinessError } 13900038 - Value too large for defined data type
781         * @throws { BusinessError } 13900041 - Quota exceeded
782         * @throws { BusinessError } 13900042 - Unknown error
783         * @throws { BusinessError } 14000001 - Invalid display name
784         * @throws { BusinessError } 14000002 - Invalid uri
785         * @throws { BusinessError } 14000003 - Invalid file extension
786         * @throws { BusinessError } 14000004 - File has been put into trash bin
787         * @throws { BusinessError } 14300001 - IPC error
788         * @throws { BusinessError } 14300002 - Invalid uri
789         * @throws { BusinessError } 14300003 - Fail to get fileextension info
790         * @throws { BusinessError } 14300004 - Get wrong result
791         */
792        move(sourceFile: string, destFile: string) : Promise<string>;
793        move(sourceFile: string, destFile: string, callback: AsyncCallback<string>) : void;
794
795        /**
796         * Rename the selected file or directory.
797         *
798         * @since 9
799         * @syscap SystemCapability.FileManagement.UserFileService
800         * @StageModelOnly
801         * @systemapi
802         * @permission ohos.permission.FILE_ACCESS_MANAGER
803         * @param uri Indicates the selected file or directory.
804         * @param displayName Indicates the new directory or file name.
805         * @returns {(void | Promise<string>)} Returns a URI representing the new file or directory.
806         * @throws { BusinessError } 13900001 - Operation not permitted
807         * @throws { BusinessError } 13900002 - No such file or directory
808         * @throws { BusinessError } 13900004 - Interrupted system call
809         * @throws { BusinessError } 13900006 - No such device or address
810         * @throws { BusinessError } 13900008 - Bad file descriptor
811         * @throws { BusinessError } 13900011 - Out of memory
812         * @throws { BusinessError } 13900012 - Permission denied
813         * @throws { BusinessError } 13900013 - Bad address
814         * @throws { BusinessError } 13900014 - Device or resource busy
815         * @throws { BusinessError } 13900015 - File exists
816         * @throws { BusinessError } 13900017 - No such device
817         * @throws { BusinessError } 13900018 - Not a directory
818         * @throws { BusinessError } 13900019 - Is a directory
819         * @throws { BusinessError } 13900020 - Invalid argument
820         * @throws { BusinessError } 13900022 - Too many open files
821         * @throws { BusinessError } 13900023 - Text file busy
822         * @throws { BusinessError } 13900024 - File too large
823         * @throws { BusinessError } 13900025 - No space left on device
824         * @throws { BusinessError } 13900027 - Read-only file system
825         * @throws { BusinessError } 13900029 - Resource deadlock would occur
826         * @throws { BusinessError } 13900030 - File name too long
827         * @throws { BusinessError } 13900033 - Too many symbolic links encountered
828         * @throws { BusinessError } 13900034 - Operation would block
829         * @throws { BusinessError } 13900038 - Value too large for defined data type
830         * @throws { BusinessError } 13900041 - Quota exceeded
831         * @throws { BusinessError } 13900042 - Unknown error
832         * @throws { BusinessError } 14000001 - Invalid display name
833         * @throws { BusinessError } 14000002 - Invalid uri
834         * @throws { BusinessError } 14000003 - Invalid file extension
835         * @throws { BusinessError } 14000004 - File has been put into trash bin
836         * @throws { BusinessError } 14300001 - IPC error
837         * @throws { BusinessError } 14300002 - Invalid uri
838         * @throws { BusinessError } 14300003 - Fail to get fileextension info
839         * @throws { BusinessError } 14300004 - Get wrong result
840         */
841        rename(uri: string, displayName: string) : Promise<string>;
842        rename(uri: string, displayName: string, callback: AsyncCallback<string>) : void;
843
844        /**
845         * Obtain the status of a file or directory.
846         *
847         * @since 9
848         * @syscap SystemCapability.FileManagement.UserFileService
849         * @StageModelOnly
850         * @systemapi
851         * @permission ohos.permission.FILE_ACCESS_MANAGER
852         * @param uri Indicates the selected file or directory.
853         * @returns {(void | Promise<boolean>)} Returns whether it exists.
854         * @throws { BusinessError } 13900001 - Operation not permitted
855         * @throws { BusinessError } 13900002 - No such file or directory
856         * @throws { BusinessError } 13900004 - Interrupted system call
857         * @throws { BusinessError } 13900006 - No such device or address
858         * @throws { BusinessError } 13900008 - Bad file descriptor
859         * @throws { BusinessError } 13900011 - Out of memory
860         * @throws { BusinessError } 13900012 - Permission denied
861         * @throws { BusinessError } 13900013 - Bad address
862         * @throws { BusinessError } 13900014 - Device or resource busy
863         * @throws { BusinessError } 13900015 - File exists
864         * @throws { BusinessError } 13900017 - No such device
865         * @throws { BusinessError } 13900018 - Not a directory
866         * @throws { BusinessError } 13900019 - Is a directory
867         * @throws { BusinessError } 13900020 - Invalid argument
868         * @throws { BusinessError } 13900022 - Too many open files
869         * @throws { BusinessError } 13900023 - Text file busy
870         * @throws { BusinessError } 13900024 - File too large
871         * @throws { BusinessError } 13900025 - No space left on device
872         * @throws { BusinessError } 13900027 - Read-only file system
873         * @throws { BusinessError } 13900029 - Resource deadlock would occur
874         * @throws { BusinessError } 13900030 - File name too long
875         * @throws { BusinessError } 13900033 - Too many symbolic links encountered
876         * @throws { BusinessError } 13900034 - Operation would block
877         * @throws { BusinessError } 13900038 - Value too large for defined data type
878         * @throws { BusinessError } 13900041 - Quota exceeded
879         * @throws { BusinessError } 13900042 - Unknown error
880         * @throws { BusinessError } 14000001 - Invalid display name
881         * @throws { BusinessError } 14000002 - Invalid uri
882         * @throws { BusinessError } 14000003 - Invalid file extension
883         * @throws { BusinessError } 14000004 - File has been put into trash bin
884         * @throws { BusinessError } 14300001 - IPC error
885         * @throws { BusinessError } 14300002 - Invalid uri
886         * @throws { BusinessError } 14300003 - Fail to get fileextension info
887         * @throws { BusinessError } 14300004 - Get wrong result
888         */
889        access(sourceFileUri: string) : Promise<boolean>;
890        access(sourceFileUri: string, callback: AsyncCallback<boolean>) : void;
891
892        /**
893         * Get a RootIterator.
894         *
895         * @since 9
896         * @syscap SystemCapability.FileManagement.UserFileService
897         * @StageModelOnly
898         * @systemapi
899         * @permission ohos.permission.FILE_ACCESS_MANAGER
900         * @returns {(void | Promise<RootIterator>)} Returns a RootIterator.
901         * @throws { BusinessError } 13900001 - Operation not permitted
902         * @throws { BusinessError } 13900002 - No such file or directory
903         * @throws { BusinessError } 13900004 - Interrupted system call
904         * @throws { BusinessError } 13900006 - No such device or address
905         * @throws { BusinessError } 13900008 - Bad file descriptor
906         * @throws { BusinessError } 13900011 - Out of memory
907         * @throws { BusinessError } 13900012 - Permission denied
908         * @throws { BusinessError } 13900013 - Bad address
909         * @throws { BusinessError } 13900014 - Device or resource busy
910         * @throws { BusinessError } 13900015 - File exists
911         * @throws { BusinessError } 13900017 - No such device
912         * @throws { BusinessError } 13900018 - Not a directory
913         * @throws { BusinessError } 13900019 - Is a directory
914         * @throws { BusinessError } 13900020 - Invalid argument
915         * @throws { BusinessError } 13900022 - Too many open files
916         * @throws { BusinessError } 13900023 - Text file busy
917         * @throws { BusinessError } 13900024 - File too large
918         * @throws { BusinessError } 13900025 - No space left on device
919         * @throws { BusinessError } 13900027 - Read-only file system
920         * @throws { BusinessError } 13900029 - Resource deadlock would occur
921         * @throws { BusinessError } 13900030 - File name too long
922         * @throws { BusinessError } 13900033 - Too many symbolic links encountered
923         * @throws { BusinessError } 13900034 - Operation would block
924         * @throws { BusinessError } 13900038 - Value too large for defined data type
925         * @throws { BusinessError } 13900041 - Quota exceeded
926         * @throws { BusinessError } 13900042 - Unknown error
927         * @throws { BusinessError } 14000001 - Invalid display name
928         * @throws { BusinessError } 14000002 - Invalid uri
929         * @throws { BusinessError } 14000003 - Invalid file extension
930         * @throws { BusinessError } 14000004 - File has been put into trash bin
931         * @throws { BusinessError } 14300001 - IPC error
932         * @throws { BusinessError } 14300002 - Invalid uri
933         * @throws { BusinessError } 14300003 - Fail to get fileextension info
934         * @throws { BusinessError } 14300004 - Get wrong result
935         */
936        getRoots(): Promise<RootIterator>;
937        getRoots(callback:AsyncCallback<RootIterator>) : void;
938    }
939}
940
941export default fileAccess;
942