promises.d.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /// <reference types="node" />
  2. /// <reference types="node" />
  3. import { Volume, TData, TMode, TFlags, TFlagsCopy, TTime, IOptions, IAppendFileOptions, IMkdirOptions, IReaddirOptions, IReadFileOptions, IRealpathOptions, IWriteFileOptions, IStatOptions, IRmOptions, IFStatOptions } from './volume';
  4. import Stats from './Stats';
  5. import Dirent from './Dirent';
  6. import { TDataOut } from './encoding';
  7. import { PathLike, symlink } from 'fs';
  8. export interface TFileHandleReadResult {
  9. bytesRead: number;
  10. buffer: Buffer | Uint8Array;
  11. }
  12. export interface TFileHandleWriteResult {
  13. bytesWritten: number;
  14. buffer: Buffer | Uint8Array;
  15. }
  16. export interface IFileHandle {
  17. fd: number;
  18. appendFile(data: TData, options?: IAppendFileOptions | string): Promise<void>;
  19. chmod(mode: TMode): Promise<void>;
  20. chown(uid: number, gid: number): Promise<void>;
  21. close(): Promise<void>;
  22. datasync(): Promise<void>;
  23. read(buffer: Buffer | Uint8Array, offset: number, length: number, position: number): Promise<TFileHandleReadResult>;
  24. readFile(options?: IReadFileOptions | string): Promise<TDataOut>;
  25. stat(options?: IStatOptions): Promise<Stats>;
  26. truncate(len?: number): Promise<void>;
  27. utimes(atime: TTime, mtime: TTime): Promise<void>;
  28. write(buffer: Buffer | Uint8Array, offset?: number, length?: number, position?: number): Promise<TFileHandleWriteResult>;
  29. writeFile(data: TData, options?: IWriteFileOptions): Promise<void>;
  30. }
  31. export declare type TFileHandle = PathLike | IFileHandle;
  32. export interface IPromisesAPI {
  33. FileHandle: any;
  34. access(path: PathLike, mode?: number): Promise<void>;
  35. appendFile(path: TFileHandle, data: TData, options?: IAppendFileOptions | string): Promise<void>;
  36. chmod(path: PathLike, mode: TMode): Promise<void>;
  37. chown(path: PathLike, uid: number, gid: number): Promise<void>;
  38. copyFile(src: PathLike, dest: PathLike, flags?: TFlagsCopy): Promise<void>;
  39. lchmod(path: PathLike, mode: TMode): Promise<void>;
  40. lchown(path: PathLike, uid: number, gid: number): Promise<void>;
  41. link(existingPath: PathLike, newPath: PathLike): Promise<void>;
  42. lstat(path: PathLike, options?: IStatOptions): Promise<Stats>;
  43. mkdir(path: PathLike, options?: TMode | IMkdirOptions): Promise<void>;
  44. mkdtemp(prefix: string, options?: IOptions): Promise<TDataOut>;
  45. open(path: PathLike, flags: TFlags, mode?: TMode): Promise<FileHandle>;
  46. readdir(path: PathLike, options?: IReaddirOptions | string): Promise<TDataOut[] | Dirent[]>;
  47. readFile(id: TFileHandle, options?: IReadFileOptions | string): Promise<TDataOut>;
  48. readlink(path: PathLike, options?: IOptions): Promise<TDataOut>;
  49. realpath(path: PathLike, options?: IRealpathOptions | string): Promise<TDataOut>;
  50. rename(oldPath: PathLike, newPath: PathLike): Promise<void>;
  51. rmdir(path: PathLike): Promise<void>;
  52. rm(path: PathLike, options?: IRmOptions): Promise<void>;
  53. stat(path: PathLike, options?: IStatOptions): Promise<Stats>;
  54. symlink(target: PathLike, path: PathLike, type?: symlink.Type): Promise<void>;
  55. truncate(path: PathLike, len?: number): Promise<void>;
  56. unlink(path: PathLike): Promise<void>;
  57. utimes(path: PathLike, atime: TTime, mtime: TTime): Promise<void>;
  58. writeFile(id: TFileHandle, data: TData, options?: IWriteFileOptions): Promise<void>;
  59. }
  60. export declare class FileHandle implements IFileHandle {
  61. private vol;
  62. fd: number;
  63. constructor(vol: Volume, fd: number);
  64. appendFile(data: TData, options?: IAppendFileOptions | string): Promise<void>;
  65. chmod(mode: TMode): Promise<void>;
  66. chown(uid: number, gid: number): Promise<void>;
  67. close(): Promise<void>;
  68. datasync(): Promise<void>;
  69. read(buffer: Buffer | Uint8Array, offset: number, length: number, position: number): Promise<TFileHandleReadResult>;
  70. readFile(options?: IReadFileOptions | string): Promise<TDataOut>;
  71. stat(options?: IFStatOptions): Promise<Stats>;
  72. sync(): Promise<void>;
  73. truncate(len?: number): Promise<void>;
  74. utimes(atime: TTime, mtime: TTime): Promise<void>;
  75. write(buffer: Buffer | Uint8Array, offset?: number, length?: number, position?: number): Promise<TFileHandleWriteResult>;
  76. writeFile(data: TData, options?: IWriteFileOptions): Promise<void>;
  77. }
  78. export default function createPromisesApi(vol: Volume): null | IPromisesAPI;