NodeFS.d.ts 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /// <reference types="node" />
  2. /// <reference types="node" />
  3. /// <reference types="node" />
  4. /// <reference types="node" />
  5. import fs, { BigIntStats, Stats } from 'fs';
  6. import { CreateReadStreamOptions, CreateWriteStreamOptions, Dir, StatWatcher, WatchFileCallback, WatchFileOptions, OpendirOptions } from './FakeFS';
  7. import { Dirent, SymlinkType, StatSyncOptions, StatOptions } from './FakeFS';
  8. import { BasePortableFakeFS, WriteFileOptions } from './FakeFS';
  9. import { MkdirOptions, RmdirOptions, WatchOptions, WatchCallback, Watcher } from './FakeFS';
  10. import { FSPath, PortablePath, Filename } from './path';
  11. export declare class NodeFS extends BasePortableFakeFS {
  12. private readonly realFs;
  13. constructor(realFs?: typeof fs);
  14. getExtractHint(): boolean;
  15. getRealPath(): PortablePath;
  16. resolve(p: PortablePath): PortablePath;
  17. openPromise(p: PortablePath, flags: string, mode?: number): Promise<number>;
  18. openSync(p: PortablePath, flags: string, mode?: number): number;
  19. opendirPromise(p: PortablePath, opts?: OpendirOptions): Promise<Dir<PortablePath>>;
  20. opendirSync(p: PortablePath, opts?: OpendirOptions): Dir<PortablePath>;
  21. readPromise(fd: number, buffer: Buffer, offset?: number, length?: number, position?: number | null): Promise<number>;
  22. readSync(fd: number, buffer: Buffer, offset: number, length: number, position: number): number;
  23. writePromise(fd: number, buffer: Buffer, offset?: number, length?: number, position?: number): Promise<number>;
  24. writePromise(fd: number, buffer: string, position?: number): Promise<number>;
  25. writeSync(fd: number, buffer: Buffer, offset?: number, length?: number, position?: number): number;
  26. writeSync(fd: number, buffer: string, position?: number): number;
  27. closePromise(fd: number): Promise<void>;
  28. closeSync(fd: number): void;
  29. createReadStream(p: PortablePath | null, opts?: CreateReadStreamOptions): fs.ReadStream;
  30. createWriteStream(p: PortablePath | null, opts?: CreateWriteStreamOptions): fs.WriteStream;
  31. realpathPromise(p: PortablePath): Promise<PortablePath>;
  32. realpathSync(p: PortablePath): PortablePath;
  33. existsPromise(p: PortablePath): Promise<boolean>;
  34. accessSync(p: PortablePath, mode?: number): void;
  35. accessPromise(p: PortablePath, mode?: number): Promise<void>;
  36. existsSync(p: PortablePath): boolean;
  37. statPromise(p: PortablePath): Promise<Stats>;
  38. statPromise(p: PortablePath, opts: (StatOptions & {
  39. bigint?: false | undefined;
  40. }) | undefined): Promise<Stats>;
  41. statPromise(p: PortablePath, opts: StatOptions & {
  42. bigint: true;
  43. }): Promise<BigIntStats>;
  44. statSync(p: PortablePath): Stats;
  45. statSync(p: PortablePath, opts?: StatSyncOptions & {
  46. bigint?: false | undefined;
  47. throwIfNoEntry: false;
  48. }): Stats | undefined;
  49. statSync(p: PortablePath, opts: StatSyncOptions & {
  50. bigint: true;
  51. throwIfNoEntry: false;
  52. }): BigIntStats | undefined;
  53. statSync(p: PortablePath, opts?: StatSyncOptions & {
  54. bigint?: false | undefined;
  55. }): Stats;
  56. statSync(p: PortablePath, opts: StatSyncOptions & {
  57. bigint: true;
  58. }): BigIntStats;
  59. statSync(p: PortablePath, opts: StatSyncOptions & {
  60. bigint: boolean;
  61. throwIfNoEntry?: false | undefined;
  62. }): Stats | BigIntStats;
  63. fstatPromise(fd: number): Promise<Stats>;
  64. fstatPromise(fd: number, opts: {
  65. bigint: true;
  66. }): Promise<BigIntStats>;
  67. fstatPromise(fd: number, opts?: {
  68. bigint: boolean;
  69. }): Promise<BigIntStats | Stats>;
  70. fstatSync(fd: number): Stats;
  71. fstatSync(fd: number, opts: {
  72. bigint: true;
  73. }): BigIntStats;
  74. fstatSync(fd: number, opts?: {
  75. bigint: boolean;
  76. }): BigIntStats | Stats;
  77. lstatPromise(p: PortablePath): Promise<Stats>;
  78. lstatPromise(p: PortablePath, opts: (StatOptions & {
  79. bigint?: false | undefined;
  80. }) | undefined): Promise<Stats>;
  81. lstatPromise(p: PortablePath, opts: StatOptions & {
  82. bigint: true;
  83. }): Promise<BigIntStats>;
  84. lstatSync(p: PortablePath): Stats;
  85. lstatSync(p: PortablePath, opts?: StatSyncOptions & {
  86. bigint?: false | undefined;
  87. throwIfNoEntry: false;
  88. }): Stats | undefined;
  89. lstatSync(p: PortablePath, opts: StatSyncOptions & {
  90. bigint: true;
  91. throwIfNoEntry: false;
  92. }): BigIntStats | undefined;
  93. lstatSync(p: PortablePath, opts?: StatSyncOptions & {
  94. bigint?: false | undefined;
  95. }): Stats;
  96. lstatSync(p: PortablePath, opts: StatSyncOptions & {
  97. bigint: true;
  98. }): BigIntStats;
  99. lstatSync(p: PortablePath, opts: StatSyncOptions & {
  100. bigint: boolean;
  101. throwIfNoEntry?: false | undefined;
  102. }): Stats | BigIntStats;
  103. fchmodPromise(fd: number, mask: number): Promise<void>;
  104. fchmodSync(fd: number, mask: number): void;
  105. chmodPromise(p: PortablePath, mask: number): Promise<void>;
  106. chmodSync(p: PortablePath, mask: number): void;
  107. fchownPromise(fd: number, uid: number, gid: number): Promise<void>;
  108. fchownSync(fd: number, uid: number, gid: number): void;
  109. chownPromise(p: PortablePath, uid: number, gid: number): Promise<void>;
  110. chownSync(p: PortablePath, uid: number, gid: number): void;
  111. renamePromise(oldP: PortablePath, newP: PortablePath): Promise<void>;
  112. renameSync(oldP: PortablePath, newP: PortablePath): void;
  113. copyFilePromise(sourceP: PortablePath, destP: PortablePath, flags?: number): Promise<void>;
  114. copyFileSync(sourceP: PortablePath, destP: PortablePath, flags?: number): void;
  115. appendFilePromise(p: FSPath<PortablePath>, content: string | Buffer | ArrayBuffer | DataView, opts?: WriteFileOptions): Promise<void>;
  116. appendFileSync(p: PortablePath, content: string | Buffer | ArrayBuffer | DataView, opts?: WriteFileOptions): void;
  117. writeFilePromise(p: FSPath<PortablePath>, content: string | Buffer | ArrayBuffer | DataView, opts?: WriteFileOptions): Promise<void>;
  118. writeFileSync(p: PortablePath, content: string | Buffer | ArrayBuffer | DataView, opts?: WriteFileOptions): void;
  119. unlinkPromise(p: PortablePath): Promise<void>;
  120. unlinkSync(p: PortablePath): void;
  121. utimesPromise(p: PortablePath, atime: Date | string | number, mtime: Date | string | number): Promise<void>;
  122. utimesSync(p: PortablePath, atime: Date | string | number, mtime: Date | string | number): void;
  123. private lutimesPromiseImpl;
  124. private lutimesSyncImpl;
  125. mkdirPromise(p: PortablePath, opts?: MkdirOptions): Promise<string | undefined>;
  126. mkdirSync(p: PortablePath, opts?: MkdirOptions): string | undefined;
  127. rmdirPromise(p: PortablePath, opts?: RmdirOptions): Promise<void>;
  128. rmdirSync(p: PortablePath, opts?: RmdirOptions): void;
  129. linkPromise(existingP: PortablePath, newP: PortablePath): Promise<void>;
  130. linkSync(existingP: PortablePath, newP: PortablePath): void;
  131. symlinkPromise(target: PortablePath, p: PortablePath, type?: SymlinkType): Promise<void>;
  132. symlinkSync(target: PortablePath, p: PortablePath, type?: SymlinkType): void;
  133. readFilePromise(p: FSPath<PortablePath>, encoding: 'utf8'): Promise<string>;
  134. readFilePromise(p: FSPath<PortablePath>, encoding?: string): Promise<Buffer>;
  135. readFileSync(p: FSPath<PortablePath>, encoding: 'utf8'): string;
  136. readFileSync(p: FSPath<PortablePath>, encoding?: string): Buffer;
  137. readdirPromise(p: PortablePath): Promise<Array<Filename>>;
  138. readdirPromise(p: PortablePath, opts: {
  139. withFileTypes: false;
  140. } | null): Promise<Array<Filename>>;
  141. readdirPromise(p: PortablePath, opts: {
  142. withFileTypes: true;
  143. }): Promise<Array<Dirent>>;
  144. readdirPromise(p: PortablePath, opts: {
  145. withFileTypes: boolean;
  146. }): Promise<Array<Filename> | Array<Dirent>>;
  147. readdirSync(p: PortablePath): Array<Filename>;
  148. readdirSync(p: PortablePath, opts: {
  149. withFileTypes: false;
  150. } | null): Array<Filename>;
  151. readdirSync(p: PortablePath, opts: {
  152. withFileTypes: true;
  153. }): Array<Dirent>;
  154. readdirSync(p: PortablePath, opts: {
  155. withFileTypes: boolean;
  156. }): Array<Filename> | Array<Dirent>;
  157. readlinkPromise(p: PortablePath): Promise<PortablePath>;
  158. readlinkSync(p: PortablePath): PortablePath;
  159. truncatePromise(p: PortablePath, len?: number): Promise<void>;
  160. truncateSync(p: PortablePath, len?: number): void;
  161. ftruncatePromise(fd: number, len?: number): Promise<void>;
  162. ftruncateSync(fd: number, len?: number): void;
  163. watch(p: PortablePath, cb?: WatchCallback): Watcher;
  164. watch(p: PortablePath, opts: WatchOptions, cb?: WatchCallback): Watcher;
  165. watchFile(p: PortablePath, cb: WatchFileCallback): StatWatcher;
  166. watchFile(p: PortablePath, opts: WatchFileOptions, cb: WatchFileCallback): StatWatcher;
  167. unwatchFile(p: PortablePath, cb?: WatchFileCallback): void;
  168. private makeCallback;
  169. }