1/* 2 * Copyright (c) 2022-2023 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 */ 15import { AsyncCallback } from './basic' 16 17export default fileIo; 18 19/** 20 * FileIO 21 * @syscap SystemCapability.FileManagement.File.FileIO 22 * @since 9 23 */ 24declare namespace fileIo { 25 export { access }; 26 export { accessSync }; 27 export { close }; 28 export { closeSync }; 29 export { copyFile }; 30 export { copyFileSync }; 31 export { createStream }; 32 export { createStreamSync }; 33 export { fdatasync }; 34 export { fdatasyncSync }; 35 export { fdopenStream }; 36 export { fdopenStreamSync }; 37 export { fsync }; 38 export { fsyncSync }; 39 export { listFile }; 40 export { listFileSync }; 41 export { lstat }; 42 export { lstatSync }; 43 export { mkdir }; 44 export { mkdirSync }; 45 export { mkdtemp }; 46 export { mkdtempSync }; 47 export { moveFile } 48 export { moveFileSync } 49 export { open }; 50 export { openSync }; 51 export { read }; 52 export { readSync }; 53 export { readText }; 54 export { readTextSync }; 55 export { rename }; 56 export { renameSync }; 57 export { rmdir }; 58 export { rmdirSync }; 59 export { stat }; 60 export { statSync }; 61 export { symlink }; 62 export { symlinkSync }; 63 export { truncate }; 64 export { truncateSync }; 65 export { unlink }; 66 export { unlinkSync }; 67 export { write }; 68 export { writeSync }; 69 export { File }; 70 export { OpenMode }; 71 export { Stat }; 72 export { Stream }; 73 74 /** 75 * Mode Indicates the open flags. 76 * @since 9 77 * @syscap SystemCapability.FileManagement.File.FileIO 78 */ 79 namespace OpenMode { 80 const READ_ONLY = 0o0; // Read only Permission 81 const WRITE_ONLY = 0o1; // Write only Permission 82 const READ_WRITE = 0o2; // Write and Read Permission 83 const CREATE = 0o100; // If not exist, create file 84 const TRUNC = 0o1000; // File truncate len 0 85 const APPEND = 0o2000; // File append write 86 const NONBLOCK = 0o4000; // File open in nonblocking mode 87 const DIR = 0o200000; // File is Dir 88 const NOFOLLOW = 0o400000; // File is not symbolic link 89 const SYNC = 0o4010000; // SYNC IO 90 } 91} 92 93/** 94 * Access file. 95 * 96 * @syscap SystemCapability.FileManagement.File.FileIO 97 * @since 9 98 * @param {string} path - path. 99 * @param {AsyncCallback<boolean>} [callback] - callback. 100 * @returns {void | Promise<boolean>} no callback return Promise otherwise return void 101 * @throws { BusinessError } 13900002 - No such file or directory 102 * @throws { BusinessError } 13900005 - I/O error 103 * @throws { BusinessError } 13900008 - Bad file descriptor 104 * @throws { BusinessError } 13900011 - Out of memory 105 * @throws { BusinessError } 13900012 - Permission denied 106 * @throws { BusinessError } 13900013 - Bad address 107 * @throws { BusinessError } 13900018 - Not a directory 108 * @throws { BusinessError } 13900020 - Invalid argument 109 * @throws { BusinessError } 13900023 - Text file busy 110 * @throws { BusinessError } 13900030 - File name too long 111 * @throws { BusinessError } 13900033 - Too many symbolic links encountered 112 * @throws { BusinessError } 13900042 - Unknown error 113 */ 114declare function access(path: string): Promise<boolean>; 115declare function access(path: string, callback: AsyncCallback<boolean>): void; 116 117/** 118 * Access file with sync interface. 119 * @syscap SystemCapability.FileManagement.File.FileIO 120 * @since 9 121 * @param {string} path - path. 122 * @returns {boolean} access success 123 * @throws { BusinessError } 13900002 - No such file or directory 124 * @throws { BusinessError } 13900005 - I/O error 125 * @throws { BusinessError } 13900008 - Bad file descriptor 126 * @throws { BusinessError } 13900011 - Out of memory 127 * @throws { BusinessError } 13900012 - Permission denied 128 * @throws { BusinessError } 13900013 - Bad address 129 * @throws { BusinessError } 13900018 - Not a directory 130 * @throws { BusinessError } 13900020 - Invalid argument 131 * @throws { BusinessError } 13900023 - Text file busy 132 * @throws { BusinessError } 13900030 - File name too long 133 * @throws { BusinessError } 13900033 - Too many symbolic links encountered 134 * @throws { BusinessError } 13900042 - Unknown error 135 */ 136declare function accessSync(path: string): boolean; 137 138/** 139 * Close file or fd. 140 * 141 * @syscap SystemCapability.FileManagement.File.FileIO 142 * @since 9 143 * @param {number | File} file - file object or fd. 144 * @param {AsyncCallback<void>} [callback] - callback. 145 * @returns {void | Promise<void>} no callback return Promise otherwise return void 146 * @throws { BusinessError } 13900004 - Interrupted system call 147 * @throws { BusinessError } 13900005 - I/O error 148 * @throws { BusinessError } 13900008 - Bad file descriptor 149 * @throws { BusinessError } 13900025 - No space left on device 150 * @throws { BusinessError } 13900041 - Quota exceeded 151 * @throws { BusinessError } 13900042 - Unknown error 152 */ 153declare function close(file: number | File): Promise<void>; 154declare function close(file: number | File, callback: AsyncCallback<void>): void; 155 156/** 157 * Close file or fd with sync interface. 158 * 159 * @syscap SystemCapability.FileManagement.File.FileIO 160 * @since 9 161 * @permission N/A 162 * @param {number | File} file - file object or fd. 163 * @returns {void} close success 164 * @throws { BusinessError } 13900004 - Interrupted system call 165 * @throws { BusinessError } 13900005 - I/O error 166 * @throws { BusinessError } 13900008 - Bad file descriptor 167 * @throws { BusinessError } 13900025 - No space left on device 168 * @throws { BusinessError } 13900041 - Quota exceeded 169 * @throws { BusinessError } 13900042 - Unknown error 170 */ 171declare function closeSync(fd: number | File): void; 172 173/** 174 * Copy file. 175 * 176 * @syscap SystemCapability.FileManagement.File.FileIO 177 * @since 9 178 * @param {string | number} src - src. 179 * @param {string | number} dest - dest. 180 * @param {number} [mode = 0] - mode. 181 * @param {AsyncCallback<void>} [callback] - callback. 182 * @returns {void | Promise<void>} no callback return Promise otherwise return void 183 * @throws { BusinessError } 13900002 - No such file or directory 184 * @throws { BusinessError } 13900004 - Interrupted system call 185 * @throws { BusinessError } 13900005 - I/O error 186 * @throws { BusinessError } 13900008 - Bad file descriptor 187 * @throws { BusinessError } 13900010 - Try again 188 * @throws { BusinessError } 13900011 - Out of memory 189 * @throws { BusinessError } 13900012 - Permission denied 190 * @throws { BusinessError } 13900013 - Bad address 191 * @throws { BusinessError } 13900018 - Not a directory 192 * @throws { BusinessError } 13900019 - Is a directory 193 * @throws { BusinessError } 13900020 - Invalid argument 194 * @throws { BusinessError } 13900030 - File name too long 195 * @throws { BusinessError } 13900031 - Function not implemented 196 * @throws { BusinessError } 13900033 - Too many symbolic links encountered 197 * @throws { BusinessError } 13900034 - Operation would block 198 * @throws { BusinessError } 13900038 - Value too large for defined data type 199 * @throws { BusinessError } 13900042 - Unknown error 200 */ 201declare function copyFile(src: string | number, dest: string | number, mode?: number): Promise<void>; 202declare function copyFile(src: string | number, dest: string | number, callback: AsyncCallback<void>): void; 203declare function copyFile(src: string | number, dest: string | number, mode: number, callback: AsyncCallback<void>): void; 204 205/** 206 * Copy file with sync interface. 207 * 208 * @syscap SystemCapability.FileManagement.File.FileIO 209 * @since 9 210 * @param {string | number} src - src. 211 * @param {string | number} dest - dest. 212 * @param {number} [mode = 0] - mode. 213 * @returns {void} copyFile success 214 * @throws { BusinessError } 13900002 - No such file or directory 215 * @throws { BusinessError } 13900004 - Interrupted system call 216 * @throws { BusinessError } 13900005 - I/O error 217 * @throws { BusinessError } 13900008 - Bad file descriptor 218 * @throws { BusinessError } 13900010 - Try again 219 * @throws { BusinessError } 13900011 - Out of memory 220 * @throws { BusinessError } 13900012 - Permission denied 221 * @throws { BusinessError } 13900013 - Bad address 222 * @throws { BusinessError } 13900018 - Not a directory 223 * @throws { BusinessError } 13900019 - Is a directory 224 * @throws { BusinessError } 13900020 - Invalid argument 225 * @throws { BusinessError } 13900030 - File name too long 226 * @throws { BusinessError } 13900031 - Function not implemented 227 * @throws { BusinessError } 13900033 - Too many symbolic links encountered 228 * @throws { BusinessError } 13900034 - Operation would block 229 * @throws { BusinessError } 13900038 - Value too large for defined data type 230 * @throws { BusinessError } 13900042 - Unknown error 231 */ 232declare function copyFileSync(src: string | number, dest: string | number, mode?: number): void; 233 234/** 235 * Create class Stream. 236 * 237 * @syscap SystemCapability.FileManagement.File.FileIO 238 * @since 9 239 * @param {string} path - path. 240 * @param {string} mode - mode. 241 * @param {AsyncCallback<Stream>} [callback] - callback. 242 * @returns {void | Promise<Stream>} no callback return Promise otherwise return Stream 243 * @throws { BusinessError } 13900001 - Operation not permitted 244 * @throws { BusinessError } 13900002 - No such file or directory 245 * @throws { BusinessError } 13900004 - Interrupted system call 246 * @throws { BusinessError } 13900006 - No such device or address 247 * @throws { BusinessError } 13900008 - Bad file descriptor 248 * @throws { BusinessError } 13900011 - Out of memory 249 * @throws { BusinessError } 13900012 - Permission denied 250 * @throws { BusinessError } 13900013 - Bad address 251 * @throws { BusinessError } 13900014 - Device or resource busy 252 * @throws { BusinessError } 13900015 - File exists 253 * @throws { BusinessError } 13900017 - No such device 254 * @throws { BusinessError } 13900018 - Not a directory 255 * @throws { BusinessError } 13900019 - Is a directory 256 * @throws { BusinessError } 13900020 - Invalid argument 257 * @throws { BusinessError } 13900022 - Too many open files 258 * @throws { BusinessError } 13900023 - Text file busy 259 * @throws { BusinessError } 13900024 - File too large 260 * @throws { BusinessError } 13900025 - No space left on device 261 * @throws { BusinessError } 13900027 - Read-only file system 262 * @throws { BusinessError } 13900029 - Resource deadlock would occur 263 * @throws { BusinessError } 13900030 - File name too long 264 * @throws { BusinessError } 13900033 - Too many symbolic links encountered 265 * @throws { BusinessError } 13900034 - Operation would block 266 * @throws { BusinessError } 13900038 - Value too large for defined data type 267 * @throws { BusinessError } 13900041 - Quota exceeded 268 * @throws { BusinessError } 13900042 - Unknown error 269 */ 270declare function createStream(path: string, mode: string): Promise<Stream>; 271declare function createStream(path: string, mode: string, callback: AsyncCallback<Stream>): void; 272 273/** 274 * Create class Stream with sync interface. 275 * 276 * @syscap SystemCapability.FileManagement.File.FileIO 277 * @since 9 278 * @param {string} path - path. 279 * @param {string} mode - mode. 280 * @returns {Stream} createStream 281 * @throws { BusinessError } 13900001 - Operation not permitted 282 * @throws { BusinessError } 13900002 - No such file or directory 283 * @throws { BusinessError } 13900004 - Interrupted system call 284 * @throws { BusinessError } 13900006 - No such device or address 285 * @throws { BusinessError } 13900008 - Bad file descriptor 286 * @throws { BusinessError } 13900011 - Out of memory 287 * @throws { BusinessError } 13900012 - Permission denied 288 * @throws { BusinessError } 13900013 - Bad address 289 * @throws { BusinessError } 13900014 - Device or resource busy 290 * @throws { BusinessError } 13900015 - File exists 291 * @throws { BusinessError } 13900017 - No such device 292 * @throws { BusinessError } 13900018 - Not a directory 293 * @throws { BusinessError } 13900019 - Is a directory 294 * @throws { BusinessError } 13900020 - Invalid argument 295 * @throws { BusinessError } 13900022 - Too many open files 296 * @throws { BusinessError } 13900023 - Text file busy 297 * @throws { BusinessError } 13900024 - File too large 298 * @throws { BusinessError } 13900025 - No space left on device 299 * @throws { BusinessError } 13900027 - Read-only file system 300 * @throws { BusinessError } 13900029 - Resource deadlock would occur 301 * @throws { BusinessError } 13900030 - File name too long 302 * @throws { BusinessError } 13900033 - Too many symbolic links encountered 303 * @throws { BusinessError } 13900034 - Operation would block 304 * @throws { BusinessError } 13900038 - Value too large for defined data type 305 * @throws { BusinessError } 13900041 - Quota exceeded 306 * @throws { BusinessError } 13900042 - Unknown error 307 */ 308declare function createStreamSync(path: string, mode: string): Stream; 309 310/** 311 * Synchronize file metadata. 312 * 313 * @syscap SystemCapability.FileManagement.File.FileIO 314 * @since 9 315 * @param {number} fd - fd. 316 * @param {AsyncCallback<void>} [callback] - callback. 317 * @returns {void | Promise<void>} no callback return Promise otherwise return void 318 * @throws { BusinessError } 13900005 - I/O error 319 * @throws { BusinessError } 13900008 - Bad file descriptor 320 * @throws { BusinessError } 13900020 - Invalid argument 321 * @throws { BusinessError } 13900025 - No space left on device 322 * @throws { BusinessError } 13900027 - Read-only file system 323 * @throws { BusinessError } 13900041 - Quota exceeded 324 * @throws { BusinessError } 13900042 - Unknown error 325 */ 326declare function fdatasync(fd: number): Promise<void>; 327declare function fdatasync(fd: number, callback: AsyncCallback<void>): void; 328 329/** 330 * Synchronize file metadata with sync interface. 331 * 332 * @syscap SystemCapability.FileManagement.File.FileIO 333 * @since 9 334 * @param {number} fd - fd. 335 * @returns {void} fdatasync success 336 * @throws { BusinessError } 13900005 - I/O error 337 * @throws { BusinessError } 13900008 - Bad file descriptor 338 * @throws { BusinessError } 13900020 - Invalid argument 339 * @throws { BusinessError } 13900025 - No space left on device 340 * @throws { BusinessError } 13900027 - Read-only file system 341 * @throws { BusinessError } 13900041 - Quota exceeded 342 * @throws { BusinessError } 13900042 - Unknown error 343 */ 344declare function fdatasyncSync(fd: number): void; 345 346/** 347 * Create class Stream by using fd. 348 * @syscap SystemCapability.FileManagement.File.FileIO 349 * @since 9 350 * @param {number} fd - fd. 351 * @param {string} mode - mode. 352 * @param {AsyncCallback<Stream>} [callback] - callback. 353 * @returns {void | Promise<Stream>} no callback return Promise otherwise return void 354 * @throws { BusinessError } 13900001 - Operation not permitted 355 * @throws { BusinessError } 13900002 - No such file or directory 356 * @throws { BusinessError } 13900004 - Interrupted system call 357 * @throws { BusinessError } 13900006 - No such device or address 358 * @throws { BusinessError } 13900008 - Bad file descriptor 359 * @throws { BusinessError } 13900010 - Try again 360 * @throws { BusinessError } 13900011 - Out of memory 361 * @throws { BusinessError } 13900012 - Permission denied 362 * @throws { BusinessError } 13900013 - Bad address 363 * @throws { BusinessError } 13900014 - Device or resource busy 364 * @throws { BusinessError } 13900015 - File exists 365 * @throws { BusinessError } 13900017 - No such device 366 * @throws { BusinessError } 13900018 - Not a directory 367 * @throws { BusinessError } 13900019 - Is a directory 368 * @throws { BusinessError } 13900020 - Invalid argument 369 * @throws { BusinessError } 13900022 - Too many open files 370 * @throws { BusinessError } 13900023 - Text file busy 371 * @throws { BusinessError } 13900024 - File too large 372 * @throws { BusinessError } 13900025 - No space left on device 373 * @throws { BusinessError } 13900027 - Read-only file system 374 * @throws { BusinessError } 13900029 - Resource deadlock would occur 375 * @throws { BusinessError } 13900030 - File name too long 376 * @throws { BusinessError } 13900033 - Too many symbolic links encountered 377 * @throws { BusinessError } 13900034 - Operation would block 378 * @throws { BusinessError } 13900038 - Value too large for defined data type 379 * @throws { BusinessError } 13900041 - Quota exceeded 380 * @throws { BusinessError } 13900042 - Unknown error 381 */ 382declare function fdopenStream(fd: number, mode: string): Promise<Stream>; 383declare function fdopenStream(fd: number, mode: string, callback: AsyncCallback<Stream>): void; 384 385/** 386 * Create class Stream by using fd with sync interface. 387 * @syscap SystemCapability.FileManagement.File.FileIO 388 * @since 9 389 * @param {number} fd - fd. 390 * @param {string} mode - mode. 391 * @returns {Stream} open stream from fd 392 * @throws { BusinessError } 13900001 - Operation not permitted 393 * @throws { BusinessError } 13900002 - No such file or directory 394 * @throws { BusinessError } 13900004 - Interrupted system call 395 * @throws { BusinessError } 13900006 - No such device or address 396 * @throws { BusinessError } 13900008 - Bad file descriptor 397 * @throws { BusinessError } 13900010 - Try again 398 * @throws { BusinessError } 13900011 - Out of memory 399 * @throws { BusinessError } 13900012 - Permission denied 400 * @throws { BusinessError } 13900013 - Bad address 401 * @throws { BusinessError } 13900014 - Device or resource busy 402 * @throws { BusinessError } 13900015 - File exists 403 * @throws { BusinessError } 13900017 - No such device 404 * @throws { BusinessError } 13900018 - Not a directory 405 * @throws { BusinessError } 13900019 - Is a directory 406 * @throws { BusinessError } 13900020 - Invalid argument 407 * @throws { BusinessError } 13900022 - Too many open files 408 * @throws { BusinessError } 13900023 - Text file busy 409 * @throws { BusinessError } 13900024 - File too large 410 * @throws { BusinessError } 13900025 - No space left on device 411 * @throws { BusinessError } 13900027 - Read-only file system 412 * @throws { BusinessError } 13900029 - Resource deadlock would occur 413 * @throws { BusinessError } 13900030 - File name too long 414 * @throws { BusinessError } 13900033 - Too many symbolic links encountered 415 * @throws { BusinessError } 13900034 - Operation would block 416 * @throws { BusinessError } 13900038 - Value too large for defined data type 417 * @throws { BusinessError } 13900041 - Quota exceeded 418 * @throws { BusinessError } 13900042 - Unknown error 419 */ 420declare function fdopenStreamSync(fd: number, mode: string): Stream; 421 422/** 423 * Synchronize file. 424 * 425 * @syscap SystemCapability.FileManagement.File.FileIO 426 * @since 9 427 * @param {number} fd - fd. 428 * @param {AsyncCallback<void>} [callback] - callback. 429 * @returns {void | Promise<void>} no callback return Promise otherwise return void 430 * @throws { BusinessError } 13900005 - I/O error 431 * @throws { BusinessError } 13900008 - Bad file descriptor 432 * @throws { BusinessError } 13900020 - Invalid argument 433 * @throws { BusinessError } 13900025 - No space left on device 434 * @throws { BusinessError } 13900027 - Read-only file system 435 * @throws { BusinessError } 13900041 - Quota exceeded 436 * @throws { BusinessError } 13900042 - Unknown error 437 */ 438declare function fsync(fd: number): Promise<void>; 439declare function fsync(fd: number, callback: AsyncCallback<void>): void; 440 441/** 442 * Synchronize file with sync interface. 443 * 444 * @syscap SystemCapability.FileManagement.File.FileIO 445 * @since 9 446 * @param {number} fd - fd. 447 * @returns {void} fsync success 448 * @throws { BusinessError } 13900005 - I/O error 449 * @throws { BusinessError } 13900008 - Bad file descriptor 450 * @throws { BusinessError } 13900020 - Invalid argument 451 * @throws { BusinessError } 13900025 - No space left on device 452 * @throws { BusinessError } 13900027 - Read-only file system 453 * @throws { BusinessError } 13900041 - Quota exceeded 454 * @throws { BusinessError } 13900042 - Unknown error 455 */ 456declare function fsyncSync(fd: number): void; 457 458/** 459 * List file. 460 * 461 * @syscap SystemCapability.FileManagement.File.FileIO 462 * @since 9 463 * @param {string} path - path. 464 * @param {Object} [options] - options. 465 * @param {boolean} [options.recursion = false] - whether to list recursively 466 * @param {number} [options.listNum = 0] - the number of listing file. 467 * @param {Filter} [options.filter] - file filter. 468 * @returns {Promise<string[]>} return Promise 469 * @throws { BusinessError } 13900002 - No such file or directory 470 * @throws { BusinessError } 13900008 - Bad file descriptor 471 * @throws { BusinessError } 13900011 - Out of memory 472 * @throws { BusinessError } 13900018 - Not a directory 473 * @throws { BusinessError } 13900042 - Unknown error 474 */ 475declare function listFile(path: string, options?: { 476 recursion?: boolean; 477 listNum?: number; 478 filter?: Filter; 479}): Promise<string[]>; 480 481/** 482 * List file. 483 * 484 * @syscap SystemCapability.FileManagement.File.FileIO 485 * @since 9 486 * @param {string} path - path. 487 * @param {Object} [options] - options. 488 * @param {boolean} [options.recursion = false] - whether to list recursively 489 * @param {number} [options.listNum = 0] - the number of listing file. 490 * @param {Filter} [options.filter] - file filter. 491 * @param {AsyncCallback<string[]>} callback - callback. 492 * @throws { BusinessError } 13900002 - No such file or directory 493 * @throws { BusinessError } 13900008 - Bad file descriptor 494 * @throws { BusinessError } 13900011 - Out of memory 495 * @throws { BusinessError } 13900018 - Not a directory 496 * @throws { BusinessError } 13900042 - Unknown error 497 */ 498declare function listFile(path: string, callback: AsyncCallback<string[]>): void; 499declare function listFile(path: string, options: { 500 recursion?: boolean; 501 listNum?: number; 502 filter?: Filter; 503}, callback: AsyncCallback<string[]>): void; 504 505/** 506 * List file with sync interface. 507 * 508 * @syscap SystemCapability.FileManagement.File.FileIO 509 * @since 9 510 * @param {string} path - path. 511 * @param {Object} [options] - options. 512 * @param {boolean} [options.recursion = false] - whether to list recursively 513 * @param {number} [options.listNum = 0] - the number of listing file. 514 * @param {Filter} [options.filter] - file filter. 515 * @returns {string[]} array of file name 516 * @throws { BusinessError } 13900002 - No such file or directory 517 * @throws { BusinessError } 13900008 - Bad file descriptor 518 * @throws { BusinessError } 13900011 - Out of memory 519 * @throws { BusinessError } 13900018 - Not a directory 520 * @throws { BusinessError } 13900042 - Unknown error 521 */ 522declare function listFileSync(path: string, options?: { 523 recursion?: boolean; 524 listNum?: number; 525 filter?: Filter; 526}): string[]; 527 528/** 529 * Stat link file. 530 * 531 * @syscap SystemCapability.FileManagement.File.FileIO 532 * @since 9 533 * @param {string} path - path. 534 * @param {AsyncCallback<Stat>} [callback] - callback. 535 * @returns {void | Promise<Stat>} no callback return Promise otherwise return void 536 * @throws { BusinessError } 13900002 - No such file or directory 537 * @throws { BusinessError } 13900008 - Bad file descriptor 538 * @throws { BusinessError } 13900011 - Out of memory 539 * @throws { BusinessError } 13900012 - Permission denied 540 * @throws { BusinessError } 13900013 - Bad address 541 * @throws { BusinessError } 13900018 - Not a directory 542 * @throws { BusinessError } 13900030 - File name too long 543 * @throws { BusinessError } 13900033 - Too many symbolic links encountered 544 * @throws { BusinessError } 13900038 - Value too large for defined data type 545 * @throws { BusinessError } 13900042 - Unknown error 546 */ 547declare function lstat(path: string): Promise<Stat>; 548declare function lstat(path: string, callback: AsyncCallback<Stat>): void; 549 550/** 551 * Stat link file with sync interface. 552 * 553 * @syscap SystemCapability.FileManagement.File.FileIO 554 * @since 9 555 * @param {string} path - path. 556 * @returns {Stat} lstat success 557 * @throws { BusinessError } 13900002 - No such file or directory 558 * @throws { BusinessError } 13900008 - Bad file descriptor 559 * @throws { BusinessError } 13900011 - Out of memory 560 * @throws { BusinessError } 13900012 - Permission denied 561 * @throws { BusinessError } 13900013 - Bad address 562 * @throws { BusinessError } 13900018 - Not a directory 563 * @throws { BusinessError } 13900030 - File name too long 564 * @throws { BusinessError } 13900033 - Too many symbolic links encountered 565 * @throws { BusinessError } 13900038 - Value too large for defined data type 566 * @throws { BusinessError } 13900042 - Unknown error 567 */ 568declare function lstatSync(path: string): Stat; 569 570/** 571 * Make dir. 572 * 573 * @syscap SystemCapability.FileManagement.File.FileIO 574 * @since 9 575 * @param {string} path - path. 576 * @param {AsyncCallback<void>} [callback] - callback. 577 * @returns {void | Promise<void>} no callback return Promise otherwise return void 578 * @throws { BusinessError } 13900001 - Operation not permitted 579 * @throws { BusinessError } 13900002 - No such file or directory 580 * @throws { BusinessError } 13900008 - Bad file descriptor 581 * @throws { BusinessError } 13900011 - Out of memory 582 * @throws { BusinessError } 13900012 - Permission denied 583 * @throws { BusinessError } 13900013 - Bad address 584 * @throws { BusinessError } 13900015 - File exists 585 * @throws { BusinessError } 13900018 - Not a directory 586 * @throws { BusinessError } 13900020 - Invalid argument 587 * @throws { BusinessError } 13900025 - No space left on device 588 * @throws { BusinessError } 13900028 - Too many links 589 * @throws { BusinessError } 13900030 - File name too long 590 * @throws { BusinessError } 13900033 - Too many symbolic links encountered 591 * @throws { BusinessError } 13900041 - Quota exceeded 592 * @throws { BusinessError } 13900042 - Unknown error 593 */ 594declare function mkdir(path: string): Promise<void>; 595declare function mkdir(path: string, callback: AsyncCallback<void>): void; 596 597/** 598 * Make dir with sync interface. 599 * 600 * @syscap SystemCapability.FileManagement.File.FileIO 601 * @since 9 602 * @param {string} path - path. 603 * @returns {void} mkdir success 604 * @throws { BusinessError } 13900001 - Operation not permitted 605 * @throws { BusinessError } 13900002 - No such file or directory 606 * @throws { BusinessError } 13900008 - Bad file descriptor 607 * @throws { BusinessError } 13900011 - Out of memory 608 * @throws { BusinessError } 13900012 - Permission denied 609 * @throws { BusinessError } 13900013 - Bad address 610 * @throws { BusinessError } 13900015 - File exists 611 * @throws { BusinessError } 13900018 - Not a directory 612 * @throws { BusinessError } 13900020 - Invalid argument 613 * @throws { BusinessError } 13900025 - No space left on device 614 * @throws { BusinessError } 13900028 - Too many links 615 * @throws { BusinessError } 13900030 - File name too long 616 * @throws { BusinessError } 13900033 - Too many symbolic links encountered 617 * @throws { BusinessError } 13900041 - Quota exceeded 618 * @throws { BusinessError } 13900042 - Unknown error 619 */ 620declare function mkdirSync(path: string): void; 621 622/** 623 * Make temp dir. 624 * 625 * @syscap SystemCapability.FileManagement.File.FileIO 626 * @since 9 627 * @param {string} prefix - dir prefix. 628 * @param {AsyncCallback<string>} [callback] - callback. 629 * @returns {void | Promise<string>} no callback return Promise otherwise return void 630 * @throws { BusinessError } 13900001 - Operation not permitted 631 * @throws { BusinessError } 13900002 - No such file or directory 632 * @throws { BusinessError } 13900008 - Bad file descriptor 633 * @throws { BusinessError } 13900011 - Out of memory 634 * @throws { BusinessError } 13900012 - Permission denied 635 * @throws { BusinessError } 13900013 - Bad address 636 * @throws { BusinessError } 13900015 - File exists 637 * @throws { BusinessError } 13900018 - Not a directory 638 * @throws { BusinessError } 13900020 - Invalid argument 639 * @throws { BusinessError } 13900025 - No space left on device 640 * @throws { BusinessError } 13900028 - Too many links 641 * @throws { BusinessError } 13900030 - File name too long 642 * @throws { BusinessError } 13900033 - Too many symbolic links encountered 643 * @throws { BusinessError } 13900041 - Quota exceeded 644 * @throws { BusinessError } 13900042 - Unknown error 645 */ 646declare function mkdtemp(prefix: string): Promise<string>; 647declare function mkdtemp(prefix: string, callback: AsyncCallback<string>): void; 648 649/** 650 * Make temp dir with sync interface. 651 * 652 * @syscap SystemCapability.FileManagement.File.FileIO 653 * @since 9 654 * @param {string} prefix - dir prefix. 655 * @returns {string} directory name 656 * @throws { BusinessError } 13900001 - Operation not permitted 657 * @throws { BusinessError } 13900002 - No such file or directory 658 * @throws { BusinessError } 13900008 - Bad file descriptor 659 * @throws { BusinessError } 13900011 - Out of memory 660 * @throws { BusinessError } 13900012 - Permission denied 661 * @throws { BusinessError } 13900013 - Bad address 662 * @throws { BusinessError } 13900015 - File exists 663 * @throws { BusinessError } 13900018 - Not a directory 664 * @throws { BusinessError } 13900020 - Invalid argument 665 * @throws { BusinessError } 13900025 - No space left on device 666 * @throws { BusinessError } 13900028 - Too many links 667 * @throws { BusinessError } 13900030 - File name too long 668 * @throws { BusinessError } 13900033 - Too many symbolic links encountered 669 * @throws { BusinessError } 13900041 - Quota exceeded 670 * @throws { BusinessError } 13900042 - Unknown error 671 */ 672declare function mkdtempSync(prefix: string): string; 673 674/** 675 * Move file. 676 * 677 * @syscap SystemCapability.FileManagement.File.FileIO 678 * @since 9 679 * @param {string} src - source file path. 680 * @param {string} dest - destination file path. 681 * @param {number} [mode = 0] - move mode when duplicate file name exists. 682 * @returns {Promise<void>} return Promise 683 * @throws { BusinessError } 13900001 - Operation not permitted 684 * @throws { BusinessError } 13900002 - No such file or directory 685 * @throws { BusinessError } 13900008 - Bad file descriptor 686 * @throws { BusinessError } 13900011 - Out of memory 687 * @throws { BusinessError } 13900012 - Permission denied 688 * @throws { BusinessError } 13900013 - Bad address 689 * @throws { BusinessError } 13900014 - Device or resource busy 690 * @throws { BusinessError } 13900015 - File exists 691 * @throws { BusinessError } 13900015 - Cross-device link 692 * @throws { BusinessError } 13900018 - Not a directory 693 * @throws { BusinessError } 13900019 - Is a directory 694 * @throws { BusinessError } 13900020 - Invalid argument 695 * @throws { BusinessError } 13900025 - No space left on device 696 * @throws { BusinessError } 13900027 - Read-only file system 697 * @throws { BusinessError } 13900028 - Too many links 698 * @throws { BusinessError } 13900032 - Directory not empty 699 * @throws { BusinessError } 13900033 - Too many symbolic links encountered 700 * @throws { BusinessError } 13900041 - Quota exceeded 701 * @throws { BusinessError } 13900042 - Unknown error 702 */ 703declare function moveFile(src: string, dest: string, mode?: number): Promise<void>; 704 705/** 706 * Move file. 707 * 708 * @syscap SystemCapability.FileManagement.File.FileIO 709 * @since 9 710 * @param {string} src - source file path. 711 * @param {string} dest - destination file path. 712 * @param {number} [mode = 0] - move mode when duplicate file name exists. 713 * @param {AsyncCallback<void>} callback - callback. 714 * @throws { BusinessError } 13900001 - Operation not permitted 715 * @throws { BusinessError } 13900002 - No such file or directory 716 * @throws { BusinessError } 13900008 - Bad file descriptor 717 * @throws { BusinessError } 13900011 - Out of memory 718 * @throws { BusinessError } 13900012 - Permission denied 719 * @throws { BusinessError } 13900013 - Bad address 720 * @throws { BusinessError } 13900014 - Device or resource busy 721 * @throws { BusinessError } 13900015 - File exists 722 * @throws { BusinessError } 13900015 - Cross-device link 723 * @throws { BusinessError } 13900018 - Not a directory 724 * @throws { BusinessError } 13900019 - Is a directory 725 * @throws { BusinessError } 13900020 - Invalid argument 726 * @throws { BusinessError } 13900025 - No space left on device 727 * @throws { BusinessError } 13900027 - Read-only file system 728 * @throws { BusinessError } 13900028 - Too many links 729 * @throws { BusinessError } 13900032 - Directory not empty 730 * @throws { BusinessError } 13900033 - Too many symbolic links encountered 731 * @throws { BusinessError } 13900041 - Quota exceeded 732 * @throws { BusinessError } 13900042 - Unknown error 733 */ 734declare function moveFile(src: string, dest: string, callback: AsyncCallback<void>): void; 735declare function moveFile(src: string, dest: string, mode: number, callback: AsyncCallback<void>): void; 736 737/** 738 * Move file with sync interface. 739 * 740 * @syscap SystemCapability.FileManagement.File.FileIO 741 * @since 9 742 * @param {string} src - source file path. 743 * @param {string} dest - destination file path. 744 * @param {number} [mode = 0] - move mode when duplicate file name exists. 745 * @returns {void} move success 746 * @throws { BusinessError } 13900001 - Operation not permitted 747 * @throws { BusinessError } 13900002 - No such file or directory 748 * @throws { BusinessError } 13900008 - Bad file descriptor 749 * @throws { BusinessError } 13900011 - Out of memory 750 * @throws { BusinessError } 13900012 - Permission denied 751 * @throws { BusinessError } 13900013 - Bad address 752 * @throws { BusinessError } 13900014 - Device or resource busy 753 * @throws { BusinessError } 13900015 - File exists 754 * @throws { BusinessError } 13900015 - Cross-device link 755 * @throws { BusinessError } 13900018 - Not a directory 756 * @throws { BusinessError } 13900019 - Is a directory 757 * @throws { BusinessError } 13900020 - Invalid argument 758 * @throws { BusinessError } 13900025 - No space left on device 759 * @throws { BusinessError } 13900027 - Read-only file system 760 * @throws { BusinessError } 13900028 - Too many links 761 * @throws { BusinessError } 13900032 - Directory not empty 762 * @throws { BusinessError } 13900033 - Too many symbolic links encountered 763 * @throws { BusinessError } 13900041 - Quota exceeded 764 * @throws { BusinessError } 13900042 - Unknown error 765 */ 766declare function moveFileSync(src: string, dest: string, mode?: number): void; 767 768/** 769 * Open file. 770 * 771 * @syscap SystemCapability.FileManagement.File.FileIO 772 * @since 9 773 * @param {string} path - path. 774 * @param {number} [mode = OpenMode.READ_ONLY] - mode. 775 * @param {AsyncCallback<File>} [callback] - callback. 776 * @returns {void | Promise<File>} no callback return Promise otherwise return void 777 * @throws { BusinessError } 13900001 - Operation not permitted 778 * @throws { BusinessError } 13900002 - No such file or directory 779 * @throws { BusinessError } 13900004 - Interrupted system call 780 * @throws { BusinessError } 13900006 - No such device or address 781 * @throws { BusinessError } 13900008 - Bad file descriptor 782 * @throws { BusinessError } 13900011 - Out of memory 783 * @throws { BusinessError } 13900012 - Permission denied 784 * @throws { BusinessError } 13900013 - Bad address 785 * @throws { BusinessError } 13900014 - Device or resource busy 786 * @throws { BusinessError } 13900015 - File exists 787 * @throws { BusinessError } 13900017 - No such device 788 * @throws { BusinessError } 13900018 - Not a directory 789 * @throws { BusinessError } 13900019 - Is a directory 790 * @throws { BusinessError } 13900020 - Invalid argument 791 * @throws { BusinessError } 13900022 - Too many open files 792 * @throws { BusinessError } 13900023 - Text file busy 793 * @throws { BusinessError } 13900024 - File too large 794 * @throws { BusinessError } 13900025 - No space left on device 795 * @throws { BusinessError } 13900027 - Read-only file system 796 * @throws { BusinessError } 13900029 - Resource deadlock would occur 797 * @throws { BusinessError } 13900030 - File name too long 798 * @throws { BusinessError } 13900033 - Too many symbolic links encountered 799 * @throws { BusinessError } 13900034 - Operation would block 800 * @throws { BusinessError } 13900038 - Value too large for defined data type 801 * @throws { BusinessError } 13900041 - Quota exceeded 802 * @throws { BusinessError } 13900042 - Unknown error 803 */ 804declare function open(path: string, mode?: number): Promise<File>; 805declare function open(path: string, callback: AsyncCallback<File>): void; 806declare function open(path: string, mode: number, callback: AsyncCallback<File>): void; 807 808/** 809 * Open file with sync interface. 810 * 811 * @syscap SystemCapability.FileManagement.File.FileIO 812 * @since 9 813 * @param {string} path - path. 814 * @param {number} [mode = OpenMode.READ_ONLY] - mode. 815 * @returns {File} open fd 816 * @throws { BusinessError } 13900001 - Operation not permitted 817 * @throws { BusinessError } 13900002 - No such file or directory 818 * @throws { BusinessError } 13900004 - Interrupted system call 819 * @throws { BusinessError } 13900006 - No such device or address 820 * @throws { BusinessError } 13900008 - Bad file descriptor 821 * @throws { BusinessError } 13900011 - Out of memory 822 * @throws { BusinessError } 13900012 - Permission denied 823 * @throws { BusinessError } 13900013 - Bad address 824 * @throws { BusinessError } 13900014 - Device or resource busy 825 * @throws { BusinessError } 13900015 - File exists 826 * @throws { BusinessError } 13900017 - No such device 827 * @throws { BusinessError } 13900018 - Not a directory 828 * @throws { BusinessError } 13900019 - Is a directory 829 * @throws { BusinessError } 13900020 - Invalid argument 830 * @throws { BusinessError } 13900022 - Too many open files 831 * @throws { BusinessError } 13900023 - Text file busy 832 * @throws { BusinessError } 13900024 - File too large 833 * @throws { BusinessError } 13900025 - No space left on device 834 * @throws { BusinessError } 13900027 - Read-only file system 835 * @throws { BusinessError } 13900029 - Resource deadlock would occur 836 * @throws { BusinessError } 13900030 - File name too long 837 * @throws { BusinessError } 13900033 - Too many symbolic links encountered 838 * @throws { BusinessError } 13900034 - Operation would block 839 * @throws { BusinessError } 13900038 - Value too large for defined data type 840 * @throws { BusinessError } 13900041 - Quota exceeded 841 * @throws { BusinessError } 13900042 - Unknown error 842 */ 843declare function openSync(path: string, mode?: number): File; 844 845/** 846 * Read file. 847 * 848 * @syscap SystemCapability.FileManagement.File.FileIO 849 * @since 9 850 * @param {number} fd - file descriptor. 851 * @param {ArrayBuffer} buffer - file descriptor. 852 * @param {Object} [options] - options. 853 * @param {number} [options.offset = 0] - offset. 854 * @param {number} [options.length = 0] - length. 855 * @param {AsyncCallback<number>} [callback] - callback. 856 * @returns {void | Promise<number>} no callback return Promise otherwise return void 857 * @throws { BusinessError } 13900004 - Interrupted system call 858 * @throws { BusinessError } 13900005 - I/O error 859 * @throws { BusinessError } 13900008 - Bad file descriptor 860 * @throws { BusinessError } 13900010 - Try again 861 * @throws { BusinessError } 13900013 - Bad address 862 * @throws { BusinessError } 13900019 - Is a directory 863 * @throws { BusinessError } 13900020 - Invalid argument 864 * @throws { BusinessError } 13900034 - Operation would block 865 * @throws { BusinessError } 13900042 - Unknown error 866 */ 867declare function read(fd: number, buffer: ArrayBuffer, options?: { 868 offset?: number; 869 length?: number; 870}): Promise<number>; 871declare function read(fd: number, buffer: ArrayBuffer, callback: AsyncCallback<number>): void; 872declare function read(fd: number, buffer: ArrayBuffer, options: { 873 offset?: number; 874 length?: number; 875}, callback: AsyncCallback<number>): void; 876 877/** 878 * Read file with sync interface. 879 * 880 * @syscap SystemCapability.FileManagement.File.FileIO 881 * @since 9 882 * @param {number} fd - file descriptor. 883 * @param {ArrayBuffer} buffer - file descriptor. 884 * @param {Object} [options] - options. 885 * @param {number} [options.offset = 0] - offset. 886 * @param {number} [options.length = 0] - length. 887 * @returns {number} number of bytesRead 888 * @throws { BusinessError } 13900004 - Interrupted system call 889 * @throws { BusinessError } 13900005 - I/O error 890 * @throws { BusinessError } 13900008 - Bad file descriptor 891 * @throws { BusinessError } 13900010 - Try again 892 * @throws { BusinessError } 13900013 - Bad address 893 * @throws { BusinessError } 13900019 - Is a directory 894 * @throws { BusinessError } 13900020 - Invalid argument 895 * @throws { BusinessError } 13900034 - Operation would block 896 * @throws { BusinessError } 13900042 - Unknown error 897 */ 898declare function readSync(fd: number, buffer: ArrayBuffer, options?: { 899 offset?: number; 900 length?: number; 901}): number; 902 903/** 904 * Read text. 905 * 906 * @syscap SystemCapability.FileManagement.File.FileIO 907 * @since 9 908 * @param {string} filePath - file path. 909 * @param {Object} [options] - options. 910 * @param {number} [options.offset = 0] - offset in bytes. 911 * @param {number} [options.length = 0] - length in bytes. 912 * @param {number} [options.encoding = 'utf-8'] - encoding. 913 * @param {AsyncCallback<string>} [callback] - callback. 914 * @returns {void | Promise<string>} no callback return Promise otherwise return void 915 * @throws { BusinessError } 13900001 - Operation not permitted 916 * @throws { BusinessError } 13900004 - Interrupted system call 917 * @throws { BusinessError } 13900005 - I/O error 918 * @throws { BusinessError } 13900008 - Bad file descriptor 919 * @throws { BusinessError } 13900010 - Try again 920 * @throws { BusinessError } 13900013 - Bad address 921 * @throws { BusinessError } 13900019 - Is a directory 922 * @throws { BusinessError } 13900020 - Invalid argument 923 * @throws { BusinessError } 13900024 - File too large 924 * @throws { BusinessError } 13900025 - No space left on device 925 * @throws { BusinessError } 13900034 - Operation would block 926 * @throws { BusinessError } 13900041 - Quota exceeded 927 * @throws { BusinessError } 13900042 - Unknown error 928 */ 929 930declare function readText(filePath: string, options?: { 931 offset?: number; 932 length?: number; 933 encoding?: string; 934}): Promise<string>; 935declare function readText(filePath: string, callback: AsyncCallback<string>): void; 936declare function readText(filePath: string, options: { 937 offset?: number; 938 length?: number; 939 encoding?: string; 940}, callback: AsyncCallback<string>): void; 941 942/** 943 * Read text with sync interface. 944 * 945 * @syscap SystemCapability.FileManagement.File.FileIO 946 * @since 9 947 * @param {string} filePath - file path. 948 * @param {Object} [options] - options. 949 * @param {number} [options.offset = 0] - offset in bytes. 950 * @param {number} [options.length = 0] - length in bytes. 951 * @param {number} [options.encoding = 'utf-8'] - encoding. 952 * @returns {string} readout result 953 * @throws { BusinessError } 13900001 - Operation not permitted 954 * @throws { BusinessError } 13900004 - Interrupted system call 955 * @throws { BusinessError } 13900005 - I/O error 956 * @throws { BusinessError } 13900008 - Bad file descriptor 957 * @throws { BusinessError } 13900010 - Try again 958 * @throws { BusinessError } 13900013 - Bad address 959 * @throws { BusinessError } 13900019 - Is a directory 960 * @throws { BusinessError } 13900020 - Invalid argument 961 * @throws { BusinessError } 13900024 - File too large 962 * @throws { BusinessError } 13900025 - No space left on device 963 * @throws { BusinessError } 13900034 - Operation would block 964 * @throws { BusinessError } 13900041 - Quota exceeded 965 * @throws { BusinessError } 13900042 - Unknown error 966 */ 967declare function readTextSync(filePath: string, options?: { 968 offset?: number; 969 length?: number; 970 encoding?: string; 971}): string; 972 973/** 974 * Rename file. 975 * 976 * @syscap SystemCapability.FileManagement.File.FileIO 977 * @since 9 978 * @param {string} oldPath - oldPath. 979 * @param {string} newPath - newPath. 980 * @param {AsyncCallback<void>} [callback] - callback. 981 * @returns {void | Promise<void>} no callback return Promise otherwise return void 982 * @throws { BusinessError } 13900001 - Operation not permitted 983 * @throws { BusinessError } 13900002 - No such file or directory 984 * @throws { BusinessError } 13900008 - Bad file descriptor 985 * @throws { BusinessError } 13900011 - Out of memory 986 * @throws { BusinessError } 13900012 - Permission denied 987 * @throws { BusinessError } 13900013 - Bad address 988 * @throws { BusinessError } 13900014 - Device or resource busy 989 * @throws { BusinessError } 13900015 - File exists 990 * @throws { BusinessError } 13900015 - Cross-device link 991 * @throws { BusinessError } 13900018 - Not a directory 992 * @throws { BusinessError } 13900019 - Is a directory 993 * @throws { BusinessError } 13900020 - Invalid argument 994 * @throws { BusinessError } 13900025 - No space left on device 995 * @throws { BusinessError } 13900027 - Read-only file system 996 * @throws { BusinessError } 13900028 - Too many links 997 * @throws { BusinessError } 13900032 - Directory not empty 998 * @throws { BusinessError } 13900033 - Too many symbolic links encountered 999 * @throws { BusinessError } 13900041 - Quota exceeded 1000 * @throws { BusinessError } 13900042 - Unknown error 1001 */ 1002declare function rename(oldPath: string, newPath: string): Promise<void>; 1003declare function rename(oldPath: string, newPath: string, callback: AsyncCallback<void>): void; 1004 1005/** 1006 * Rename file with sync interface. 1007 * 1008 * @syscap SystemCapability.FileManagement.File.FileIO 1009 * @since 9 1010 * @param {string} oldPath - oldPath. 1011 * @param {string} newPath - newPath. 1012 * @returns {void} rename success 1013 * @throws { BusinessError } 13900001 - Operation not permitted 1014 * @throws { BusinessError } 13900002 - No such file or directory 1015 * @throws { BusinessError } 13900008 - Bad file descriptor 1016 * @throws { BusinessError } 13900011 - Out of memory 1017 * @throws { BusinessError } 13900012 - Permission denied 1018 * @throws { BusinessError } 13900013 - Bad address 1019 * @throws { BusinessError } 13900014 - Device or resource busy 1020 * @throws { BusinessError } 13900015 - File exists 1021 * @throws { BusinessError } 13900015 - Cross-device link 1022 * @throws { BusinessError } 13900018 - Not a directory 1023 * @throws { BusinessError } 13900019 - Is a directory 1024 * @throws { BusinessError } 13900020 - Invalid argument 1025 * @throws { BusinessError } 13900025 - No space left on device 1026 * @throws { BusinessError } 13900027 - Read-only file system 1027 * @throws { BusinessError } 13900028 - Too many links 1028 * @throws { BusinessError } 13900032 - Directory not empty 1029 * @throws { BusinessError } 13900033 - Too many symbolic links encountered 1030 * @throws { BusinessError } 13900041 - Quota exceeded 1031 * @throws { BusinessError } 13900042 - Unknown error 1032 */ 1033declare function renameSync(oldPath: string, newPath: string): void; 1034 1035/** 1036 * Delete dir. 1037 * 1038 * @syscap SystemCapability.FileManagement.File.FileIO 1039 * @since 9 1040 * @param {string} path - path. 1041 * @param {AsyncCallback<void>} [callback] - callback. 1042 * @returns {void | Promise<void>} no callback return Promise otherwise return void 1043 * @throws { BusinessError } 13900001 - Operation not permitted 1044 * @throws { BusinessError } 13900002 - No such file or directory 1045 * @throws { BusinessError } 13900011 - Out of memory 1046 * @throws { BusinessError } 13900012 - Permission denied 1047 * @throws { BusinessError } 13900013 - Bad address 1048 * @throws { BusinessError } 13900014 - Device or resource busy 1049 * @throws { BusinessError } 13900018 - Not a directory 1050 * @throws { BusinessError } 13900020 - Invalid argument 1051 * @throws { BusinessError } 13900027 - Read-only file system1 1052 * @throws { BusinessError } 13900030 - File name too long 1053 * @throws { BusinessError } 13900032 - Directory not empty 1054 * @throws { BusinessError } 13900042 - Unknown error 1055 */ 1056declare function rmdir(path: string): Promise<void>; 1057declare function rmdir(path: string, callback: AsyncCallback<void>): void; 1058 1059/** 1060 * Delete dir with sync interface. 1061 * 1062 * @syscap SystemCapability.FileManagement.File.FileIO 1063 * @since 9 1064 * @param {string} path - path. 1065 * @returns {void} rmdir success 1066 * @throws { BusinessError } 13900001 - Operation not permitted 1067 * @throws { BusinessError } 13900002 - No such file or directory 1068 * @throws { BusinessError } 13900011 - Out of memory 1069 * @throws { BusinessError } 13900012 - Permission denied 1070 * @throws { BusinessError } 13900013 - Bad address 1071 * @throws { BusinessError } 13900014 - Device or resource busy 1072 * @throws { BusinessError } 13900018 - Not a directory 1073 * @throws { BusinessError } 13900020 - Invalid argument 1074 * @throws { BusinessError } 13900027 - Read-only file system1 1075 * @throws { BusinessError } 13900030 - File name too long 1076 * @throws { BusinessError } 13900032 - Directory not empty 1077 * @throws { BusinessError } 13900042 - Unknown error 1078 */ 1079declare function rmdirSync(path: string): void; 1080 1081/** 1082 * Get file information. 1083 * @static 1084 * @syscap SystemCapability.FileManagement.File.FileIO 1085 * @since 9 1086 * @param {string | number} file - path or file descriptor. 1087 * @param {AsyncCallback<Stat>} [callback] - callback. 1088 * @returns {void | Promise<Stat>} no callback return Promise otherwise return void 1089 * @throws { BusinessError } 13900002 - No such file or directory 1090 * @throws { BusinessError } 13900004 - Interrupted system call 1091 * @throws { BusinessError } 13900005 - I/O error 1092 * @throws { BusinessError } 13900008 - Bad file descriptor 1093 * @throws { BusinessError } 13900011 - Out of memory 1094 * @throws { BusinessError } 13900012 - Permission denied 1095 * @throws { BusinessError } 13900013 - Bad address 1096 * @throws { BusinessError } 13900018 - Not a directory 1097 * @throws { BusinessError } 13900030 - File name too long 1098 * @throws { BusinessError } 13900031 - Function not implemented 1099 * @throws { BusinessError } 13900033 - Too many symbolic links encountered 1100 * @throws { BusinessError } 13900038 - Value too large for defined data type 1101 * @throws { BusinessError } 13900042 - Unknown error 1102 */ 1103declare function stat(file: string | number): Promise<Stat>; 1104declare function stat(file: string | number, callback: AsyncCallback<Stat>): void; 1105 1106/** 1107 * Get file information with sync interface. 1108 * @static 1109 * @syscap SystemCapability.FileManagement.File.FileIO 1110 * @since 9 1111 * @param {string | number} file - path or file descriptor. 1112 * @returns {Stat} stat success 1113 * @throws { BusinessError } 13900002 - No such file or directory 1114 * @throws { BusinessError } 13900004 - Interrupted system call 1115 * @throws { BusinessError } 13900005 - I/O error 1116 * @throws { BusinessError } 13900008 - Bad file descriptor 1117 * @throws { BusinessError } 13900011 - Out of memory 1118 * @throws { BusinessError } 13900012 - Permission denied 1119 * @throws { BusinessError } 13900013 - Bad address 1120 * @throws { BusinessError } 13900018 - Not a directory 1121 * @throws { BusinessError } 13900030 - File name too long 1122 * @throws { BusinessError } 13900031 - Function not implemented 1123 * @throws { BusinessError } 13900033 - Too many symbolic links encountered 1124 * @throws { BusinessError } 13900038 - Value too large for defined data type 1125 * @throws { BusinessError } 13900042 - Unknown error 1126 */ 1127declare function statSync(file: string | number): Stat; 1128 1129/** 1130 * Link file. 1131 * 1132 * @syscap SystemCapability.FileManagement.File.FileIO 1133 * @since 9 1134 * @param {string} target - target. 1135 * @param {string} srcPath - srcPath. 1136 * @param {AsyncCallback<void>} [callback] - callback. 1137 * @returns {void | Promise<void>} no callback return Promise otherwise return void 1138 * @throws { BusinessError } 13900001 - Operation not permitted 1139 * @throws { BusinessError } 13900002 - No such file or directory 1140 * @throws { BusinessError } 13900005 - I/O error 1141 * @throws { BusinessError } 13900008 - Bad file descriptor 1142 * @throws { BusinessError } 13900011 - Out of memory 1143 * @throws { BusinessError } 13900012 - Permission denied 1144 * @throws { BusinessError } 13900013 - Bad address 1145 * @throws { BusinessError } 13900015 - File exists 1146 * @throws { BusinessError } 13900018 - Not a directory 1147 * @throws { BusinessError } 13900025 - No space left on device 1148 * @throws { BusinessError } 13900027 - Read-only file system 1149 * @throws { BusinessError } 13900030 - File name too long 1150 * @throws { BusinessError } 13900041 - Quota exceeded 1151 * @throws { BusinessError } 13900042 - Unknown error 1152 */ 1153declare function symlink(target: string, srcPath: string): Promise<void>; 1154declare function symlink(target: string, srcPath: string, callback: AsyncCallback<void>): void; 1155 1156/** 1157 * Link file with sync interface. 1158 * 1159 * @syscap SystemCapability.FileManagement.File.FileIO 1160 * @since 9 1161 * @param {string} target - target. 1162 * @param {string} srcPath - srcPath. 1163 * @returns {void} symlink success 1164 * @throws { BusinessError } 13900001 - Operation not permitted 1165 * @throws { BusinessError } 13900002 - No such file or directory 1166 * @throws { BusinessError } 13900005 - I/O error 1167 * @throws { BusinessError } 13900008 - Bad file descriptor 1168 * @throws { BusinessError } 13900011 - Out of memory 1169 * @throws { BusinessError } 13900012 - Permission denied 1170 * @throws { BusinessError } 13900013 - Bad address 1171 * @throws { BusinessError } 13900015 - File exists 1172 * @throws { BusinessError } 13900018 - Not a directory 1173 * @throws { BusinessError } 13900025 - No space left on device 1174 * @throws { BusinessError } 13900027 - Read-only file system 1175 * @throws { BusinessError } 13900030 - File name too long 1176 * @throws { BusinessError } 13900041 - Quota exceeded 1177 * @throws { BusinessError } 13900042 - Unknown error 1178 */ 1179declare function symlinkSync(target: string, srcPath: string): void; 1180 1181/** 1182 * Truncate file. 1183 * 1184 * @syscap SystemCapability.FileManagement.File.FileIO 1185 * @since 9 1186 * @param {string | number} file - path or file descriptor. 1187 * @param {number} [len = 0] - len. 1188 * @param {AsyncCallback<void>} [callback] - callback. 1189 * @returns {void | Promise<void>} no callback return Promise otherwise return void 1190 * @throws { BusinessError } 13900001 - Operation not permitted 1191 * @throws { BusinessError } 13900002 - No such file or directory 1192 * @throws { BusinessError } 13900004 - Interrupted system call 1193 * @throws { BusinessError } 13900005 - I/O error 1194 * @throws { BusinessError } 13900008 - Bad file descriptor 1195 * @throws { BusinessError } 13900012 - Permission denied 1196 * @throws { BusinessError } 13900013 - Bad address 1197 * @throws { BusinessError } 13900018 - Not a directory 1198 * @throws { BusinessError } 13900019 - Is a directory 1199 * @throws { BusinessError } 13900020 - Invalid argument 1200 * @throws { BusinessError } 13900023 - Text file busy 1201 * @throws { BusinessError } 13900024 - File too large 1202 * @throws { BusinessError } 13900027 - Read-only file system 1203 * @throws { BusinessError } 13900030 - File name too long 1204 * @throws { BusinessError } 13900033 - Too many symbolic links encountered 1205 * @throws { BusinessError } 13900042 - Unknown error 1206 */ 1207declare function truncate(file: string | number, len?: number): Promise<void>; 1208declare function truncate(file: string | number, callback: AsyncCallback<void>): void; 1209declare function truncate(file: string | number, len: number, callback: AsyncCallback<void>): void; 1210 1211/** 1212 * Truncate file with sync interface. 1213 * 1214 * @syscap SystemCapability.FileManagement.File.FileIO 1215 * @since 9 1216 * @param {string | number} file - path or file descriptor. 1217 * @param {number} [len = 0] - len. 1218 * @returns {void} truncate success 1219 * @throws { BusinessError } 13900001 - Operation not permitted 1220 * @throws { BusinessError } 13900002 - No such file or directory 1221 * @throws { BusinessError } 13900004 - Interrupted system call 1222 * @throws { BusinessError } 13900005 - I/O error 1223 * @throws { BusinessError } 13900008 - Bad file descriptor 1224 * @throws { BusinessError } 13900012 - Permission denied 1225 * @throws { BusinessError } 13900013 - Bad address 1226 * @throws { BusinessError } 13900018 - Not a directory 1227 * @throws { BusinessError } 13900019 - Is a directory 1228 * @throws { BusinessError } 13900020 - Invalid argument 1229 * @throws { BusinessError } 13900023 - Text file busy 1230 * @throws { BusinessError } 13900024 - File too large 1231 * @throws { BusinessError } 13900027 - Read-only file system 1232 * @throws { BusinessError } 13900030 - File name too long 1233 * @throws { BusinessError } 13900033 - Too many symbolic links encountered 1234 * @throws { BusinessError } 13900042 - Unknown error 1235 */ 1236declare function truncateSync(file: string | number, len?: number): void; 1237 1238/** 1239 * Delete file. 1240 * 1241 * @syscap SystemCapability.FileManagement.File.FileIO 1242 * @since 9 1243 * @param {string} path - path. 1244 * @param {AsyncCallback<void>} [callback] - callback. 1245 * @returns {void | Promise<void>} no callback return Promise otherwise return void 1246 * @throws { BusinessError } 13900001 - Operation not permitted 1247 * @throws { BusinessError } 13900002 - No such file or directory 1248 * @throws { BusinessError } 13900005 - I/O error 1249 * @throws { BusinessError } 13900008 - Bad file descriptor 1250 * @throws { BusinessError } 13900011 - Out of memory 1251 * @throws { BusinessError } 13900012 - Permission denied 1252 * @throws { BusinessError } 13900013 - Bad address 1253 * @throws { BusinessError } 13900014 - Device or resource busy 1254 * @throws { BusinessError } 13900018 - Not a directory 1255 * @throws { BusinessError } 13900019 - Is a directory 1256 * @throws { BusinessError } 13900020 - Invalid argument 1257 * @throws { BusinessError } 13900027 - Read-only file system 1258 * @throws { BusinessError } 13900030 - File name too long 1259 * @throws { BusinessError } 13900033 - Too many symbolic links encountered 1260 * @throws { BusinessError } 13900042 - Unknown error 1261 */ 1262declare function unlink(path: string): Promise<void>; 1263declare function unlink(path: string, callback: AsyncCallback<void>): void; 1264 1265/** 1266 * Delete file with sync interface. 1267 * 1268 * @syscap SystemCapability.FileManagement.File.FileIO 1269 * @since 9 1270 * @param {string} path - path. 1271 * @returns {void} unlink success 1272 * @throws { BusinessError } 13900001 - Operation not permitted 1273 * @throws { BusinessError } 13900002 - No such file or directory 1274 * @throws { BusinessError } 13900005 - I/O error 1275 * @throws { BusinessError } 13900008 - Bad file descriptor 1276 * @throws { BusinessError } 13900011 - Out of memory 1277 * @throws { BusinessError } 13900012 - Permission denied 1278 * @throws { BusinessError } 13900013 - Bad address 1279 * @throws { BusinessError } 13900014 - Device or resource busy 1280 * @throws { BusinessError } 13900018 - Not a directory 1281 * @throws { BusinessError } 13900019 - Is a directory 1282 * @throws { BusinessError } 13900020 - Invalid argument 1283 * @throws { BusinessError } 13900027 - Read-only file system 1284 * @throws { BusinessError } 13900030 - File name too long 1285 * @throws { BusinessError } 13900033 - Too many symbolic links encountered 1286 * @throws { BusinessError } 13900042 - Unknown error 1287 */ 1288declare function unlinkSync(path: string): void; 1289 1290/** 1291 * Write file. 1292 * 1293 * @syscap SystemCapability.FileManagement.File.FileIO 1294 * @since 9 1295 * @param {number} fd - file descriptor. 1296 * @param {ArrayBuffer | string} buffer - file descriptor. 1297 * @param {Object} [options] - options. 1298 * @param {number} [options.offset = 0] - offset. 1299 * @param {number} [options.length = 0] - length. 1300 * @param {string} [options.encoding = 'utf-8'] - encoding. 1301 * @param {AsyncCallback<number>} [callback] - callback. 1302 * @returns {void | Promise<number>} no callback return Promise otherwise return void 1303 * @throws { BusinessError } 13900001 - Operation not permitted 1304 * @throws { BusinessError } 13900004 - Interrupted system call 1305 * @throws { BusinessError } 13900005 - I/O error 1306 * @throws { BusinessError } 13900008 - Bad file descriptor 1307 * @throws { BusinessError } 13900010 - Try again 1308 * @throws { BusinessError } 13900013 - Bad address 1309 * @throws { BusinessError } 13900020 - Invalid argument 1310 * @throws { BusinessError } 13900024 - File too large 1311 * @throws { BusinessError } 13900025 - No space left on device 1312 * @throws { BusinessError } 13900034 - Operation would block 1313 * @throws { BusinessError } 13900041 - Quota exceeded 1314 * @throws { BusinessError } 13900042 - Unknown error 1315 */ 1316declare function write(fd: number, buffer: ArrayBuffer | string, options?: { 1317 offset?: number; 1318 length?: number; 1319 encoding?: string; 1320}): Promise<number>; 1321declare function write(fd: number, buffer: ArrayBuffer | string, callback: AsyncCallback<number>): void; 1322declare function write(fd: number, buffer: ArrayBuffer | string, options: { 1323 offset?: number; 1324 length?: number; 1325 encoding?: string; 1326}, callback: AsyncCallback<number>): void; 1327 1328/** 1329 * Write file with sync interface. 1330 * 1331 * @syscap SystemCapability.FileManagement.File.FileIO 1332 * @since 9 1333 * @param {number} fd - file descriptor. 1334 * @param {ArrayBuffer | string} buffer - file descriptor. 1335 * @param {Object} [options] - options. 1336 * @param {number} [options.offset = 0] - offset. 1337 * @param {number} [options.length = 0] - length. 1338 * @param {string} [options.encoding = 'utf-8'] - encoding. 1339 * @returns {number} on success number of bytesRead 1340 * @throws { BusinessError } 13900001 - Operation not permitted 1341 * @throws { BusinessError } 13900004 - Interrupted system call 1342 * @throws { BusinessError } 13900005 - I/O error 1343 * @throws { BusinessError } 13900008 - Bad file descriptor 1344 * @throws { BusinessError } 13900010 - Try again 1345 * @throws { BusinessError } 13900013 - Bad address 1346 * @throws { BusinessError } 13900020 - Invalid argument 1347 * @throws { BusinessError } 13900024 - File too large 1348 * @throws { BusinessError } 13900025 - No space left on device 1349 * @throws { BusinessError } 13900034 - Operation would block 1350 * @throws { BusinessError } 13900041 - Quota exceeded 1351 * @throws { BusinessError } 13900042 - Unknown error 1352 */ 1353declare function writeSync(fd: number, buffer: ArrayBuffer | string, options?: { 1354 offset?: number; 1355 length?: number; 1356 encoding?: string; 1357}): number; 1358 1359/** 1360 * File object. 1361 * @syscap SystemCapability.FileManagement.File.FileIO 1362 * @since 9 1363 */ 1364declare interface File { 1365 /** 1366 * @type {number} 1367 * @syscap SystemCapability.FileManagement.File.FileIO 1368 * @since 9 1369 * @readonly 1370 */ 1371 readonly fd: number; 1372 1373 /** 1374 * Lock file with blocking method. 1375 * @syscap SystemCapability.FileManagement.File.FileIO 1376 * @since 9 1377 * @param {boolean} exclusive - whether lock is exclusive. 1378 * @returns {Promise<void>} return Promise 1379 * @throws { BusinessError } 13900004 - Interrupted system call 1380 * @throws { BusinessError } 13900008 - Bad file descriptor 1381 * @throws { BusinessError } 13900020 - Invalid argument 1382 * @throws { BusinessError } 13900034 - Operation would block 1383 * @throws { BusinessError } 13900042 - Unknown error 1384 * @throws { BusinessError } 13900043 - No record locks available 1385 */ 1386 lock(exclusive?: boolean): Promise<void>; 1387 1388 /** 1389 * Lock file with blocking method. 1390 * @syscap SystemCapability.FileManagement.File.FileIO 1391 * @since 9 1392 * @param {boolean} exclusive - whether lock is exclusive. 1393 * @param {AsyncCallback<void>} callback - callback. 1394 * @throws { BusinessError } 13900004 - Interrupted system call 1395 * @throws { BusinessError } 13900008 - Bad file descriptor 1396 * @throws { BusinessError } 13900020 - Invalid argument 1397 * @throws { BusinessError } 13900034 - Operation would block 1398 * @throws { BusinessError } 13900042 - Unknown error 1399 * @throws { BusinessError } 13900043 - No record locks available 1400 */ 1401 lock(callback: AsyncCallback<void>): void; 1402 lock(exclusive: boolean, callback: AsyncCallback<void>): void; 1403 1404 /** 1405 * Try to lock file with returning results immediately. 1406 * @syscap SystemCapability.FileManagement.File.FileIO 1407 * @since 9 1408 * @param {boolean} exclusive - whether lock is exclusive. 1409 * @returns {void} tryLock success 1410 * @throws { BusinessError } 13900004 - Interrupted system call 1411 * @throws { BusinessError } 13900008 - Bad file descriptor 1412 * @throws { BusinessError } 13900020 - Invalid argument 1413 * @throws { BusinessError } 13900034 - Operation would block 1414 * @throws { BusinessError } 13900042 - Unknown error 1415 * @throws { BusinessError } 13900043 - No record locks available 1416 */ 1417 tryLock(exclusive?: boolean): void; 1418 1419 /** 1420 * Unlock file. 1421 * @syscap SystemCapability.FileManagement.File.FileIO 1422 * @since 9 1423 * @returns {void} unlock success 1424 * @throws { BusinessError } 13900004 - Interrupted system call 1425 * @throws { BusinessError } 13900008 - Bad file descriptor 1426 * @throws { BusinessError } 13900020 - Invalid argument 1427 * @throws { BusinessError } 13900034 - Operation would block 1428 * @throws { BusinessError } 13900042 - Unknown error 1429 * @throws { BusinessError } 13900043 - No record locks available 1430 */ 1431 unlock(): void; 1432} 1433/** 1434 * Stat object. 1435 * @syscap SystemCapability.FileManagement.File.FileIO 1436 * @since 9 1437 */ 1438declare interface Stat { 1439 /** 1440 * @type {number} 1441 * @syscap SystemCapability.FileManagement.File.FileIO 1442 * @since 9 1443 * @readonly 1444 * @throws { BusinessError } 13900005 - I/O error 1445 * @throws { BusinessError } 13900042 - Unknown error 1446 */ 1447 readonly ino: bigint; 1448 /** 1449 * @type {bigint} 1450 * @syscap SystemCapability.FileManagement.File.FileIO 1451 * @since 9 1452 * @readonly 1453 * @throws { BusinessError } 13900005 - I/O error 1454 * @throws { BusinessError } 13900042 - Unknown error 1455 */ 1456 readonly mode: number; 1457 /** 1458 * @type {number} 1459 * @syscap SystemCapability.FileManagement.File.FileIO 1460 * @since 9 1461 * @readonly 1462 * @throws { BusinessError } 13900005 - I/O error 1463 * @throws { BusinessError } 13900042 - Unknown error 1464 * @throws { BusinessError } 13900005 - I/O error 1465 * @throws { BusinessError } 13900042 - Unknown error 1466 */ 1467 readonly uid: number; 1468 /** 1469 * @type {number} 1470 * @syscap SystemCapability.FileManagement.File.FileIO 1471 * @since 9 1472 * @readonly 1473 * @throws { BusinessError } 13900005 - I/O error 1474 * @throws { BusinessError } 13900042 - Unknown error 1475 */ 1476 readonly gid: number; 1477 /** 1478 * @type {number} 1479 * @syscap SystemCapability.FileManagement.File.FileIO 1480 * @since 9 1481 * @readonly 1482 * @throws { BusinessError } 13900005 - I/O error 1483 * @throws { BusinessError } 13900042 - Unknown error 1484 */ 1485 readonly size: number; 1486 /** 1487 * @type {number} 1488 * @syscap SystemCapability.FileManagement.File.FileIO 1489 * @since 9 1490 * @readonly 1491 * @throws { BusinessError } 13900005 - I/O error 1492 * @throws { BusinessError } 13900042 - Unknown error 1493 */ 1494 readonly atime: number; 1495 /** 1496 * @type {number} 1497 * @syscap SystemCapability.FileManagement.File.FileIO 1498 * @since 9 1499 * @readonly 1500 * @throws { BusinessError } 13900005 - I/O error 1501 * @throws { BusinessError } 13900042 - Unknown error 1502 */ 1503 readonly mtime: number; 1504 /** 1505 * @type {number} 1506 * @syscap SystemCapability.FileManagement.File.FileIO 1507 * @since 9 1508 * @readonly 1509 * @throws { BusinessError } 13900005 - I/O error 1510 * @throws { BusinessError } 13900042 - Unknown error 1511 */ 1512 readonly ctime: number; 1513 /** 1514 * Whether path/fd is block device. 1515 * @syscap SystemCapability.FileManagement.File.FileIO 1516 * @since 9 1517 * @returns {boolean} is or not 1518 * @throws { BusinessError } 13900005 - I/O error 1519 * @throws { BusinessError } 13900042 - Unknown error 1520 */ 1521 isBlockDevice(): boolean; 1522 /** 1523 * Whether path/fd is character device. 1524 * @syscap SystemCapability.FileManagement.File.FileIO 1525 * @since 9 1526 * @returns {boolean} is or not 1527 * @throws { BusinessError } 13900005 - I/O error 1528 * @throws { BusinessError } 13900042 - Unknown error 1529 */ 1530 isCharacterDevice(): boolean; 1531 /** 1532 * Whether path/fd is directory. 1533 * @syscap SystemCapability.FileManagement.File.FileIO 1534 * @since 9 1535 * @returns {boolean} is or not 1536 * @throws { BusinessError } 13900005 - I/O error 1537 * @throws { BusinessError } 13900042 - Unknown error 1538 */ 1539 isDirectory(): boolean; 1540 /** 1541 * Whether path/fd is fifo. 1542 * @syscap SystemCapability.FileManagement.File.FileIO 1543 * @since 9 1544 * @returns {boolean} is or not 1545 * @throws { BusinessError } 13900005 - I/O error 1546 * @throws { BusinessError } 13900042 - Unknown error 1547 */ 1548 isFIFO(): boolean; 1549 /** 1550 * Whether path/fd is file. 1551 * @syscap SystemCapability.FileManagement.File.FileIO 1552 * @since 9 1553 * @returns {boolean} is or not 1554 * @throws { BusinessError } 13900005 - I/O error 1555 * @throws { BusinessError } 13900042 - Unknown error 1556 */ 1557 isFile(): boolean; 1558 /** 1559 * Whether path/fd is socket. 1560 * @syscap SystemCapability.FileManagement.File.FileIO 1561 * @since 9 1562 * @returns {boolean} is or not 1563 * @throws { BusinessError } 13900005 - I/O error 1564 * @throws { BusinessError } 13900042 - Unknown error 1565 */ 1566 isSocket(): boolean; 1567 /** 1568 * Whether path/fd is symbolic link. 1569 * @syscap SystemCapability.FileManagement.File.FileIO 1570 * @since 9 1571 * @returns {boolean} is or not 1572 * @throws { BusinessError } 13900005 - I/O error 1573 * @throws { BusinessError } 13900042 - Unknown error 1574 */ 1575 isSymbolicLink(): boolean; 1576} 1577 1578/** 1579 * Stream object 1580 * @syscap SystemCapability.FileManagement.File.FileIO 1581 * @since 9 1582 */ 1583declare interface Stream { 1584 /** 1585 * Close stream. 1586 * 1587 * @syscap SystemCapability.FileManagement.File.FileIO 1588 * @since 9 1589 * @param {AsyncCallback<void>} [callback] - callback. 1590 * @returns {void | Promise<void>} close success 1591 * @throws { BusinessError } 13900004 - Interrupted system call 1592 * @throws { BusinessError } 13900005 - I/O error 1593 * @throws { BusinessError } 13900008 - Bad file descriptor 1594 * @throws { BusinessError } 13900025 - No space left on device 1595 * @throws { BusinessError } 13900041 - Quota exceeded 1596 * @throws { BusinessError } 13900042 - Unknown error 1597 * 1598 */ 1599 close(): Promise<void>; 1600 close(callback: AsyncCallback<void>): void; 1601 1602 /** 1603 * Close stream with sync interface. 1604 * 1605 * @syscap SystemCapability.FileManagement.File.FileIO 1606 * @since 9 1607 * @returns {void} close success 1608 * @throws { BusinessError } 13900004 - Interrupted system call 1609 * @throws { BusinessError } 13900005 - I/O error 1610 * @throws { BusinessError } 13900008 - Bad file descriptor 1611 * @throws { BusinessError } 13900025 - No space left on device 1612 * @throws { BusinessError } 13900041 - Quota exceeded 1613 * @throws { BusinessError } 13900042 - Unknown error 1614 */ 1615 closeSync(): void; 1616 /** 1617 * Flush stream. 1618 * 1619 * @syscap SystemCapability.FileManagement.File.FileIO 1620 * @since 9 1621 * @param {AsyncCallback<void>} [callback] - callback. 1622 * @returns {void | Promise<void>} no callback return Promise otherwise return void 1623 * @throws { BusinessError } 13900001 - Operation not permitted 1624 * @throws { BusinessError } 13900004 - Interrupted system call 1625 * @throws { BusinessError } 13900005 - I/O error 1626 * @throws { BusinessError } 13900008 - Bad file descriptor 1627 * @throws { BusinessError } 13900010 - Try again 1628 * @throws { BusinessError } 13900013 - Bad address 1629 * @throws { BusinessError } 13900020 - Invalid argument 1630 * @throws { BusinessError } 13900024 - File too large 1631 * @throws { BusinessError } 13900025 - No space left on device 1632 * @throws { BusinessError } 13900034 - Operation would block 1633 * @throws { BusinessError } 13900041 - Quota exceeded 1634 * @throws { BusinessError } 13900042 - Unknown error 1635 */ 1636 flush(): Promise<void>; 1637 flush(callback: AsyncCallback<void>): void; 1638 /** 1639 * Flush stream with sync interface. 1640 * 1641 * @syscap SystemCapability.FileManagement.File.FileIO 1642 * @since 9 1643 * @returns {void} flush success 1644 * @throws { BusinessError } 13900001 - Operation not permitted 1645 * @throws { BusinessError } 13900004 - Interrupted system call 1646 * @throws { BusinessError } 13900005 - I/O error 1647 * @throws { BusinessError } 13900008 - Bad file descriptor 1648 * @throws { BusinessError } 13900010 - Try again 1649 * @throws { BusinessError } 13900013 - Bad address 1650 * @throws { BusinessError } 13900020 - Invalid argument 1651 * @throws { BusinessError } 13900024 - File too large 1652 * @throws { BusinessError } 13900025 - No space left on device 1653 * @throws { BusinessError } 13900034 - Operation would block 1654 * @throws { BusinessError } 13900041 - Quota exceeded 1655 * @throws { BusinessError } 13900042 - Unknown error 1656 */ 1657 flushSync(): void; 1658 /** 1659 * Write stream. 1660 * 1661 * @syscap SystemCapability.FileManagement.File.FileIO 1662 * @since 9 1663 * @param {ArrayBuffer | string} buffer - file description. 1664 * @param {Object} [options] - options. 1665 * @param {number} [options.length = 0] - length(bytes) ignored when buffer is string. 1666 * @param {number} [options.offset = 0] - offset(bytes) where start to write < 0 use read, else use pread. 1667 * @param {string} [options.encoding = 'utf-8'] - encoding. 1668 * @param {AsyncCallback<number>} [callback] - callback. 1669 * @returns {void | Promise<number>} no callback return Promise otherwise return void 1670 * @throws { BusinessError } 13900001 - Operation not permitted 1671 * @throws { BusinessError } 13900004 - Interrupted system call 1672 * @throws { BusinessError } 13900005 - I/O error 1673 * @throws { BusinessError } 13900008 - Bad file descriptor 1674 * @throws { BusinessError } 13900010 - Try again 1675 * @throws { BusinessError } 13900013 - Bad address 1676 * @throws { BusinessError } 13900020 - Invalid argument 1677 * @throws { BusinessError } 13900024 - File too large 1678 * @throws { BusinessError } 13900025 - No space left on device 1679 * @throws { BusinessError } 13900034 - Operation would block 1680 * @throws { BusinessError } 13900041 - Quota exceeded 1681 * @throws { BusinessError } 13900042 - Unknown error 1682 */ 1683 write(buffer: ArrayBuffer | string, options?: { 1684 offset?: number; 1685 length?: number; 1686 encoding?: string; 1687 }): Promise<number>; 1688 write(buffer: ArrayBuffer | string, callback: AsyncCallback<number>): void; 1689 write(buffer: ArrayBuffer | string, options: { 1690 offset?: number; 1691 length?: number; 1692 encoding?: string; 1693 }, callback: AsyncCallback<number>): void; 1694 /** 1695 * Write stream with sync interface. 1696 * 1697 * @syscap SystemCapability.FileManagement.File.FileIO 1698 * @since 9 1699 * @param {ArrayBuffer | string} buffer - file description. 1700 * @param {Object} [options] - options. 1701 * @param {number} [options.length = 0] - length(bytes) ignored when buffer is string. 1702 * @param {number} [options.offset = 0] - offset(bytes) where start to write < 0 use read, else use pread. 1703 * @param {string} [options.encoding = 'utf-8'] - encoding. 1704 * @returns {number} on success number of bytes written 1705 * @throws { BusinessError } 13900001 - Operation not permitted 1706 * @throws { BusinessError } 13900004 - Interrupted system call 1707 * @throws { BusinessError } 13900005 - I/O error 1708 * @throws { BusinessError } 13900008 - Bad file descriptor 1709 * @throws { BusinessError } 13900010 - Try again 1710 * @throws { BusinessError } 13900013 - Bad address 1711 * @throws { BusinessError } 13900020 - Invalid argument 1712 * @throws { BusinessError } 13900024 - File too large 1713 * @throws { BusinessError } 13900025 - No space left on device 1714 * @throws { BusinessError } 13900034 - Operation would block 1715 * @throws { BusinessError } 13900041 - Quota exceeded 1716 * @throws { BusinessError } 13900042 - Unknown error 1717 */ 1718 writeSync(buffer: ArrayBuffer | string, options?: { 1719 offset?: number; 1720 length?: number; 1721 encoding?: string; 1722 }): number; 1723 /** 1724 * Read stream. 1725 * 1726 * @syscap SystemCapability.FileManagement.File.FileIO 1727 * @since 9 1728 * @param {ArrayBuffer} buffer - file description. 1729 * @param {Object} [options] - options. 1730 * @param {number} [options.offset = 0] - offset. 1731 * @param {number} [options.length = 0] - length. 1732 * @param {AsyncCallback<number>} [callback] - callback. 1733 * @returns {void | Promise<number>} no callback return Promise otherwise return void 1734 * @throws { BusinessError } 13900004 - Interrupted system call 1735 * @throws { BusinessError } 13900005 - I/O error 1736 * @throws { BusinessError } 13900008 - Bad file descriptor 1737 * @throws { BusinessError } 13900010 - Try again 1738 * @throws { BusinessError } 13900013 - Bad address 1739 * @throws { BusinessError } 13900019 - Is a directory 1740 * @throws { BusinessError } 13900020 - Invalid argument 1741 * @throws { BusinessError } 13900034 - Operation would block 1742 * @throws { BusinessError } 13900042 - Unknown error 1743 */ 1744 read(buffer: ArrayBuffer, options?: { 1745 offset?: number; 1746 length?: number; 1747 }): Promise<number>; 1748 read(buffer: ArrayBuffer, callback: AsyncCallback<number>): void; 1749 read(buffer: ArrayBuffer, options: { 1750 offset?: number; 1751 length?: number; 1752 }, callback: AsyncCallback<number>): void; 1753 1754 /** 1755 * Read stream with sync interface. 1756 * 1757 * @syscap SystemCapability.FileManagement.File.FileIO 1758 * @since 9 1759 * @param {ArrayBuffer} buffer - file description. 1760 * @param {Object} [options] - options. 1761 * @param {number} [options.offset = 0] - offset. 1762 * @param {number} [options.length = 0] - length. 1763 * @returns {number} number of bytesRead 1764 * @throws { BusinessError } 13900004 - Interrupted system call 1765 * @throws { BusinessError } 13900005 - I/O error 1766 * @throws { BusinessError } 13900008 - Bad file descriptor 1767 * @throws { BusinessError } 13900010 - Try again 1768 * @throws { BusinessError } 13900013 - Bad address 1769 * @throws { BusinessError } 13900019 - Is a directory 1770 * @throws { BusinessError } 13900020 - Invalid argument 1771 * @throws { BusinessError } 13900034 - Operation would block 1772 * @throws { BusinessError } 13900042 - Unknown error 1773 */ 1774 readSync(buffer: ArrayBuffer, options?: { 1775 offset?: number; 1776 length?: number; 1777 }): number; 1778} 1779 1780/** 1781 * File filter type 1782 * @syscap SystemCapability.FileManagement.File.FileIO 1783 * @since 9 1784 */ 1785export type Filter = { 1786 /** 1787 * @type {Array<string>} 1788 * @syscap SystemCapability.FileManagement.File.FileIO 1789 * @systemapi 1790 * @since 9 1791 * @readonly 1792 */ 1793 suffix?: Array<string>; 1794 /** 1795 * @type {Array<string>} 1796 * @syscap SystemCapability.FileManagement.File.FileIO 1797 * @systemapi 1798 * @since 9 1799 * @readonly 1800 */ 1801 displayName?: Array<string>; 1802 /** 1803 * @type {Array<string>} 1804 * @syscap SystemCapability.FileManagement.File.FileIO 1805 * @systemapi 1806 * @since 9 1807 * @readonly 1808 */ 1809 mimeType?: Array<string>; 1810 /** 1811 * @type {number} 1812 * @syscap SystemCapability.FileManagement.File.FileIO 1813 * @systemapi 1814 * @since 9 1815 * @readonly 1816 */ 1817 fileSizeOver?: number; 1818 /** 1819 * @type {number} 1820 * @syscap SystemCapability.FileManagement.File.FileIO 1821 * @systemapi 1822 * @since 9 1823 * @readonly 1824 */ 1825 lastModifiedAfter?: number; 1826 /** 1827 * @type {boolean} 1828 * @syscap SystemCapability.FileManagement.File.FileIO 1829 * @systemapi 1830 * @since 9 1831 * @readonly 1832 */ 1833 excludeMedia?: boolean; 1834} 1835