1/* 2 * Copyright (c) 2021 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 N/A 22 * @since 6 23 * @devices phone, tablet, tv, wearable, car 24 * @import import fileio from '@ohos.fileio'; 25 * @permission N/A 26 */ 27declare namespace fileIO { 28 export { accessSync }; 29 export { chmodSync }; 30 export { chownSync }; 31 export { closeSync }; 32 export { copyFileSync }; 33 export { createStreamSync }; 34 export { fchmodSync }; 35 export { fchownSync }; 36 export { fdopenStreamSync }; 37 export { fstatSync }; 38 export { fsyncSync }; 39 export { ftruncateSync }; 40 export { mkdirSync }; 41 export { openSync }; 42 export { opendirSync }; 43 export { readSync }; 44 export { renameSync }; 45 export { rmdirSync }; 46 export { statSync }; 47 export { truncateSync }; 48 export { unlinkSync }; 49 export { writeSync }; 50 export { Dir }; 51 export { Dirent }; 52 export { Stat }; 53 export { Stream }; 54} 55 56 57/** 58 * accessSync. 59 * 60 * @note N/A 61 * @sysCap N/A 62 * @since 6 63 * @permission N/A 64 * @function accessSync 65 * @param {string} path - path. 66 * @param {number} [mode = 0] - mode. 67 * @returns {void} access success 68 * @throws {TypedError | Error} access fail 69 */ 70declare function accessSync(path: string, mode?: number): void; 71/** 72 * closeSync. 73 * 74 * @note N/A 75 * @sysCap N/A 76 * @since 6 77 * @permission N/A 78 * @function closeSync 79 * @param {number} fd - fd. 80 * @returns {void} close success 81 * @throws {TypedError | Error} close fail 82 */ 83declare function closeSync(fd: number): void; 84/** 85 * copyFileSync. 86 * 87 * @note N/A 88 * @sysCap N/A 89 * @since 6 90 * @permission N/A 91 * @function copyFileSync 92 * @param {string} src - src. 93 * @param {string} dest - dest. 94 * @param {number} [mode = 0] - mode. 95 * @returns {void} copyFile success 96 * @throws {TypedError | Error} copyFile fail 97 */ 98declare function copyFileSync(src: string, dest: string, mode?: number): void; 99/** 100 * createStreamSync. 101 * 102 * @note N/A 103 * @sysCap N/A 104 * @since 7 105 * @permission N/A 106 * @function createStreamSync 107 * @param {string} path - path. 108 * @param {string} mode - mode. 109 * @returns {Stream} createStream 110 * @throws {TypedError} Parameter check failed 111 */ 112declare function createStreamSync(path: string, mode: string): Stream; 113/** 114 * chownSync. 115 * 116 * @note N/A 117 * @sysCap N/A 118 * @since 7 119 * @permission N/A 120 * @function appendFile 121 * @param {string} path - path. 122 * @param {number} uid - mode. 123 * @param {number} gid - mode. 124 * @returns {void} chown success 125 * @throws {TypedError | Error} chown fail 126 */ 127declare function chownSync(path: string, uid: number, gid: number): void; 128/** 129 * chmodSync. 130 * 131 * @note N/A 132 * @sysCap N/A 133 * @since 7 134 * @permission N/A 135 * @function chmodSync 136 * @param {string} path - path. 137 * @param {number} mode - mode. 138 * @returns {void} chmod success 139 * @throws {TypedError | Error} chmod fail 140 */ 141declare function chmodSync(path: string, mode: number): void; 142/** 143 * ftruncateSync. 144 * 145 * @note N/A 146 * @sysCap N/A 147 * @since 7 148 * @permission N/A 149 * @function ftruncateSync 150 * @param {number} fd - fd. 151 * @param {number} [len = 0] - len. 152 * @returns {void} ftruncate success 153 * @throws {TypedError | Error} ftruncate fail 154 */ 155declare function ftruncateSync(fd: number, len?: number): void; 156/** 157 * fsyncSync. 158 * 159 * @note N/A 160 * @sysCap N/A 161 * @since 7 162 * @permission N/A 163 * @function fsyncSync 164 * @param {number} fd - fd. 165 * @returns {void} fsync success 166 * @throws {TypedError | Error} fsync fail 167 */ 168declare function fsyncSync(fd: number): void; 169/** 170 * fstatSync. 171 * 172 * @note N/A 173 * @sysCap N/A 174 * @since 7 175 * @permission N/A 176 * @function fstatSync 177 * @param {number} fd - fd. 178 * @returns {Stat} 179 * @throws {TypedError | Error} fstat fail 180 */ 181declare function fstatSync(fd: number): Stat; 182/** 183 * fchownSync. 184 * 185 * @note N/A 186 * @sysCap N/A 187 * @since 7 188 * @permission N/A 189 * @function fchownSync 190 * @param {number} fd - fd. 191 * @param {number} uid - uid. 192 * @param {number} gid - gid. 193 * @returns {void} fchown success 194 * @throws {TypedError | Error} fchown fail 195 */ 196declare function fchownSync(fd: number, uid: number, gid: number): void; 197/** 198 * fchmodSync. 199 * 200 * @note N/A 201 * @sysCap N/A 202 * @since 7 203 * @permission N/A 204 * @function fchmodSync 205 * @param {number} fd - fd. 206 * @param {number} mode - mode. 207 * @returns {void} fchmod success 208 * @throws {TypedError | Error} fchmod fail 209 */ 210declare function fchmodSync(fd: number, mode: number): void; 211/** 212 * fdopenStreamSync. 213 * @note N/A 214 * @sysCap N/A 215 * @since 7 216 * @permission N/A 217 * @function fdopenStreamSync 218 * @param {number} fd - fd. 219 * @param {string} mode - mode. 220 * @returns {Stream} open stream from fd 221 * @throws {TypedError | Error} open fail 222 */ 223declare function fdopenStreamSync(fd: number, mode: string): Stream; 224/** 225 * mkdirSync. 226 * 227 * @note N/A 228 * @sysCap N/A 229 * @since 6 230 * @permission N/A 231 * @function mkdirSync 232 * @param {string} path - path. 233 * @param {number} [mode = 0o775] - path. 234 * @returns {void} mkdir success 235 * @throws {TypedError | Error} mkdir fail 236 */ 237declare function mkdirSync(path: string, mode?: number): void; 238 239/** 240 * openSync. 241 * 242 * @note N/A 243 * @sysCap N/A 244 * @since 6 245 * @permission N/A 246 * @function openSync 247 * @param {string} path - path. 248 * @param {number} [flags = 0] - flags. 249 * @param {number} [mode = 0o666] - mode. 250 * @returns {number} open fd 251 * @throws {TypedError | Error} open fail 252 */ 253declare function openSync(path: string, flags?: number, mode?: number): number; 254 255/** 256 * opendirSync. 257 * 258 * @param {string} path - directory name. 259 * @returns {Dir} opendir Dir Object 260 * @throws {TypedError | Error} opendir fail 261 */ 262declare function opendirSync(path: string): Dir; 263/** 264 * readSync. 265 * 266 * @note N/A 267 * @sysCap N/A 268 * @since 6 269 * @permission N/A 270 * @function readSync 271 * @param {number} fd - file descriptor. 272 * @param {ArrayBuffer} buffer - file descriptor. 273 * @param {Object} [options] - options. 274 * @param {number} [options.offset = 0] - offset. 275 * @param {number} [options.length = -1] - length. 276 * @param {number} [options.position = -1] - position. 277 * @returns {number} number of bytesRead 278 * @throws {TypedError | Error} read fail 279 */ 280declare function readSync(fd: number, buffer: ArrayBuffer, options?: { 281 offset?: number; 282 length?: number; 283 position?: number; 284}): number; 285/** 286 * renameSync. 287 * 288 * @note N/A 289 * @sysCap N/A 290 * @since 7 291 * @permission N/A 292 * @function renameSync 293 * @param {string} oldPath - oldPath. 294 * @param {string} newPath - newPath. 295 * @returns {void} rename success 296 * @throws {TypedError | Error} rename fail 297 */ 298declare function renameSync(oldPath: string, newPath: string): void; 299 300/** 301 * rmdirSync. 302 * 303 * @note N/A 304 * @sysCap N/A 305 * @since 7 306 * @permission N/A 307 * @function rmdirSync 308 * @param {string} path - path. 309 * @returns {void} rmdir success 310 * @throws {TypedError | Error} rmdir fail 311 */ 312declare function rmdirSync(path: string): void; 313/** 314 * statSync. 315 * @static 316 * @note N/A 317 * @sysCap N/A 318 * @since 6 319 * @permission N/A 320 * @param {string} path - path. 321 * @returns {Stat} stat success 322 * @throws {TypedError | Error} stat fail 323 */ 324declare function statSync(path: string): Stat; 325/** 326 * truncateSync. 327 * 328 * @note N/A 329 * @sysCap N/A 330 * @since 7 331 * @permission N/A 332 * @function truncateSync 333 * @param {string} path - path. 334 * @param {number} [len = 0] - len. 335 * @returns {void} truncate success 336 * @throws {TypedError | Error} truncate fail 337 */ 338declare function truncateSync(path: string, len?: number): void; 339/** 340 * unlinkSync. 341 * 342 * @note N/A 343 * @sysCap N/A 344 * @since 6 345 * @permission N/A 346 * @function unlinkSync 347 * @param {string} path - path. 348 * @returns {void} unlink success 349 * @throws {TypedError | Error} unlink fail 350 */ 351declare function unlinkSync(path: string): void; 352/** 353 * writeSync. 354 * 355 * @note N/A 356 * @sysCap N/A 357 * @since 6 358 * @permission N/A 359 * @function writeSync 360 * @param {number} fd - file descriptor. 361 * @param {ArrayBuffer | string} buffer - file descriptor. 362 * @param {Object} [options] - options. 363 * @param {number} [options.offset = 0] - offset(bytes) ignored when buffer is string. 364 * @param {number} [options.length = -1] - length(bytes) ignored when buffer is string. 365 * @param {number} [options.position = -1] - position(bytes) where start to write < 0 use read, else use pread. 366 * @param {string} [options.encoding = 'utf-8'] - encoding. 367 * @returns {number} on success number of bytesRead 368 * @throws {TypedError | RangeError | Error} write fail 369 */ 370declare function writeSync(fd: number, buffer: ArrayBuffer | string, options?: { 371 offset?: number; 372 length?: number; 373 position?: number; 374 encoding?: string; 375}): number; 376 377/** 378 * Dir 379 * @devices phone, tablet, tv, wearable, car 380 * @sysCap N/A 381 * @since 6 382 * @permission N/A 383 */ 384declare interface Dir { 385 /** 386 * readSync. 387 * @note N/A 388 * @sysCap N/A 389 * @since 6 390 * @permission N/A 391 * @function readSync 392 * @returns {Dirent} Dirent Object 393 * @throws {TypedError | Error} read fail if read to end, Error.msg = "NoMore" 394 */ 395 readSync(): Dirent; 396 /** 397 * closeSync. 398 * @note N/A 399 * @sysCap N/A 400 * @since 6 401 * @permission N/A 402 * @function closeSync 403 * @returns {void} close success 404 * @throws {TypedError | Error} close fail 405 */ 406 closeSync(): void; 407} 408 409/** 410 * Dirent 411 * @devices phone, tablet, tv, wearable, car 412 * @sysCap N/A 413 * @since 6 414 * @permission N/A 415 */ 416declare interface Dirent { 417 /** 418 * @type {string} 419 * @readonly 420 * @note N/A 421 * @sysCap N/A 422 * @since 6 423 * @permission N/A 424 */ 425 readonly name: string; 426 /** 427 * isBlockDevice. 428 * @note N/A 429 * @sysCap N/A 430 * @since 6 431 * @permission N/A 432 * @returns {boolean} is or not 433 */ 434 isBlockDevice(): boolean; 435 /** 436 * isCharacterDevice. 437 * @note N/A 438 * @sysCap N/A 439 * @since 6 440 * @permission N/A 441 * @returns {boolean} is or not 442 */ 443 isCharacterDevice(): boolean; 444 /** 445 * isDirectory. 446 * @note N/A 447 * @sysCap N/A 448 * @since 6 449 * @permission N/A 450 * @returns {boolean} is or not 451 */ 452 isDirectory(): boolean; 453 /** 454 * isFIFO. 455 * @note N/A 456 * @sysCap N/A 457 * @since 6 458 * @permission N/A 459 * @returns {boolean} is or not 460 */ 461 isFIFO(): boolean; 462 /** 463 * isFile. 464 * @note N/A 465 * @sysCap N/A 466 * @since 6 467 * @permission N/A 468 * @returns {boolean} is or not 469 */ 470 isFile(): boolean; 471 /** 472 * isSocket. 473 * @note N/A 474 * @sysCap N/A 475 * @since 6 476 * @permission N/A 477 * @returns {boolean} is or not 478 */ 479 isSocket(): boolean; 480 /** 481 * isSymbolicLink. 482 * @note N/A 483 * @sysCap N/A 484 * @since 6 485 * @permission N/A 486 * @returns {boolean} is or not 487 */ 488 isSymbolicLink(): boolean; 489} 490 491/** 492 * Stat 493 * @devices phone, tablet, tv, wearable, car 494 * @sysCap N/A 495 * @since 6 496 * @permission N/A 497 */ 498declare interface Stat { 499 /** 500 * @type {number} 501 * @note N/A 502 * @sysCap N/A 503 * @since 6 504 * @permission N/A 505 * @readonly 506 */ 507 readonly dev: number; 508 /** 509 * @type {number} 510 * @note N/A 511 * @sysCap N/A 512 * @since 6 513 * @permission N/A 514 * @readonly 515 */ 516 readonly ino: number; 517 /** 518 * @type {number} 519 * @note N/A 520 * @sysCap N/A 521 * @since 6 522 * @permission N/A 523 * @readonly 524 */ 525 readonly mode: number; 526 /** 527 * @type {number} 528 * @note N/A 529 * @sysCap N/A 530 * @since 6 531 * @permission N/A 532 * @readonly 533 */ 534 readonly nlink: number; 535 /** 536 * @type {number} 537 * @note N/A 538 * @sysCap N/A 539 * @since 6 540 * @permission N/A 541 * @readonly 542 */ 543 readonly uid: number; 544 /** 545 * @type {number} 546 * @note N/A 547 * @sysCap N/A 548 * @since 6 549 * @permission N/A 550 * @readonly 551 */ 552 readonly gid: number; 553 /** 554 * @type {number} 555 * @note N/A 556 * @sysCap N/A 557 * @since 6 558 * @permission N/A 559 * @readonly 560 */ 561 readonly rdev: number; 562 /** 563 * @type {number} 564 * @note N/A 565 * @sysCap N/A 566 * @since 6 567 * @permission N/A 568 * @readonly 569 */ 570 readonly size: number; 571 /** 572 * @type {number} 573 * @note N/A 574 * @sysCap N/A 575 * @since 6 576 * @permission N/A 577 * @readonly 578 */ 579 readonly blocks: number; 580 /** 581 * @type {number} 582 * @note N/A 583 * @sysCap N/A 584 * @since 6 585 * @permission N/A 586 * @readonly 587 */ 588 readonly atime: number; 589 /** 590 * @type {number} 591 * @note N/A 592 * @sysCap N/A 593 * @since 6 594 * @permission N/A 595 * @readonly 596 */ 597 readonly mtime: number; 598 /** 599 * @type {number} 600 * @note N/A 601 * @sysCap N/A 602 * @since 6 603 * @permission N/A 604 * @readonly 605 */ 606 readonly ctime: number; 607 /** 608 * isBlockDevice. 609 * @note N/A 610 * @sysCap N/A 611 * @since 6 612 * @permission N/A 613 * @returns {boolean} is or not 614 */ 615 isBlockDevice(): boolean; 616 /** 617 * isCharacterDevice. 618 * @note N/A 619 * @sysCap N/A 620 * @since 6 621 * @permission N/A 622 * @returns {boolean} is or not 623 */ 624 isCharacterDevice(): boolean; 625 /** 626 * isDirectory. 627 * @note N/A 628 * @sysCap N/A 629 * @since 6 630 * @permission N/A 631 * @returns {boolean} is or not 632 */ 633 isDirectory(): boolean; 634 /** 635 * isFIFO. 636 * @note N/A 637 * @sysCap N/A 638 * @since 6 639 * @permission N/A 640 * @returns {boolean} is or not 641 */ 642 isFIFO(): boolean; 643 /** 644 * isFile. 645 * @note N/A 646 * @sysCap N/A 647 * @since 6 648 * @permission N/A 649 * @returns {boolean} is or not 650 */ 651 isFile(): boolean; 652 /** 653 * isSocket. 654 * @note N/A 655 * @sysCap N/A 656 * @since 6 657 * @permission N/A 658 * @returns {boolean} is or not 659 */ 660 isSocket(): boolean; 661 /** 662 * isSymbolicLink. 663 * @note N/A 664 * @sysCap N/A 665 * @since 6 666 * @permission N/A 667 * @returns {boolean} is or not 668 */ 669 isSymbolicLink(): boolean; 670} 671 672/** 673 * Stream 674 * @devices phone, tablet, tv, wearable, car 675 * @sysCap N/A 676 * @since 6 677 * @permission N/A 678 */ 679declare interface Stream { 680 /** 681 * closeSync. 682 * 683 * @note N/A 684 * @sysCap N/A 685 * @since 6 686 * @permission N/A 687 * @returns {void} close success 688 * @throws {TypedError | Error} close fail 689 */ 690 closeSync(): void; 691 /** 692 * flushSync. 693 * 694 * @note N/A 695 * @sysCap N/A 696 * @since 7 697 * @permission N/A 698 * @returns {void} flush success 699 * @throws {Error} flush fail 700 */ 701 flushSync(): void; 702 /** 703 * writeSync. 704 * 705 * @note N/A 706 * @sysCap N/A 707 * @since 7 708 * @permission N/A 709 * @param {ArrayBuffer | string} buffer - file description. 710 * @param {Object} [options] - options. 711 * @param {number} [options.offset = 0] - offset(bytes) ignored when buffer is string. 712 * @param {number} [options.length = -1] - length(bytes) ignored when buffer is string. 713 * @param {number} [options.position = -1] - position(bytes) where start to write < 0 use read, else use pread. 714 * @param {string} [options.encoding = 'utf-8'] - encoding. 715 * @returns {number} on success number of bytes written 716 * @throws {TypedError | Error} write fail 717 */ 718 writeSync(buffer: ArrayBuffer | string, options?: { 719 offset?: number; 720 length?: number; 721 position?: number; 722 encoding?: string; 723 }): number; 724 /** 725 * readSync. 726 * 727 * @note N/A 728 * @sysCap N/A 729 * @since 7 730 * @permission N/A 731 * @param {ArrayBuffer} buffer - file description. 732 * @param {Object} [options] - options. 733 * @param {number} [options.offset = 0] - offset. 734 * @param {number} [options.length = -1] - length. 735 * @returns {number} number of bytesRead 736 * @throws {TypedError | Error} read fail 737 */ 738 readSync(buffer: ArrayBuffer, options?: { 739 position?: number; 740 offset?: number; 741 length?: number; 742 }): number; 743}