diff --git a/api/@ohos.file.fs.d.ts b/api/@ohos.file.fs.d.ts index 6652e7c5b50f08c7de6e4fd867b38df9df70d7b6..4893dd95d2d98ed61f7bc3d7d1b1b185e9a1e709 100644 --- a/api/@ohos.file.fs.d.ts +++ b/api/@ohos.file.fs.d.ts @@ -22,19 +22,50 @@ export default fileIo; * @since 9 */ declare namespace fileIo { + export { access }; + export { accessSync }; + export { close }; + export { closeSync }; + export { copyFile }; + export { copyFileSync }; + export { createStream }; + export { createStreamSync }; + export { fdatasync }; + export { fdatasyncSync }; + export { fdopenStream }; + export { fdopenStreamSync }; + export { fsync }; + export { fsyncSync }; + export { lstat }; + export { lstatSync }; + export { mkdir }; + export { mkdirSync }; + export { mkdtemp }; + export { mkdtempSync }; export { open }; export { openSync }; export { read }; export { readSync }; + export { readText }; + export { readTextSync }; + export { rename }; + export { renameSync }; + export { rmdir }; + export { rmdirSync }; export { stat }; export { statSync }; + export { symlink }; + export { symlinkSync }; export { truncate }; export { truncateSync }; + export { unlink }; + export { unlinkSync }; export { write }; export { writeSync }; export { File }; export { OpenMode }; export { Stat }; + export { Stream }; /** * Mode Indicates the open flags. @@ -55,142 +86,828 @@ declare namespace fileIo { } } +/** + * access file. + * + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @function access + * @param {string} path - path. + * @param {AsyncCallback} [callback] - callback. + * @returns {void | Promise} no callback return Promise otherwise return void + * @throws { BusinessError } 13900002 - No such file or directory + * @throws { BusinessError } 13900005 - I/O error + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900011 - Out of memory + * @throws { BusinessError } 13900012 - Permission denied + * @throws { BusinessError } 13900013 - Bad address + * @throws { BusinessError } 13900018 - Not a directory + * @throws { BusinessError } 13900020 - Invalid argument + * @throws { BusinessError } 13900023 - Text file busy + * @throws { BusinessError } 13900030 - File name too long + * @throws { BusinessError } 13900033 - Too many symbolic links encountered + * @throws { BusinessError } 13900042 - Unknown error + */ +declare function access(path: string, callback?: AsyncCallback): void | Promise; +/** + * access file with sync interface. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @function accessSync + * @param {string} path - path. + * @returns {boolean} access success + * @throws { BusinessError } 13900002 - No such file or directory + * @throws { BusinessError } 13900005 - I/O error + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900011 - Out of memory + * @throws { BusinessError } 13900012 - Permission denied + * @throws { BusinessError } 13900013 - Bad address + * @throws { BusinessError } 13900018 - Not a directory + * @throws { BusinessError } 13900020 - Invalid argument + * @throws { BusinessError } 13900023 - Text file busy + * @throws { BusinessError } 13900030 - File name too long + * @throws { BusinessError } 13900033 - Too many symbolic links encountered + * @throws { BusinessError } 13900042 - Unknown error + */ +declare function accessSync(path: string): boolean; + +/** + * close. + * + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @function close + * @param {number | File} file - file object or fd. + * @param {AsyncCallback} [callback] - callback. + * @returns {void | Promise} no callback return Promise otherwise return void + * @throws { BusinessError } 13900004 - Interrupted system call + * @throws { BusinessError } 13900005 - I/O error + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900025 - No space left on device + * @throws { BusinessError } 13900041 - Quota exceeded + * @throws { BusinessError } 13900042 - Unknown error + */ +declare function close(file: number | File, callback?: AsyncCallback): void | Promise; +/** + * closeSync. + * + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @permission N/A + * @function closeSync + * @param {number | File} file - file object or fd. + * @returns {void} close success + * @throws { BusinessError } 13900004 - Interrupted system call + * @throws { BusinessError } 13900005 - I/O error + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900025 - No space left on device + * @throws { BusinessError } 13900041 - Quota exceeded + * @throws { BusinessError } 13900042 - Unknown error + */ +declare function closeSync(fd: number | File): void; + +/** + * copyFile. + * + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @function copyFile + * @param {string | number} src - src. + * @param {string | number} dest - dest. + * @param {number} [mode = 0] - mode. + * @param {AsyncCallback} [callback] - callback. + * @returns {void | Promise} no callback return Promise otherwise return void + * @throws { BusinessError } 13900002 - No such file or directory + * @throws { BusinessError } 13900004 - Interrupted system call + * @throws { BusinessError } 13900005 - I/O error + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900010 - Try again + * @throws { BusinessError } 13900011 - Out of memory + * @throws { BusinessError } 13900012 - Permission denied + * @throws { BusinessError } 13900013 - Bad address + * @throws { BusinessError } 13900018 - Not a directory + * @throws { BusinessError } 13900019 - Is a directory + * @throws { BusinessError } 13900020 - Invalid argument + * @throws { BusinessError } 13900030 - File name too long + * @throws { BusinessError } 13900031 - Function not implemented + * @throws { BusinessError } 13900033 - Too many symbolic links encountered + * @throws { BusinessError } 13900034 - Operation would block + * @throws { BusinessError } 13900038 - Value too large for defined data type + * @throws { BusinessError } 13900042 - Unknown error + */ +declare function copyFile(src: string | number, dest: string | number, mode?: number, callback?: AsyncCallback): void | Promise; +/** + * copyFileSync. + * + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @function copyFileSync + * @param {string | number} src - src. + * @param {string | number} dest - dest. + * @param {number} [mode = 0] - mode. + * @returns {void} copyFile success + * @throws { BusinessError } 13900002 - No such file or directory + * @throws { BusinessError } 13900004 - Interrupted system call + * @throws { BusinessError } 13900005 - I/O error + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900010 - Try again + * @throws { BusinessError } 13900011 - Out of memory + * @throws { BusinessError } 13900012 - Permission denied + * @throws { BusinessError } 13900013 - Bad address + * @throws { BusinessError } 13900018 - Not a directory + * @throws { BusinessError } 13900019 - Is a directory + * @throws { BusinessError } 13900020 - Invalid argument + * @throws { BusinessError } 13900030 - File name too long + * @throws { BusinessError } 13900031 - Function not implemented + * @throws { BusinessError } 13900033 - Too many symbolic links encountered + * @throws { BusinessError } 13900034 - Operation would block + * @throws { BusinessError } 13900038 - Value too large for defined data type + * @throws { BusinessError } 13900042 - Unknown error + */ +declare function copyFileSync(src: string | number, dest: string | number, mode?: number): void; + +/** + * createStream. + * + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @function createStream + * @param {string} path - path. + * @param {string} mode - mode. + * @param {AsyncCallback} [callback] - callback. + * @returns {void | Promise} no callback return Promise otherwise return Stream + * @throws { BusinessError } 13900001 - Operation not permitted + * @throws { BusinessError } 13900002 - No such file or directory + * @throws { BusinessError } 13900004 - Interrupted system call + * @throws { BusinessError } 13900006 - No such device or address + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900011 - Out of memory + * @throws { BusinessError } 13900012 - Permission denied + * @throws { BusinessError } 13900013 - Bad address + * @throws { BusinessError } 13900014 - Device or resource busy + * @throws { BusinessError } 13900015 - File exists + * @throws { BusinessError } 13900017 - No such device + * @throws { BusinessError } 13900018 - Not a directory + * @throws { BusinessError } 13900019 - Is a directory + * @throws { BusinessError } 13900020 - Invalid argument + * @throws { BusinessError } 13900022 - Too many open files + * @throws { BusinessError } 13900023 - Text file busy + * @throws { BusinessError } 13900024 - File too large + * @throws { BusinessError } 13900025 - No space left on device + * @throws { BusinessError } 13900027 - Read-only file system + * @throws { BusinessError } 13900029 - Resource deadlock would occur + * @throws { BusinessError } 13900030 - File name too long + * @throws { BusinessError } 13900033 - Too many symbolic links encountered + * @throws { BusinessError } 13900034 - Operation would block + * @throws { BusinessError } 13900038 - Value too large for defined data type + * @throws { BusinessError } 13900041 - Quota exceeded + * @throws { BusinessError } 13900042 - Unknown error + */ +declare function createStream(path: string, mode: string, callback?: AsyncCallback): void | Promise; + +/** + * createStreamSync. + * + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @function createStreamSync + * @param {string} path - path. + * @param {string} mode - mode. + * @returns {Stream} createStream + * @throws { BusinessError } 13900001 - Operation not permitted + * @throws { BusinessError } 13900002 - No such file or directory + * @throws { BusinessError } 13900004 - Interrupted system call + * @throws { BusinessError } 13900006 - No such device or address + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900011 - Out of memory + * @throws { BusinessError } 13900012 - Permission denied + * @throws { BusinessError } 13900013 - Bad address + * @throws { BusinessError } 13900014 - Device or resource busy + * @throws { BusinessError } 13900015 - File exists + * @throws { BusinessError } 13900017 - No such device + * @throws { BusinessError } 13900018 - Not a directory + * @throws { BusinessError } 13900019 - Is a directory + * @throws { BusinessError } 13900020 - Invalid argument + * @throws { BusinessError } 13900022 - Too many open files + * @throws { BusinessError } 13900023 - Text file busy + * @throws { BusinessError } 13900024 - File too large + * @throws { BusinessError } 13900025 - No space left on device + * @throws { BusinessError } 13900027 - Read-only file system + * @throws { BusinessError } 13900029 - Resource deadlock would occur + * @throws { BusinessError } 13900030 - File name too long + * @throws { BusinessError } 13900033 - Too many symbolic links encountered + * @throws { BusinessError } 13900034 - Operation would block + * @throws { BusinessError } 13900038 - Value too large for defined data type + * @throws { BusinessError } 13900041 - Quota exceeded + * @throws { BusinessError } 13900042 - Unknown error + */ +declare function createStreamSync(path: string, mode: string): Stream; + +/** + * fdatasync. + * + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @function fdatasync + * @param {number} fd - fd. + * @param {AsyncCallback} [callback] - callback. + * @returns {void | Promise} no callback return Promise otherwise return void + * @throws { BusinessError } 13900005 - I/O error + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900020 - Invalid argument + * @throws { BusinessError } 13900025 - No space left on device + * @throws { BusinessError } 13900027 - Read-only file system + * @throws { BusinessError } 13900041 - Quota exceeded + * @throws { BusinessError } 13900042 - Unknown error + */ +declare function fdatasync(fd: number, callback?: AsyncCallback): void | Promise; +/** + * fdatasyncSync. + * + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @function fdatasyncSync + * @param {number} fd - fd. + * @returns {void} fdatasync success + * @throws { BusinessError } 13900005 - I/O error + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900020 - Invalid argument + * @throws { BusinessError } 13900025 - No space left on device + * @throws { BusinessError } 13900027 - Read-only file system + * @throws { BusinessError } 13900041 - Quota exceeded + * @throws { BusinessError } 13900042 - Unknown error + */ +declare function fdatasyncSync(fd: number): void; + +/** + * fdopenStream. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @function fdopenStream + * @param {number} fd - fd. + * @param {string} mode - mode. + * @param {AsyncCallback} [callback] - callback. + * @returns {void | Promise} no callback return Promise otherwise return void + * @throws { BusinessError } 13900001 - Operation not permitted + * @throws { BusinessError } 13900002 - No such file or directory + * @throws { BusinessError } 13900004 - Interrupted system call + * @throws { BusinessError } 13900006 - No such device or address + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900010 - Try again + * @throws { BusinessError } 13900011 - Out of memory + * @throws { BusinessError } 13900012 - Permission denied + * @throws { BusinessError } 13900013 - Bad address + * @throws { BusinessError } 13900014 - Device or resource busy + * @throws { BusinessError } 13900015 - File exists + * @throws { BusinessError } 13900017 - No such device + * @throws { BusinessError } 13900018 - Not a directory + * @throws { BusinessError } 13900019 - Is a directory + * @throws { BusinessError } 13900020 - Invalid argument + * @throws { BusinessError } 13900022 - Too many open files + * @throws { BusinessError } 13900023 - Text file busy + * @throws { BusinessError } 13900024 - File too large + * @throws { BusinessError } 13900025 - No space left on device + * @throws { BusinessError } 13900027 - Read-only file system + * @throws { BusinessError } 13900029 - Resource deadlock would occur + * @throws { BusinessError } 13900030 - File name too long + * @throws { BusinessError } 13900033 - Too many symbolic links encountered + * @throws { BusinessError } 13900034 - Operation would block + * @throws { BusinessError } 13900038 - Value too large for defined data type + * @throws { BusinessError } 13900041 - Quota exceeded + * @throws { BusinessError } 13900042 - Unknown error + */ +declare function fdopenStream(fd: number, mode: string, callback?: AsyncCallback): void | Promise; +/** + * fdopenStreamSync. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @function fdopenStreamSync + * @param {number} fd - fd. + * @param {string} mode - mode. + * @returns {Stream} open stream from fd + * @throws { BusinessError } 13900001 - Operation not permitted + * @throws { BusinessError } 13900002 - No such file or directory + * @throws { BusinessError } 13900004 - Interrupted system call + * @throws { BusinessError } 13900006 - No such device or address + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900010 - Try again + * @throws { BusinessError } 13900011 - Out of memory + * @throws { BusinessError } 13900012 - Permission denied + * @throws { BusinessError } 13900013 - Bad address + * @throws { BusinessError } 13900014 - Device or resource busy + * @throws { BusinessError } 13900015 - File exists + * @throws { BusinessError } 13900017 - No such device + * @throws { BusinessError } 13900018 - Not a directory + * @throws { BusinessError } 13900019 - Is a directory + * @throws { BusinessError } 13900020 - Invalid argument + * @throws { BusinessError } 13900022 - Too many open files + * @throws { BusinessError } 13900023 - Text file busy + * @throws { BusinessError } 13900024 - File too large + * @throws { BusinessError } 13900025 - No space left on device + * @throws { BusinessError } 13900027 - Read-only file system + * @throws { BusinessError } 13900029 - Resource deadlock would occur + * @throws { BusinessError } 13900030 - File name too long + * @throws { BusinessError } 13900033 - Too many symbolic links encountered + * @throws { BusinessError } 13900034 - Operation would block + * @throws { BusinessError } 13900038 - Value too large for defined data type + * @throws { BusinessError } 13900041 - Quota exceeded + * @throws { BusinessError } 13900042 - Unknown error + */ +declare function fdopenStreamSync(fd: number, mode: string): Stream; + +/** + * fsync. + * + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @function fsync + * @param {number} fd - fd. + * @param {AsyncCallback} [callback] - callback. + * @returns {void | Promise} no callback return Promise otherwise return void + * @throws { BusinessError } 13900005 - I/O error + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900020 - Invalid argument + * @throws { BusinessError } 13900025 - No space left on device + * @throws { BusinessError } 13900027 - Read-only file system + * @throws { BusinessError } 13900041 - Quota exceeded + * @throws { BusinessError } 13900042 - Unknown error + */ +declare function fsync(fd: number, callback?: AsyncCallback): void | Promise; + +/** + * fsyncSync. + * + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @function fsyncSync + * @param {number} fd - fd. + * @returns {void} fsync success + * @throws { BusinessError } 13900005 - I/O error + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900020 - Invalid argument + * @throws { BusinessError } 13900025 - No space left on device + * @throws { BusinessError } 13900027 - Read-only file system + * @throws { BusinessError } 13900041 - Quota exceeded + * @throws { BusinessError } 13900042 - Unknown error + */ +declare function fsyncSync(fd: number): void; + +/** + * lstat. + * + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @function lstat + * @param {string} path - path. + * @param {AsyncCallback} [callback] - callback. + * @returns {void | Promise} no callback return Promise otherwise return void + * @throws { BusinessError } 13900002 - No such file or directory + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900011 - Out of memory + * @throws { BusinessError } 13900012 - Permission denied + * @throws { BusinessError } 13900013 - Bad address + * @throws { BusinessError } 13900018 - Not a directory + * @throws { BusinessError } 13900030 - File name too long + * @throws { BusinessError } 13900033 - Too many symbolic links encountered + * @throws { BusinessError } 13900038 - Value too large for defined data type + * @throws { BusinessError } 13900042 - Unknown error + */ +declare function lstat(path: string, callback?: AsyncCallback): void | Promise; + +/** + * lstatSync. + * + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @function lstatSync + * @param {string} path - path. + * @returns {Stat} lstat success + * @throws { BusinessError } 13900002 - No such file or directory + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900011 - Out of memory + * @throws { BusinessError } 13900012 - Permission denied + * @throws { BusinessError } 13900013 - Bad address + * @throws { BusinessError } 13900018 - Not a directory + * @throws { BusinessError } 13900030 - File name too long + * @throws { BusinessError } 13900033 - Too many symbolic links encountered + * @throws { BusinessError } 13900038 - Value too large for defined data type + * @throws { BusinessError } 13900042 - Unknown error + */ +declare function lstatSync(path: string): Stat; + +/** + * mkdir. + * + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @function mkdir + * @param {string} path - path. + * @param {AsyncCallback} [callback] - callback. + * @returns {void | Promise} no callback return Promise otherwise return void + * @throws { BusinessError } 13900001 - Operation not permitted + * @throws { BusinessError } 13900002 - No such file or directory + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900011 - Out of memory + * @throws { BusinessError } 13900012 - Permission denied + * @throws { BusinessError } 13900013 - Bad address + * @throws { BusinessError } 13900015 - File exists + * @throws { BusinessError } 13900018 - Not a directory + * @throws { BusinessError } 13900020 - Invalid argument + * @throws { BusinessError } 13900025 - No space left on device + * @throws { BusinessError } 13900028 - Too many links + * @throws { BusinessError } 13900030 - File name too long + * @throws { BusinessError } 13900033 - Too many symbolic links encountered + * @throws { BusinessError } 13900041 - Quota exceeded + * @throws { BusinessError } 13900042 - Unknown error + */ +declare function mkdir(path: string, callback?: AsyncCallback): void | Promise; + +/** + * mkdirSync. + * + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @function mkdirSync + * @param {string} path - path. + * @returns {void} mkdir success + * @throws { BusinessError } 13900001 - Operation not permitted + * @throws { BusinessError } 13900002 - No such file or directory + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900011 - Out of memory + * @throws { BusinessError } 13900012 - Permission denied + * @throws { BusinessError } 13900013 - Bad address + * @throws { BusinessError } 13900015 - File exists + * @throws { BusinessError } 13900018 - Not a directory + * @throws { BusinessError } 13900020 - Invalid argument + * @throws { BusinessError } 13900025 - No space left on device + * @throws { BusinessError } 13900028 - Too many links + * @throws { BusinessError } 13900030 - File name too long + * @throws { BusinessError } 13900033 - Too many symbolic links encountered + * @throws { BusinessError } 13900041 - Quota exceeded + * @throws { BusinessError } 13900042 - Unknown error + */ +declare function mkdirSync(path: string): void; + +/** + * mkdtemp. + * + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @function mkdtemp + * @param {string} prefix - dir prefix. + * @param {AsyncCallback} [callback] - callback. + * @returns {void | Promise} no callback return Promise otherwise return void + * @throws { BusinessError } 13900001 - Operation not permitted + * @throws { BusinessError } 13900002 - No such file or directory + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900011 - Out of memory + * @throws { BusinessError } 13900012 - Permission denied + * @throws { BusinessError } 13900013 - Bad address + * @throws { BusinessError } 13900015 - File exists + * @throws { BusinessError } 13900018 - Not a directory + * @throws { BusinessError } 13900020 - Invalid argument + * @throws { BusinessError } 13900025 - No space left on device + * @throws { BusinessError } 13900028 - Too many links + * @throws { BusinessError } 13900030 - File name too long + * @throws { BusinessError } 13900033 - Too many symbolic links encountered + * @throws { BusinessError } 13900041 - Quota exceeded + * @throws { BusinessError } 13900042 - Unknown error + */ +declare function mkdtemp(prefix: string, callback?: AsyncCallback): void | Promise; + +/** + * mkdtempSync. + * + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @function mkdtempSync + * @param {string} prefix - dir prefix. + * @returns {string} directory name + * @throws { BusinessError } 13900001 - Operation not permitted + * @throws { BusinessError } 13900002 - No such file or directory + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900011 - Out of memory + * @throws { BusinessError } 13900012 - Permission denied + * @throws { BusinessError } 13900013 - Bad address + * @throws { BusinessError } 13900015 - File exists + * @throws { BusinessError } 13900018 - Not a directory + * @throws { BusinessError } 13900020 - Invalid argument + * @throws { BusinessError } 13900025 - No space left on device + * @throws { BusinessError } 13900028 - Too many links + * @throws { BusinessError } 13900030 - File name too long + * @throws { BusinessError } 13900033 - Too many symbolic links encountered + * @throws { BusinessError } 13900041 - Quota exceeded + * @throws { BusinessError } 13900042 - Unknown error + */ +declare function mkdtempSync(prefix: string): string; + /** * Open file. * * @syscap SystemCapability.FileManagement.File.FileIO * @since 9 - * @function open - * @param {string} path - path. - * @param {number} [mode = OpenMode.READ_ONLY] - mode. - * @param {AsyncCallback} [callback] - callback. - * @returns {void | Promise} no callback return Promise otherwise return void + * @function open + * @param {string} path - path. + * @param {number} [mode = OpenMode.READ_ONLY] - mode. + * @param {AsyncCallback} [callback] - callback. + * @returns {void | Promise} no callback return Promise otherwise return void + * @throws { BusinessError } 13900001 - Operation not permitted + * @throws { BusinessError } 13900002 - No such file or directory + * @throws { BusinessError } 13900004 - Interrupted system call + * @throws { BusinessError } 13900006 - No such device or address + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900011 - Out of memory + * @throws { BusinessError } 13900012 - Permission denied + * @throws { BusinessError } 13900013 - Bad address + * @throws { BusinessError } 13900014 - Device or resource busy + * @throws { BusinessError } 13900015 - File exists + * @throws { BusinessError } 13900017 - No such device + * @throws { BusinessError } 13900018 - Not a directory + * @throws { BusinessError } 13900019 - Is a directory + * @throws { BusinessError } 13900020 - Invalid argument + * @throws { BusinessError } 13900022 - Too many open files + * @throws { BusinessError } 13900023 - Text file busy + * @throws { BusinessError } 13900024 - File too large + * @throws { BusinessError } 13900025 - No space left on device + * @throws { BusinessError } 13900027 - Read-only file system + * @throws { BusinessError } 13900029 - Resource deadlock would occur + * @throws { BusinessError } 13900030 - File name too long + * @throws { BusinessError } 13900033 - Too many symbolic links encountered + * @throws { BusinessError } 13900034 - Operation would block + * @throws { BusinessError } 13900038 - Value too large for defined data type + * @throws { BusinessError } 13900041 - Quota exceeded + * @throws { BusinessError } 13900042 - Unknown error + */ +declare function open(path: string, mode?: number, callback?: AsyncCallback): void | Promise; + +/** + * Open file with sync interface. + * + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @function openSync + * @param {string} path - path. + * @param {number} [mode = OpenMode.READ_ONLY] - mode. + * @returns {File} open fd + * @throws { BusinessError } 13900001 - Operation not permitted + * @throws { BusinessError } 13900002 - No such file or directory + * @throws { BusinessError } 13900004 - Interrupted system call + * @throws { BusinessError } 13900006 - No such device or address + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900011 - Out of memory + * @throws { BusinessError } 13900012 - Permission denied + * @throws { BusinessError } 13900013 - Bad address + * @throws { BusinessError } 13900014 - Device or resource busy + * @throws { BusinessError } 13900015 - File exists + * @throws { BusinessError } 13900017 - No such device + * @throws { BusinessError } 13900018 - Not a directory + * @throws { BusinessError } 13900019 - Is a directory + * @throws { BusinessError } 13900020 - Invalid argument + * @throws { BusinessError } 13900022 - Too many open files + * @throws { BusinessError } 13900023 - Text file busy + * @throws { BusinessError } 13900024 - File too large + * @throws { BusinessError } 13900025 - No space left on device + * @throws { BusinessError } 13900027 - Read-only file system + * @throws { BusinessError } 13900029 - Resource deadlock would occur + * @throws { BusinessError } 13900030 - File name too long + * @throws { BusinessError } 13900033 - Too many symbolic links encountered + * @throws { BusinessError } 13900034 - Operation would block + * @throws { BusinessError } 13900038 - Value too large for defined data type + * @throws { BusinessError } 13900041 - Quota exceeded + * @throws { BusinessError } 13900042 - Unknown error + */ +declare function openSync(path: string, mode?: number): File; + +/** + * Read file. + * + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @function read + * @param {number} fd - file descriptor. + * @param {ArrayBuffer} buffer - file descriptor. + * @param {Object} [options] - options. + * @param {number} [options.offset = 0] - offset. + * @param {number} [options.length = 0] - length. + * @param {AsyncCallback} [callback] - callback. + * @returns {void | Promise} no callback return Promise otherwise return void + * @throws { BusinessError } 13900004 - Interrupted system call + * @throws { BusinessError } 13900005 - I/O error + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900010 - Try again + * @throws { BusinessError } 13900013 - Bad address + * @throws { BusinessError } 13900019 - Is a directory + * @throws { BusinessError } 13900020 - Invalid argument + * @throws { BusinessError } 13900034 - Operation would block + * @throws { BusinessError } 13900042 - Unknown error + */ +declare function read(fd: number, buffer: ArrayBuffer, options?: { + offset?: number; + length?: number; +}, callback?: AsyncCallback): void | Promise + +/** + * Read file with sync interface. + * + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @function readSync + * @param {number} fd - file descriptor. + * @param {ArrayBuffer} buffer - file descriptor. + * @param {Object} [options] - options. + * @param {number} [options.offset = 0] - offset. + * @param {number} [options.length = 0] - length. + * @returns {number} number of bytesRead + * @throws { BusinessError } 13900004 - Interrupted system call + * @throws { BusinessError } 13900005 - I/O error + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900010 - Try again + * @throws { BusinessError } 13900013 - Bad address + * @throws { BusinessError } 13900019 - Is a directory + * @throws { BusinessError } 13900020 - Invalid argument + * @throws { BusinessError } 13900034 - Operation would block + * @throws { BusinessError } 13900042 - Unknown error + */ +declare function readSync(fd: number, buffer: ArrayBuffer, options?: { + offset?: number; + length?: number; +}): number; + +/** + * readText. + * + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @function readText + * @param {string} filePath - file path. + * @param {Object} [options] - options. + * @param {number} [options.offset = 0] - offset in bytes. + * @param {number} [options.length = 0] - length in bytes. + * @param {number} [options.encoding = 'utf-8'] - encoding. + * @param {AsyncCallback} [callback] - callback. + * @returns {void | Promise} no callback return Promise otherwise return void + * @throws { BusinessError } 13900001 - Operation not permitted + * @throws { BusinessError } 13900004 - Interrupted system call + * @throws { BusinessError } 13900005 - I/O error + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900010 - Try again + * @throws { BusinessError } 13900013 - Bad address + * @throws { BusinessError } 13900019 - Is a directory + * @throws { BusinessError } 13900020 - Invalid argument + * @throws { BusinessError } 13900024 - File too large + * @throws { BusinessError } 13900025 - No space left on device + * @throws { BusinessError } 13900034 - Operation would block + * @throws { BusinessError } 13900041 - Quota exceeded + * @throws { BusinessError } 13900042 - Unknown error + */ + +declare function readText(filePath: string, options?: { + offset?: number; + length?: number; + encoding?: string; +}, callback?: AsyncCallback): void | Promise; + +/** + * readTextSync. + * + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @function readTextSync + * @param {string} filePath - file path. + * @param {Object} [options] - options. + * @param {number} [options.offset = 0] - offset in bytes. + * @param {number} [options.length = 0] - length in bytes. + * @param {number} [options.encoding = 'utf-8'] - encoding. + * @returns {string} readout result * @throws { BusinessError } 13900001 - Operation not permitted - * @throws { BusinessError } 13900002 - No such file or directory * @throws { BusinessError } 13900004 - Interrupted system call - * @throws { BusinessError } 13900006 - No such device or address + * @throws { BusinessError } 13900005 - I/O error + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900010 - Try again + * @throws { BusinessError } 13900013 - Bad address + * @throws { BusinessError } 13900019 - Is a directory + * @throws { BusinessError } 13900020 - Invalid argument + * @throws { BusinessError } 13900024 - File too large + * @throws { BusinessError } 13900025 - No space left on device + * @throws { BusinessError } 13900034 - Operation would block + * @throws { BusinessError } 13900041 - Quota exceeded + * @throws { BusinessError } 13900042 - Unknown error + */ +declare function readTextSync(filePath: string, options?: { + offset?: number; + length?: number; + encoding?: string; +}): string; + +/** + * rename. + * + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @function rename + * @param {string} oldPath - oldPath. + * @param {string} newPath - newPath. + * @param {AsyncCallback} [callback] - callback. + * @returns {void | Promise} no callback return Promise otherwise return void + * @throws { BusinessError } 13900001 - Operation not permitted + * @throws { BusinessError } 13900002 - No such file or directory * @throws { BusinessError } 13900008 - Bad file descriptor * @throws { BusinessError } 13900011 - Out of memory * @throws { BusinessError } 13900012 - Permission denied * @throws { BusinessError } 13900013 - Bad address * @throws { BusinessError } 13900014 - Device or resource busy * @throws { BusinessError } 13900015 - File exists - * @throws { BusinessError } 13900017 - No such device + * @throws { BusinessError } 13900015 - Cross-device link * @throws { BusinessError } 13900018 - Not a directory * @throws { BusinessError } 13900019 - Is a directory * @throws { BusinessError } 13900020 - Invalid argument - * @throws { BusinessError } 13900022 - Too many open files - * @throws { BusinessError } 13900023 - Text file busy - * @throws { BusinessError } 13900024 - File too large * @throws { BusinessError } 13900025 - No space left on device * @throws { BusinessError } 13900027 - Read-only file system - * @throws { BusinessError } 13900029 - Resource deadlock would occur - * @throws { BusinessError } 13900030 - File name too long + * @throws { BusinessError } 13900028 - Too many links + * @throws { BusinessError } 13900032 - Directory not empty * @throws { BusinessError } 13900033 - Too many symbolic links encountered - * @throws { BusinessError } 13900034 - Operation would block - * @throws { BusinessError } 13900038 - Value too large for defined data type * @throws { BusinessError } 13900041 - Quota exceeded * @throws { BusinessError } 13900042 - Unknown error */ -declare function open(path: string, mode?: number): Promise; -declare function open(path: string, callback: AsyncCallback): void; -declare function open(path: string, mode: number, callback: AsyncCallback): void; +declare function rename(oldPath: string, newPath: string, callback?: AsyncCallback): void | Promise; + /** - * Open file with sync interface. + * renameSync. * * @syscap SystemCapability.FileManagement.File.FileIO * @since 9 - * @function openSync - * @param {string} path - path. - * @param {number} [mode = OpenMode.READ_ONLY] - mode. - * @returns {File} open fd + * @function renameSync + * @param {string} oldPath - oldPath. + * @param {string} newPath - newPath. + * @returns {void} rename success * @throws { BusinessError } 13900001 - Operation not permitted * @throws { BusinessError } 13900002 - No such file or directory - * @throws { BusinessError } 13900004 - Interrupted system call - * @throws { BusinessError } 13900006 - No such device or address * @throws { BusinessError } 13900008 - Bad file descriptor * @throws { BusinessError } 13900011 - Out of memory * @throws { BusinessError } 13900012 - Permission denied * @throws { BusinessError } 13900013 - Bad address * @throws { BusinessError } 13900014 - Device or resource busy * @throws { BusinessError } 13900015 - File exists - * @throws { BusinessError } 13900017 - No such device + * @throws { BusinessError } 13900015 - Cross-device link * @throws { BusinessError } 13900018 - Not a directory * @throws { BusinessError } 13900019 - Is a directory * @throws { BusinessError } 13900020 - Invalid argument - * @throws { BusinessError } 13900022 - Too many open files - * @throws { BusinessError } 13900023 - Text file busy - * @throws { BusinessError } 13900024 - File too large * @throws { BusinessError } 13900025 - No space left on device * @throws { BusinessError } 13900027 - Read-only file system - * @throws { BusinessError } 13900029 - Resource deadlock would occur - * @throws { BusinessError } 13900030 - File name too long + * @throws { BusinessError } 13900028 - Too many links + * @throws { BusinessError } 13900032 - Directory not empty * @throws { BusinessError } 13900033 - Too many symbolic links encountered - * @throws { BusinessError } 13900034 - Operation would block - * @throws { BusinessError } 13900038 - Value too large for defined data type * @throws { BusinessError } 13900041 - Quota exceeded * @throws { BusinessError } 13900042 - Unknown error - */ -declare function openSync(path: string, mode?: number): File; + */ +declare function renameSync(oldPath: string, newPath: string): void; /** - * Read file. + * rmdir. * * @syscap SystemCapability.FileManagement.File.FileIO * @since 9 - * @function read - * @param {number} fd - file descriptor. - * @param {ArrayBuffer} buffer - file descriptor. - * @param {Object} [options] - options. - * @param {number} [options.offset = 0] - offset. - * @param {number} [options.length = 0] - length. - * @param {AsyncCallback} [callback] - callback. - * @returns {void | Promise} no callback return Promise otherwise return void - * @throws { BusinessError } 13900004 - Interrupted system call - * @throws { BusinessError } 13900005 - I/O error - * @throws { BusinessError } 13900008 - Bad file descriptor - * @throws { BusinessError } 13900010 - Try again + * @function rmdir + * @param {string} path - path. + * @param {AsyncCallback} [callback] - callback. + * @returns {void | Promise} no callback return Promise otherwise return void + * @throws { BusinessError } 13900001 - Operation not permitted + * @throws { BusinessError } 13900002 - No such file or directory + * @throws { BusinessError } 13900011 - Out of memory + * @throws { BusinessError } 13900012 - Permission denied * @throws { BusinessError } 13900013 - Bad address - * @throws { BusinessError } 13900019 - Is a directory + * @throws { BusinessError } 13900014 - Device or resource busy + * @throws { BusinessError } 13900018 - Not a directory * @throws { BusinessError } 13900020 - Invalid argument - * @throws { BusinessError } 13900034 - Operation would block + * @throws { BusinessError } 13900027 - Read-only file system1 + * @throws { BusinessError } 13900030 - File name too long + * @throws { BusinessError } 13900032 - Directory not empty * @throws { BusinessError } 13900042 - Unknown error */ -declare function read(fd: number, buffer: ArrayBuffer, options?: { - offset?: number; - length?: number; -}): Promise -declare function read(fd: number, buffer: ArrayBuffer, callback: AsyncCallback): void; -declare function read(fd: number, buffer: ArrayBuffer, options: { - offset?: number; - length?: number; -}, callback: AsyncCallback): void; +declare function rmdir(path: string, callback?: AsyncCallback): void | Promise; + /** - * Read file with sync interface. + * rmdirSync. * * @syscap SystemCapability.FileManagement.File.FileIO * @since 9 - * @function readSync - * @param {number} fd - file descriptor. - * @param {ArrayBuffer} buffer - file descriptor. - * @param {Object} [options] - options. - * @param {number} [options.offset = 0] - offset. - * @param {number} [options.length = 0] - length. - * @returns {number} number of bytesRead - * @throws { BusinessError } 13900004 - Interrupted system call - * @throws { BusinessError } 13900005 - I/O error - * @throws { BusinessError } 13900008 - Bad file descriptor - * @throws { BusinessError } 13900010 - Try again + * @function rmdirSync + * @param {string} path - path. + * @returns {void} rmdir success + * @throws { BusinessError } 13900001 - Operation not permitted + * @throws { BusinessError } 13900002 - No such file or directory + * @throws { BusinessError } 13900011 - Out of memory + * @throws { BusinessError } 13900012 - Permission denied * @throws { BusinessError } 13900013 - Bad address - * @throws { BusinessError } 13900019 - Is a directory + * @throws { BusinessError } 13900014 - Device or resource busy + * @throws { BusinessError } 13900018 - Not a directory * @throws { BusinessError } 13900020 - Invalid argument - * @throws { BusinessError } 13900034 - Operation would block + * @throws { BusinessError } 13900027 - Read-only file system1 + * @throws { BusinessError } 13900030 - File name too long + * @throws { BusinessError } 13900032 - Directory not empty * @throws { BusinessError } 13900042 - Unknown error - */ -declare function readSync(fd: number, buffer: ArrayBuffer, options?: { - offset?: number; - length?: number; -}): number; + */ +declare function rmdirSync(path: string): void; /** * Get file information. @@ -214,8 +931,8 @@ declare function readSync(fd: number, buffer: ArrayBuffer, options?: { * @throws { BusinessError } 13900038 - Value too large for defined data type * @throws { BusinessError } 13900042 - Unknown error */ -declare function stat(file: string | number): Promise; -declare function stat(file: string | number, callback: AsyncCallback): void; +declare function stat(file: string | number, callback?: AsyncCallback): void | Promise; + /** * Get file information with sync interface. * @static @@ -239,7 +956,60 @@ declare function stat(file: string | number, callback: AsyncCallback): voi */ declare function statSync(file: string | number): Stat; - /** +/** + * symlink. + * + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @function symlink + * @param {string} target - target. + * @param {string} srcPath - srcPath. + * @param {AsyncCallback} [callback] - callback. + * @returns {void | Promise} no callback return Promise otherwise return void + * @throws { BusinessError } 13900001 - Operation not permitted + * @throws { BusinessError } 13900002 - No such file or directory + * @throws { BusinessError } 13900005 - I/O error + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900011 - Out of memory + * @throws { BusinessError } 13900012 - Permission denied + * @throws { BusinessError } 13900013 - Bad address + * @throws { BusinessError } 13900015 - File exists + * @throws { BusinessError } 13900018 - Not a directory + * @throws { BusinessError } 13900025 - No space left on device + * @throws { BusinessError } 13900027 - Read-only file system + * @throws { BusinessError } 13900030 - File name too long + * @throws { BusinessError } 13900041 - Quota exceeded + * @throws { BusinessError } 13900042 - Unknown error + */ +declare function symlink(target: string, srcPath: string): Promise; +declare function symlink(target: string, srcPath: string, callback: AsyncCallback): void; +/** + * symlinkSync. + * + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @function symlinkSync + * @param {string} target - target. + * @param {string} srcPath - srcPath. + * @returns {void} symlink success + * @throws { BusinessError } 13900001 - Operation not permitted + * @throws { BusinessError } 13900002 - No such file or directory + * @throws { BusinessError } 13900005 - I/O error + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900011 - Out of memory + * @throws { BusinessError } 13900012 - Permission denied + * @throws { BusinessError } 13900013 - Bad address + * @throws { BusinessError } 13900015 - File exists + * @throws { BusinessError } 13900018 - Not a directory + * @throws { BusinessError } 13900025 - No space left on device + * @throws { BusinessError } 13900027 - Read-only file system + * @throws { BusinessError } 13900030 - File name too long + * @throws { BusinessError } 13900041 - Quota exceeded + * @throws { BusinessError } 13900042 - Unknown error + */ +declare function symlinkSync(target: string, srcPath: string): void; + +/** * Truncate file. * * @syscap SystemCapability.FileManagement.File.FileIO @@ -266,9 +1036,8 @@ declare function statSync(file: string | number): Stat; * @throws { BusinessError } 13900033 - Too many symbolic links encountered * @throws { BusinessError } 13900042 - Unknown error */ -declare function truncate(file: string | number, len?: number): Promise; -declare function truncate(file: string | number, callback: AsyncCallback): void; -declare function truncate(file: string | number, len: number, callback: AsyncCallback): void; +declare function truncate(file: string | number, len?: number, callback?: AsyncCallback): void | Promise; + /** * Truncate file with sync interface. * @@ -297,6 +1066,59 @@ declare function truncate(file: string | number, len: number, callback: AsyncCal */ declare function truncateSync(file: string | number, len?: number): void; +/** + * unlink. + * + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @function unlink + * @param {string} path - path. + * @param {AsyncCallback} [callback] - callback. + * @returns {void | Promise} no callback return Promise otherwise return void + * @throws { BusinessError } 13900001 - Operation not permitted + * @throws { BusinessError } 13900002 - No such file or directory + * @throws { BusinessError } 13900005 - I/O error + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900011 - Out of memory + * @throws { BusinessError } 13900012 - Permission denied + * @throws { BusinessError } 13900013 - Bad address + * @throws { BusinessError } 13900014 - Device or resource busy + * @throws { BusinessError } 13900018 - Not a directory + * @throws { BusinessError } 13900019 - Is a directory + * @throws { BusinessError } 13900020 - Invalid argument + * @throws { BusinessError } 13900027 - Read-only file system + * @throws { BusinessError } 13900030 - File name too long + * @throws { BusinessError } 13900033 - Too many symbolic links encountered + * @throws { BusinessError } 13900042 - Unknown error + */ +declare function unlink(path: string, callback?: AsyncCallback): void | Promise; + +/** + * unlinkSync. + * + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @function unlinkSync + * @param {string} path - path. + * @returns {void} unlink success + * @throws { BusinessError } 13900001 - Operation not permitted + * @throws { BusinessError } 13900002 - No such file or directory + * @throws { BusinessError } 13900005 - I/O error + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900011 - Out of memory + * @throws { BusinessError } 13900012 - Permission denied + * @throws { BusinessError } 13900013 - Bad address + * @throws { BusinessError } 13900014 - Device or resource busy + * @throws { BusinessError } 13900018 - Not a directory + * @throws { BusinessError } 13900019 - Is a directory + * @throws { BusinessError } 13900020 - Invalid argument + * @throws { BusinessError } 13900027 - Read-only file system + * @throws { BusinessError } 13900030 - File name too long + * @throws { BusinessError } 13900033 - Too many symbolic links encountered + * @throws { BusinessError } 13900042 - Unknown error + */ +declare function unlinkSync(path: string): void; + /** * Write file. * @@ -328,13 +1150,8 @@ declare function write(fd: number, buffer: ArrayBuffer | string, options?: { offset?: number; length?: number; encoding?: string; -}): Promise; -declare function write(fd: number, buffer: ArrayBuffer | string, callback: AsyncCallback): void; -declare function write(fd: number, buffer: ArrayBuffer | string, options: { - offset?: number; - length?: number; - encoding?: string; -}, callback: AsyncCallback): void; +}, callback?: AsyncCallback): void | Promise; + /** * Write file with sync interface. * @@ -392,6 +1209,8 @@ declare interface Stat { * @syscap SystemCapability.FileManagement.File.FileIO * @since 9 * @readonly + * @throws { BusinessError } 13900005 - I/O error + * @throws { BusinessError } 13900042 - Unknown error */ readonly ino: number; /** @@ -399,6 +1218,8 @@ declare interface Stat { * @syscap SystemCapability.FileManagement.File.FileIO * @since 9 * @readonly + * @throws { BusinessError } 13900005 - I/O error + * @throws { BusinessError } 13900042 - Unknown error */ readonly mode: number; /** @@ -406,6 +1227,10 @@ declare interface Stat { * @syscap SystemCapability.FileManagement.File.FileIO * @since 9 * @readonly + * @throws { BusinessError } 13900005 - I/O error + * @throws { BusinessError } 13900042 - Unknown error + * @throws { BusinessError } 13900005 - I/O error + * @throws { BusinessError } 13900042 - Unknown error */ readonly uid: number; /** @@ -413,6 +1238,8 @@ declare interface Stat { * @syscap SystemCapability.FileManagement.File.FileIO * @since 9 * @readonly + * @throws { BusinessError } 13900005 - I/O error + * @throws { BusinessError } 13900042 - Unknown error */ readonly gid: number; /** @@ -420,6 +1247,8 @@ declare interface Stat { * @syscap SystemCapability.FileManagement.File.FileIO * @since 9 * @readonly + * @throws { BusinessError } 13900005 - I/O error + * @throws { BusinessError } 13900042 - Unknown error */ readonly size: number; /** @@ -427,6 +1256,8 @@ declare interface Stat { * @syscap SystemCapability.FileManagement.File.FileIO * @since 9 * @readonly + * @throws { BusinessError } 13900005 - I/O error + * @throws { BusinessError } 13900042 - Unknown error */ readonly atime: number; /** @@ -434,6 +1265,8 @@ declare interface Stat { * @syscap SystemCapability.FileManagement.File.FileIO * @since 9 * @readonly + * @throws { BusinessError } 13900005 - I/O error + * @throws { BusinessError } 13900042 - Unknown error */ readonly mtime: number; /** @@ -441,6 +1274,8 @@ declare interface Stat { * @syscap SystemCapability.FileManagement.File.FileIO * @since 9 * @readonly + * @throws { BusinessError } 13900005 - I/O error + * @throws { BusinessError } 13900042 - Unknown error */ readonly ctime: number; /** @@ -448,6 +1283,8 @@ declare interface Stat { * @syscap SystemCapability.FileManagement.File.FileIO * @since 9 * @returns {boolean} is or not + * @throws { BusinessError } 13900005 - I/O error + * @throws { BusinessError } 13900042 - Unknown error */ isBlockDevice(): boolean; /** @@ -455,6 +1292,8 @@ declare interface Stat { * @syscap SystemCapability.FileManagement.File.FileIO * @since 9 * @returns {boolean} is or not + * @throws { BusinessError } 13900005 - I/O error + * @throws { BusinessError } 13900042 - Unknown error */ isCharacterDevice(): boolean; /** @@ -462,6 +1301,8 @@ declare interface Stat { * @syscap SystemCapability.FileManagement.File.FileIO * @since 9 * @returns {boolean} is or not + * @throws { BusinessError } 13900005 - I/O error + * @throws { BusinessError } 13900042 - Unknown error */ isDirectory(): boolean; /** @@ -469,6 +1310,8 @@ declare interface Stat { * @syscap SystemCapability.FileManagement.File.FileIO * @since 9 * @returns {boolean} is or not + * @throws { BusinessError } 13900005 - I/O error + * @throws { BusinessError } 13900042 - Unknown error */ isFIFO(): boolean; /** @@ -476,6 +1319,8 @@ declare interface Stat { * @syscap SystemCapability.FileManagement.File.FileIO * @since 9 * @returns {boolean} is or not + * @throws { BusinessError } 13900005 - I/O error + * @throws { BusinessError } 13900042 - Unknown error */ isFile(): boolean; /** @@ -483,6 +1328,8 @@ declare interface Stat { * @syscap SystemCapability.FileManagement.File.FileIO * @since 9 * @returns {boolean} is or not + * @throws { BusinessError } 13900005 - I/O error + * @throws { BusinessError } 13900042 - Unknown error */ isSocket(): boolean; /** @@ -490,6 +1337,195 @@ declare interface Stat { * @syscap SystemCapability.FileManagement.File.FileIO * @since 9 * @returns {boolean} is or not + * @throws { BusinessError } 13900005 - I/O error + * @throws { BusinessError } 13900042 - Unknown error */ isSymbolicLink(): boolean; } + +/** + * Stream + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + */ +declare interface Stream { + /** + * close. + * + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @param {AsyncCallback} [callback] - callback. + * @returns {void | Promise} close success + * @throws { BusinessError } 13900004 - Interrupted system call + * @throws { BusinessError } 13900005 - I/O error + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900025 - No space left on device + * @throws { BusinessError } 13900041 - Quota exceeded + * @throws { BusinessError } 13900042 - Unknown error + * + */ + close(callback?: AsyncCallback): void | Promise; + /** + * closeSync. + * + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @returns {void} close success + * @throws { BusinessError } 13900004 - Interrupted system call + * @throws { BusinessError } 13900005 - I/O error + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900025 - No space left on device + * @throws { BusinessError } 13900041 - Quota exceeded + * @throws { BusinessError } 13900042 - Unknown error + */ + closeSync(): void; + /** + * flush. + * + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @param {AsyncCallback} [callback] - callback. + * @returns {void | Promise} no callback return Promise otherwise return void + * @throws { BusinessError } 13900001 - Operation not permitted + * @throws { BusinessError } 13900004 - Interrupted system call + * @throws { BusinessError } 13900005 - I/O error + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900010 - Try again + * @throws { BusinessError } 13900013 - Bad address + * @throws { BusinessError } 13900020 - Invalid argument + * @throws { BusinessError } 13900024 - File too large + * @throws { BusinessError } 13900025 - No space left on device + * @throws { BusinessError } 13900034 - Operation would block + * @throws { BusinessError } 13900041 - Quota exceeded + * @throws { BusinessError } 13900042 - Unknown error + */ + flush(callback?: AsyncCallback): void | Promise; + /** + * flushSync. + * + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @returns {void} flush success + * @throws { BusinessError } 13900001 - Operation not permitted + * @throws { BusinessError } 13900004 - Interrupted system call + * @throws { BusinessError } 13900005 - I/O error + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900010 - Try again + * @throws { BusinessError } 13900013 - Bad address + * @throws { BusinessError } 13900020 - Invalid argument + * @throws { BusinessError } 13900024 - File too large + * @throws { BusinessError } 13900025 - No space left on device + * @throws { BusinessError } 13900034 - Operation would block + * @throws { BusinessError } 13900041 - Quota exceeded + * @throws { BusinessError } 13900042 - Unknown error + */ + flushSync(): void; + /** + * write. + * + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @param {ArrayBuffer | string} buffer - file description. + * @param {Object} [options] - options. + * @param {number} [options.length = 0] - length(bytes) ignored when buffer is string. + * @param {number} [options.offset = 0] - offset(bytes) where start to write < 0 use read, else use pread. + * @param {string} [options.encoding = 'utf-8'] - encoding. + * @param {AsyncCallback} [callback] - callback. + * @returns {void | Promise} no callback return Promise otherwise return void + * @throws { BusinessError } 13900001 - Operation not permitted + * @throws { BusinessError } 13900004 - Interrupted system call + * @throws { BusinessError } 13900005 - I/O error + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900010 - Try again + * @throws { BusinessError } 13900013 - Bad address + * @throws { BusinessError } 13900020 - Invalid argument + * @throws { BusinessError } 13900024 - File too large + * @throws { BusinessError } 13900025 - No space left on device + * @throws { BusinessError } 13900034 - Operation would block + * @throws { BusinessError } 13900041 - Quota exceeded + * @throws { BusinessError } 13900042 - Unknown error + */ + write(buffer: ArrayBuffer | string, options?: { + offset?: number; + length?: number; + encoding?: string; + }, callback?: AsyncCallback): void | Promise; + /** + * writeSync. + * + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @param {ArrayBuffer | string} buffer - file description. + * @param {Object} [options] - options. + * @param {number} [options.length = 0] - length(bytes) ignored when buffer is string. + * @param {number} [options.offset = 0] - offset(bytes) where start to write < 0 use read, else use pread. + * @param {string} [options.encoding = 'utf-8'] - encoding. + * @returns {number} on success number of bytes written + * @throws { BusinessError } 13900001 - Operation not permitted + * @throws { BusinessError } 13900004 - Interrupted system call + * @throws { BusinessError } 13900005 - I/O error + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900010 - Try again + * @throws { BusinessError } 13900013 - Bad address + * @throws { BusinessError } 13900020 - Invalid argument + * @throws { BusinessError } 13900024 - File too large + * @throws { BusinessError } 13900025 - No space left on device + * @throws { BusinessError } 13900034 - Operation would block + * @throws { BusinessError } 13900041 - Quota exceeded + * @throws { BusinessError } 13900042 - Unknown error + */ + writeSync(buffer: ArrayBuffer | string, options?: { + offset?: number; + length?: number; + encoding?: string; + }): number; + /** + * read. + * + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @param {ArrayBuffer} buffer - file description. + * @param {Object} [options] - options. + * @param {number} [options.offset = 0] - offset. + * @param {number} [options.length = 0] - length. + * @param {AsyncCallback} [callback] - callback. + * @returns {void | Promise} no callback return Promise otherwise return void + * @throws { BusinessError } 13900004 - Interrupted system call + * @throws { BusinessError } 13900005 - I/O error + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900010 - Try again + * @throws { BusinessError } 13900013 - Bad address + * @throws { BusinessError } 13900019 - Is a directory + * @throws { BusinessError } 13900020 - Invalid argument + * @throws { BusinessError } 13900034 - Operation would block + * @throws { BusinessError } 13900042 - Unknown error + */ + read(buffer: ArrayBuffer, options?: { + offset?: number; + length?: number; + }, callback?: AsyncCallback): void | Promise; + /** + * readSync. + * + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @param {ArrayBuffer} buffer - file description. + * @param {Object} [options] - options. + * @param {number} [options.offset = 0] - offset. + * @param {number} [options.length = 0] - length. + * @returns {number} number of bytesRead + * @throws { BusinessError } 13900004 - Interrupted system call + * @throws { BusinessError } 13900005 - I/O error + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900010 - Try again + * @throws { BusinessError } 13900013 - Bad address + * @throws { BusinessError } 13900019 - Is a directory + * @throws { BusinessError } 13900020 - Invalid argument + * @throws { BusinessError } 13900034 - Operation would block + * @throws { BusinessError } 13900042 - Unknown error + */ + readSync(buffer: ArrayBuffer, options?: { + offset?: number; + length?: number; + }): number; +} diff --git a/api/@ohos.file.hash.d.ts b/api/@ohos.file.hash.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..fc44d598deba31e568f9aa406a422cfc7331679f --- /dev/null +++ b/api/@ohos.file.hash.d.ts @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { AsyncCallback } from './basic' + +export default Hash; + +/** + * Hash + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + */ +declare namespace Hash { + export { hash }; +} + + /** + * hash. + * @static + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @function hash + * @param {string} path - path. + * @param {string} algorithm - algorithm md5 sha1 sha256. + * @param {AsyncCallback} [callback] - callback. + * @returns {void | Promise} no callback return Promise otherwise return void + * @throws {BusinessError} Parameter check failed + */ + declare function hash(path: string, algorithm: string): Promise; + declare function hash(path: string, algorithm: string, callback: AsyncCallback): void; \ No newline at end of file diff --git a/api/@ohos.fileio.d.ts b/api/@ohos.fileio.d.ts index beaf544455ddbcfd0091975b20e618331752932e..be7a93c235fb80196ecc71f15d102ddc02a89d98 100644 --- a/api/@ohos.fileio.d.ts +++ b/api/@ohos.fileio.d.ts @@ -94,6 +94,8 @@ declare namespace fileIO { * * @syscap SystemCapability.FileManagement.File.FileIO * @since 6 + * @deprecated since 9 + * @useinstead ohos.file.fs.access * @permission N/A * @function access * @param {string} path - path. @@ -110,6 +112,8 @@ declare function access(path: string, mode: number, callback: AsyncCallback): void; * * @syscap SystemCapability.FileManagement.File.FileIO * @since 6 + * @deprecated since 9 + * @useinstead ohos.file.fs.closeSync * @permission N/A * @function closeSync * @param {number} fd - fd. @@ -149,6 +157,8 @@ declare function closeSync(fd: number): void; * * @syscap SystemCapability.FileManagement.File.FileIO * @since 6 + * @deprecated since 9 + * @useinstead ohos.file.fs.copyFile * @permission N/A * @function copyFile * @param {string | number} src - src. @@ -166,6 +176,8 @@ declare function copyFile(src: string | number, dest: string | number, mode: num * * @syscap SystemCapability.FileManagement.File.FileIO * @since 6 + * @deprecated since 9 + * @useinstead ohos.file.fs.copyFileSync * @permission N/A * @function copyFileSync * @param {string | number} src - src. @@ -180,6 +192,8 @@ declare function copyFileSync(src: string | number, dest: string | number, mode? * * @syscap SystemCapability.FileManagement.File.FileIO * @since 7 + * @deprecated since 9 + * @useinstead ohos.file.fs.createStream * @permission N/A * @function createStream * @param {string} path - path. @@ -195,6 +209,8 @@ declare function createStream(path: string, mode: string, callback: AsyncCallbac * * @syscap SystemCapability.FileManagement.File.FileIO * @since 7 + * @deprecated since 9 + * @useinstead ohos.file.fs.createStreamSync * @permission N/A * @function createStreamSync * @param {string} path - path. @@ -208,6 +224,7 @@ declare function createStreamSync(path: string, mode: string): Stream; * * @syscap SystemCapability.FileManagement.File.FileIO * @since 7 + * @deprecated since 9 * @permission N/A * @function appendFile * @param {string} path - path. @@ -224,6 +241,7 @@ declare function chown(path: string, uid: number, gid: number, callback: AsyncCa * * @syscap SystemCapability.FileManagement.File.FileIO * @since 7 + * @deprecated since 9 * @permission N/A * @function appendFile * @param {string} path - path. @@ -238,6 +256,7 @@ declare function chownSync(path: string, uid: number, gid: number): void; * * @syscap SystemCapability.FileManagement.File.FileIO * @since 7 + * @deprecated since 9 * @permission N/A * @function chmod * @param {string} path - path. @@ -253,6 +272,7 @@ declare function chmod(path: string, mode: number, callback: AsyncCallback * * @syscap SystemCapability.FileManagement.File.FileIO * @since 7 + * @deprecated since 9 * @permission N/A * @function chmodSync * @param {string} path - path. @@ -297,6 +317,8 @@ declare function ftruncateSync(fd: number, len?: number): void; * * @syscap SystemCapability.FileManagement.File.FileIO * @since 7 + * @deprecated since 9 + * @useinstead ohos.file.fs.fsync * @permission N/A * @function fsync * @param {number} fd - fd. @@ -311,6 +333,8 @@ declare function fsync(fd: number, callback: AsyncCallback): void; * * @syscap SystemCapability.FileManagement.File.FileIO * @since 7 + * @deprecated since 9 + * @useinstead ohos.file.fs.fsyncSync * @permission N/A * @function fsyncSync * @param {number} fd - fd. @@ -350,6 +374,8 @@ declare function fstatSync(fd: number): Stat; * * @syscap SystemCapability.FileManagement.File.FileIO * @since 7 + * @deprecated since 9 + * @useinstead ohos.file.fs.fdatasync * @permission N/A * @function fdatasync * @param {number} fd - fd. @@ -364,6 +390,8 @@ declare function fdatasync(fd: number, callback: AsyncCallback): void; * * @syscap SystemCapability.FileManagement.File.FileIO * @since 7 + * @deprecated since 9 + * @useinstead ohos.file.fs.fdatasyncSync * @permission N/A * @function fdatasyncSync * @param {number} fd - fd. @@ -376,6 +404,7 @@ declare function fdatasyncSync(fd: number): void; * * @syscap SystemCapability.FileManagement.File.FileIO * @since 7 + * @deprecated since 9 * @permission N/A * @function fchown * @param {number} fd - fd. @@ -392,6 +421,7 @@ declare function fchown(fd: number, uid: number, gid: number, callback: AsyncCal * * @syscap SystemCapability.FileManagement.File.FileIO * @since 7 + * @deprecated since 9 * @permission N/A * @function fchownSync * @param {number} fd - fd. @@ -406,6 +436,7 @@ declare function fchownSync(fd: number, uid: number, gid: number): void; * * @syscap SystemCapability.FileManagement.File.FileIO * @since 7 + * @deprecated since 9 * @permission N/A * @function fchmod * @param {number} fd - fd. @@ -421,6 +452,7 @@ declare function fchmod(fd: number, mode: number, callback: AsyncCallback) * * @syscap SystemCapability.FileManagement.File.FileIO * @since 7 + * @deprecated since 9 * @permission N/A * @function fchmodSync * @param {number} fd - fd. @@ -433,6 +465,8 @@ declare function fchmodSync(fd: number, mode: number): void; * fdopenStream. * @syscap SystemCapability.FileManagement.File.FileIO * @since 7 + * @deprecated since 9 + * @useinstead ohos.file.fs.fdopenStream * @permission N/A * @function fdopenStream * @param {number} fd - fd. @@ -447,6 +481,8 @@ declare function fdopenStream(fd: number, mode: string, callback: AsyncCallback< * fdopenStreamSync. * @syscap SystemCapability.FileManagement.File.FileIO * @since 7 + * @deprecated since 9 + * @useinstead ohos.file.fs.fdopenStreamSync * @permission N/A * @function fdopenStreamSync * @param {number} fd - fd. @@ -460,6 +496,8 @@ declare function fdopenStreamSync(fd: number, mode: string): Stream; * @static * @syscap SystemCapability.FileManagement.File.FileIO * @since 6 + * @deprecated since 9 + * @useinstead ohos.file.hash.hash * @permission N/A * @function hash * @param {string} path - path. @@ -475,6 +513,7 @@ declare function hash(path: string, algorithm: string, callback: AsyncCallback): void; * * @syscap SystemCapability.FileManagement.File.FileIO * @since 7 + * @deprecated since 9 + * @useinstead ohos.file.fs.lstatSync * @permission N/A * @function lstatSync * @param {string} path - path. @@ -531,6 +575,8 @@ declare function lstatSync(path: string): Stat; * * @syscap SystemCapability.FileManagement.File.FileIO * @since 6 + * @deprecated since 9 + * @useinstead ohos.file.fs.mkdir * @permission N/A * @function mkdir * @param {string} path - path. @@ -547,6 +593,8 @@ declare function mkdir(path: string, mode: number, callback: AsyncCallback * * @syscap SystemCapability.FileManagement.File.FileIO * @since 6 + * @deprecated since 9 + * @useinstead ohos.file.fs.mkdirSync * @permission N/A * @function mkdirSync * @param {string} path - path. @@ -560,6 +608,8 @@ declare function mkdirSync(path: string, mode?: number): void; * * @syscap SystemCapability.FileManagement.File.FileIO * @since 7 + * @deprecated since 9 + * @useinstead ohos.file.fs.mkdtemp * @permission N/A * @function mkdtemp * @param {string} prefix - dir prefix. @@ -574,6 +624,8 @@ declare function mkdtemp(prefix: string, callback: AsyncCallback): void; * * @syscap SystemCapability.FileManagement.File.FileIO * @since 7 + * @deprecated since 9 + * @useinstead ohos.file.fs.mkdtempSync * @permission N/A * @function mkdtempSync * @param {string} prefix - dir prefix. @@ -642,6 +694,8 @@ declare function opendirSync(path: string): Dir; * * @syscap SystemCapability.FileManagement.File.FileIO * @since 7 + * @deprecated since 9 + * @useinstead ohos.file.fs.readText * @permission N/A * @function readText * @param {string} filePath - file path. @@ -669,6 +723,8 @@ declare function readText(filePath: string, options: { * * @syscap SystemCapability.FileManagement.File.FileIO * @since 7 + * @deprecated since 9 + * @useinstead ohos.file.fs.readTextSync * @permission N/A * @function readTextSync * @param {string} filePath - file path. @@ -741,6 +797,8 @@ declare function readSync(fd: number, buffer: ArrayBuffer, options?: { * * @syscap SystemCapability.FileManagement.File.FileIO * @since 7 + * @deprecated since 9 + * @useinstead ohos.file.fs.rename * @permission N/A * @function rename * @param {string} oldPath - oldPath. @@ -756,6 +814,8 @@ declare function rename(oldPath: string, newPath: string, callback: AsyncCallbac * * @syscap SystemCapability.FileManagement.File.FileIO * @since 7 + * @deprecated since 9 + * @useinstead ohos.file.fs.renameSync * @permission N/A * @function renameSync * @param {string} oldPath - oldPath. @@ -769,6 +829,8 @@ declare function renameSync(oldPath: string, newPath: string): void; * * @syscap SystemCapability.FileManagement.File.FileIO * @since 7 + * @deprecated since 9 + * @useinstead ohos.file.fs.rmdir * @permission N/A * @function rmdir * @param {string} path - path. @@ -783,6 +845,8 @@ declare function rmdir(path: string, callback: AsyncCallback): void; * * @syscap SystemCapability.FileManagement.File.FileIO * @since 7 + * @deprecated since 9 + * @useinstead ohos.file.fs.rmdirSync * @permission N/A * @function rmdirSync * @param {string} path - path. @@ -821,6 +885,8 @@ declare function statSync(path: string): Stat; * * @syscap SystemCapability.FileManagement.File.FileIO * @since 7 + * @deprecated since 9 + * @useinstead ohos.file.fs.symlink * @permission N/A * @function symlink * @param {string} target - target. @@ -836,6 +902,8 @@ declare function symlink(target: string, srcPath: string, callback: AsyncCallbac * * @syscap SystemCapability.FileManagement.File.FileIO * @since 7 + * @deprecated since 9 + * @useinstead ohos.file.fs.symlinkSync * @permission N/A * @function symlinkSync * @param {string} target - target. @@ -880,6 +948,8 @@ declare function truncateSync(path: string, len?: number): void; * * @syscap SystemCapability.FileManagement.File.FileIO * @since 6 + * @deprecated since 9 + * @useinstead ohos.file.fs.unlink * @permission N/A * @function unlink * @param {string} path - path. @@ -894,6 +964,8 @@ declare function unlink(path: string, callback: AsyncCallback): void; * * @syscap SystemCapability.FileManagement.File.FileIO * @since 6 + * @deprecated since 9 + * @useinstead ohos.file.fs.unlinkSync * @permission N/A * @function unlinkSync * @param {string} path - path. @@ -1316,6 +1388,8 @@ declare interface Stat { * Stream * @syscap SystemCapability.FileManagement.File.FileIO * @since 6 + * @deprecated since 9 + * @useinstead ohos.file.fs.Stream * @permission N/A */ declare interface Stream {