promises.d.ts 4.2 KB

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