typespeed 2.3.6 → 2.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (258) hide show
  1. package/app/src/config-development.json +3 -2
  2. package/app/src/test-socket.class.ts +56 -0
  3. package/app/src/views/socket.html +23 -0
  4. package/dist/introduction/decorator/example-import.class.js +17 -0
  5. package/dist/introduction/decorator/main-app.js +14 -0
  6. package/dist/introduction/decorator/main-decorator.js +127 -0
  7. package/dist/introduction/decorator/main-import.js +1 -0
  8. package/dist/introduction/decorator/main-reflect.js +38 -0
  9. package/dist/introduction/web-services/db-init.js +33 -0
  10. package/dist/introduction/web-services/db-singleton.js +49 -0
  11. package/dist/introduction/web-services/http-if.js +12 -0
  12. package/dist/introduction/web-services/http-init.js +7 -0
  13. package/dist/introduction/web-services/http-router.js +23 -0
  14. package/dist/{database.decorator.js → src/database.decorator.js} +2 -4
  15. package/dist/{default → src/default}/express-server.class.js +20 -5
  16. package/dist/{default → src/default}/rabbitmq.class.js +3 -3
  17. package/dist/{default → src/default}/redis.class.js +1 -1
  18. package/dist/src/default/socket-io.class.js +64 -0
  19. package/dist/{typespeed.js → src/typespeed.js} +6 -3
  20. package/dist/typespeed.d.ts +19 -1
  21. package/package.json +8 -8
  22. package/src/database.decorator.ts +2 -4
  23. package/src/default/express-server.class.ts +18 -7
  24. package/src/default/rabbitmq.class.ts +3 -3
  25. package/src/default/redis.class.ts +1 -1
  26. package/src/default/socket-io.class.ts +68 -0
  27. package/src/factory/server-factory.class.ts +1 -1
  28. package/src/typespeed.d.ts +19 -1
  29. package/src/typespeed.ts +7 -4
  30. package/test/socket.test.ts +60 -0
  31. package/tsconfig.json +2 -1
  32. package/app/node_modules/.package-lock.json +0 -134
  33. package/app/node_modules/@types/body-parser/LICENSE +0 -21
  34. package/app/node_modules/@types/body-parser/README.md +0 -16
  35. package/app/node_modules/@types/body-parser/index.d.ts +0 -107
  36. package/app/node_modules/@types/body-parser/package.json +0 -58
  37. package/app/node_modules/@types/connect/LICENSE +0 -21
  38. package/app/node_modules/@types/connect/README.md +0 -16
  39. package/app/node_modules/@types/connect/index.d.ts +0 -93
  40. package/app/node_modules/@types/connect/package.json +0 -32
  41. package/app/node_modules/@types/express/LICENSE +0 -21
  42. package/app/node_modules/@types/express/README.md +0 -16
  43. package/app/node_modules/@types/express/index.d.ts +0 -136
  44. package/app/node_modules/@types/express/package.json +0 -45
  45. package/app/node_modules/@types/express-serve-static-core/LICENSE +0 -21
  46. package/app/node_modules/@types/express-serve-static-core/README.md +0 -16
  47. package/app/node_modules/@types/express-serve-static-core/index.d.ts +0 -1281
  48. package/app/node_modules/@types/express-serve-static-core/package.json +0 -55
  49. package/app/node_modules/@types/mime/LICENSE +0 -21
  50. package/app/node_modules/@types/mime/Mime.d.ts +0 -10
  51. package/app/node_modules/@types/mime/README.md +0 -16
  52. package/app/node_modules/@types/mime/index.d.ts +0 -35
  53. package/app/node_modules/@types/mime/lite.d.ts +0 -7
  54. package/app/node_modules/@types/mime/package.json +0 -29
  55. package/app/node_modules/@types/node/LICENSE +0 -21
  56. package/app/node_modules/@types/node/README.md +0 -16
  57. package/app/node_modules/@types/node/assert/strict.d.ts +0 -8
  58. package/app/node_modules/@types/node/assert.d.ts +0 -961
  59. package/app/node_modules/@types/node/async_hooks.d.ts +0 -518
  60. package/app/node_modules/@types/node/buffer.d.ts +0 -2323
  61. package/app/node_modules/@types/node/child_process.d.ts +0 -1399
  62. package/app/node_modules/@types/node/cluster.d.ts +0 -410
  63. package/app/node_modules/@types/node/console.d.ts +0 -412
  64. package/app/node_modules/@types/node/constants.d.ts +0 -18
  65. package/app/node_modules/@types/node/crypto.d.ts +0 -3973
  66. package/app/node_modules/@types/node/dgram.d.ts +0 -545
  67. package/app/node_modules/@types/node/diagnostics_channel.d.ts +0 -192
  68. package/app/node_modules/@types/node/dns/promises.d.ts +0 -370
  69. package/app/node_modules/@types/node/dns.d.ts +0 -660
  70. package/app/node_modules/@types/node/dom-events.d.ts +0 -126
  71. package/app/node_modules/@types/node/domain.d.ts +0 -170
  72. package/app/node_modules/@types/node/events.d.ts +0 -682
  73. package/app/node_modules/@types/node/fs/promises.d.ts +0 -1159
  74. package/app/node_modules/@types/node/fs.d.ts +0 -3976
  75. package/app/node_modules/@types/node/globals.d.ts +0 -303
  76. package/app/node_modules/@types/node/globals.global.d.ts +0 -1
  77. package/app/node_modules/@types/node/http.d.ts +0 -1714
  78. package/app/node_modules/@types/node/http2.d.ts +0 -2133
  79. package/app/node_modules/@types/node/https.d.ts +0 -542
  80. package/app/node_modules/@types/node/index.d.ts +0 -134
  81. package/app/node_modules/@types/node/inspector.d.ts +0 -2741
  82. package/app/node_modules/@types/node/module.d.ts +0 -115
  83. package/app/node_modules/@types/node/net.d.ts +0 -883
  84. package/app/node_modules/@types/node/os.d.ts +0 -473
  85. package/app/node_modules/@types/node/package.json +0 -237
  86. package/app/node_modules/@types/node/path.d.ts +0 -191
  87. package/app/node_modules/@types/node/perf_hooks.d.ts +0 -625
  88. package/app/node_modules/@types/node/process.d.ts +0 -1488
  89. package/app/node_modules/@types/node/punycode.d.ts +0 -117
  90. package/app/node_modules/@types/node/querystring.d.ts +0 -131
  91. package/app/node_modules/@types/node/readline/promises.d.ts +0 -143
  92. package/app/node_modules/@types/node/readline.d.ts +0 -653
  93. package/app/node_modules/@types/node/repl.d.ts +0 -424
  94. package/app/node_modules/@types/node/stream/consumers.d.ts +0 -12
  95. package/app/node_modules/@types/node/stream/promises.d.ts +0 -42
  96. package/app/node_modules/@types/node/stream/web.d.ts +0 -330
  97. package/app/node_modules/@types/node/stream.d.ts +0 -1440
  98. package/app/node_modules/@types/node/string_decoder.d.ts +0 -67
  99. package/app/node_modules/@types/node/test.d.ts +0 -783
  100. package/app/node_modules/@types/node/timers/promises.d.ts +0 -93
  101. package/app/node_modules/@types/node/timers.d.ts +0 -101
  102. package/app/node_modules/@types/node/tls.d.ts +0 -1111
  103. package/app/node_modules/@types/node/trace_events.d.ts +0 -171
  104. package/app/node_modules/@types/node/ts4.8/assert/strict.d.ts +0 -8
  105. package/app/node_modules/@types/node/ts4.8/assert.d.ts +0 -961
  106. package/app/node_modules/@types/node/ts4.8/async_hooks.d.ts +0 -518
  107. package/app/node_modules/@types/node/ts4.8/buffer.d.ts +0 -2323
  108. package/app/node_modules/@types/node/ts4.8/child_process.d.ts +0 -1399
  109. package/app/node_modules/@types/node/ts4.8/cluster.d.ts +0 -410
  110. package/app/node_modules/@types/node/ts4.8/console.d.ts +0 -412
  111. package/app/node_modules/@types/node/ts4.8/constants.d.ts +0 -18
  112. package/app/node_modules/@types/node/ts4.8/crypto.d.ts +0 -3972
  113. package/app/node_modules/@types/node/ts4.8/dgram.d.ts +0 -545
  114. package/app/node_modules/@types/node/ts4.8/diagnostics_channel.d.ts +0 -192
  115. package/app/node_modules/@types/node/ts4.8/dns/promises.d.ts +0 -370
  116. package/app/node_modules/@types/node/ts4.8/dns.d.ts +0 -660
  117. package/app/node_modules/@types/node/ts4.8/dom-events.d.ts +0 -126
  118. package/app/node_modules/@types/node/ts4.8/domain.d.ts +0 -170
  119. package/app/node_modules/@types/node/ts4.8/events.d.ts +0 -682
  120. package/app/node_modules/@types/node/ts4.8/fs/promises.d.ts +0 -1138
  121. package/app/node_modules/@types/node/ts4.8/fs.d.ts +0 -3875
  122. package/app/node_modules/@types/node/ts4.8/globals.d.ts +0 -302
  123. package/app/node_modules/@types/node/ts4.8/globals.global.d.ts +0 -1
  124. package/app/node_modules/@types/node/ts4.8/http.d.ts +0 -1651
  125. package/app/node_modules/@types/node/ts4.8/http2.d.ts +0 -2133
  126. package/app/node_modules/@types/node/ts4.8/https.d.ts +0 -542
  127. package/app/node_modules/@types/node/ts4.8/index.d.ts +0 -88
  128. package/app/node_modules/@types/node/ts4.8/inspector.d.ts +0 -2741
  129. package/app/node_modules/@types/node/ts4.8/module.d.ts +0 -115
  130. package/app/node_modules/@types/node/ts4.8/net.d.ts +0 -883
  131. package/app/node_modules/@types/node/ts4.8/os.d.ts +0 -473
  132. package/app/node_modules/@types/node/ts4.8/path.d.ts +0 -191
  133. package/app/node_modules/@types/node/ts4.8/perf_hooks.d.ts +0 -625
  134. package/app/node_modules/@types/node/ts4.8/process.d.ts +0 -1488
  135. package/app/node_modules/@types/node/ts4.8/punycode.d.ts +0 -117
  136. package/app/node_modules/@types/node/ts4.8/querystring.d.ts +0 -131
  137. package/app/node_modules/@types/node/ts4.8/readline/promises.d.ts +0 -143
  138. package/app/node_modules/@types/node/ts4.8/readline.d.ts +0 -653
  139. package/app/node_modules/@types/node/ts4.8/repl.d.ts +0 -424
  140. package/app/node_modules/@types/node/ts4.8/stream/consumers.d.ts +0 -12
  141. package/app/node_modules/@types/node/ts4.8/stream/promises.d.ts +0 -42
  142. package/app/node_modules/@types/node/ts4.8/stream/web.d.ts +0 -330
  143. package/app/node_modules/@types/node/ts4.8/stream.d.ts +0 -1440
  144. package/app/node_modules/@types/node/ts4.8/string_decoder.d.ts +0 -67
  145. package/app/node_modules/@types/node/ts4.8/test.d.ts +0 -784
  146. package/app/node_modules/@types/node/ts4.8/timers/promises.d.ts +0 -93
  147. package/app/node_modules/@types/node/ts4.8/timers.d.ts +0 -94
  148. package/app/node_modules/@types/node/ts4.8/tls.d.ts +0 -1111
  149. package/app/node_modules/@types/node/ts4.8/trace_events.d.ts +0 -171
  150. package/app/node_modules/@types/node/ts4.8/tty.d.ts +0 -206
  151. package/app/node_modules/@types/node/ts4.8/url.d.ts +0 -902
  152. package/app/node_modules/@types/node/ts4.8/util.d.ts +0 -2017
  153. package/app/node_modules/@types/node/ts4.8/v8.d.ts +0 -541
  154. package/app/node_modules/@types/node/ts4.8/vm.d.ts +0 -644
  155. package/app/node_modules/@types/node/ts4.8/wasi.d.ts +0 -158
  156. package/app/node_modules/@types/node/ts4.8/worker_threads.d.ts +0 -695
  157. package/app/node_modules/@types/node/ts4.8/zlib.d.ts +0 -517
  158. package/app/node_modules/@types/node/tty.d.ts +0 -206
  159. package/app/node_modules/@types/node/url.d.ts +0 -902
  160. package/app/node_modules/@types/node/util.d.ts +0 -2017
  161. package/app/node_modules/@types/node/v8.d.ts +0 -541
  162. package/app/node_modules/@types/node/vm.d.ts +0 -644
  163. package/app/node_modules/@types/node/wasi.d.ts +0 -158
  164. package/app/node_modules/@types/node/worker_threads.d.ts +0 -695
  165. package/app/node_modules/@types/node/zlib.d.ts +0 -517
  166. package/app/node_modules/@types/qs/LICENSE +0 -21
  167. package/app/node_modules/@types/qs/README.md +0 -16
  168. package/app/node_modules/@types/qs/index.d.ts +0 -62
  169. package/app/node_modules/@types/qs/package.json +0 -65
  170. package/app/node_modules/@types/range-parser/LICENSE +0 -21
  171. package/app/node_modules/@types/range-parser/README.md +0 -55
  172. package/app/node_modules/@types/range-parser/index.d.ts +0 -35
  173. package/app/node_modules/@types/range-parser/package.json +0 -25
  174. package/app/node_modules/@types/send/LICENSE +0 -21
  175. package/app/node_modules/@types/send/README.md +0 -16
  176. package/app/node_modules/@types/send/index.d.ts +0 -231
  177. package/app/node_modules/@types/send/package.json +0 -33
  178. package/app/node_modules/@types/serve-static/LICENSE +0 -21
  179. package/app/node_modules/@types/serve-static/README.md +0 -16
  180. package/app/node_modules/@types/serve-static/index.d.ts +0 -113
  181. package/app/node_modules/@types/serve-static/package.json +0 -38
  182. package/app/node_modules/colors/LICENSE +0 -25
  183. package/app/node_modules/colors/README.md +0 -221
  184. package/app/node_modules/colors/examples/normal-usage.js +0 -82
  185. package/app/node_modules/colors/examples/safe-string.js +0 -79
  186. package/app/node_modules/colors/index.d.ts +0 -136
  187. package/app/node_modules/colors/lib/colors.js +0 -211
  188. package/app/node_modules/colors/lib/custom/trap.js +0 -46
  189. package/app/node_modules/colors/lib/custom/zalgo.js +0 -110
  190. package/app/node_modules/colors/lib/extendStringPrototype.js +0 -110
  191. package/app/node_modules/colors/lib/index.js +0 -13
  192. package/app/node_modules/colors/lib/maps/america.js +0 -10
  193. package/app/node_modules/colors/lib/maps/rainbow.js +0 -12
  194. package/app/node_modules/colors/lib/maps/random.js +0 -11
  195. package/app/node_modules/colors/lib/maps/zebra.js +0 -5
  196. package/app/node_modules/colors/lib/styles.js +0 -95
  197. package/app/node_modules/colors/lib/system/has-flag.js +0 -35
  198. package/app/node_modules/colors/lib/system/supports-colors.js +0 -151
  199. package/app/node_modules/colors/package.json +0 -45
  200. package/app/node_modules/colors/safe.d.ts +0 -48
  201. package/app/node_modules/colors/safe.js +0 -10
  202. package/app/node_modules/colors/themes/generic-logging.js +0 -12
  203. package/app/node_modules/dateformat/LICENSE +0 -20
  204. package/app/node_modules/dateformat/Readme.md +0 -204
  205. package/app/node_modules/dateformat/lib/dateformat.js +0 -1
  206. package/app/node_modules/dateformat/package.json +0 -38
  207. package/app/node_modules/mkdirp/CHANGELOG.md +0 -15
  208. package/app/node_modules/mkdirp/LICENSE +0 -21
  209. package/app/node_modules/mkdirp/bin/cmd.js +0 -68
  210. package/app/node_modules/mkdirp/index.js +0 -31
  211. package/app/node_modules/mkdirp/lib/find-made.js +0 -29
  212. package/app/node_modules/mkdirp/lib/mkdirp-manual.js +0 -64
  213. package/app/node_modules/mkdirp/lib/mkdirp-native.js +0 -39
  214. package/app/node_modules/mkdirp/lib/opts-arg.js +0 -23
  215. package/app/node_modules/mkdirp/lib/path-arg.js +0 -29
  216. package/app/node_modules/mkdirp/lib/use-native.js +0 -10
  217. package/app/node_modules/mkdirp/package.json +0 -44
  218. package/app/node_modules/mkdirp/readme.markdown +0 -266
  219. package/app/node_modules/tinytim/.travis.yml +0 -5
  220. package/app/node_modules/tinytim/README.md +0 -212
  221. package/app/node_modules/tinytim/index.js +0 -1
  222. package/app/node_modules/tinytim/lib/index.js +0 -55
  223. package/app/node_modules/tinytim/lib/tinytim.js +0 -50
  224. package/app/node_modules/tinytim/package.json +0 -24
  225. package/app/node_modules/tinytim/test/files/html.tim +0 -1
  226. package/app/node_modules/tinytim/test/files/string.tim +0 -1
  227. package/app/node_modules/tinytim/test/files/string2.tim +0 -1
  228. package/app/node_modules/tinytim/test/render-file-replace.js +0 -39
  229. package/app/node_modules/tinytim/test/render-replace.js +0 -94
  230. package/app/node_modules/tinytim/test/tim-replace.js +0 -95
  231. package/app/node_modules/tracer/README.md +0 -747
  232. package/app/node_modules/tracer/lib/color_console.js +0 -15
  233. package/app/node_modules/tracer/lib/console.js +0 -165
  234. package/app/node_modules/tracer/lib/dailyfile.js +0 -92
  235. package/app/node_modules/tracer/lib/index.js +0 -10
  236. package/app/node_modules/tracer/lib/settings.js +0 -25
  237. package/app/node_modules/tracer/lib/utils.js +0 -58
  238. package/app/node_modules/tracer/package.json +0 -53
  239. package/app/node_modules/tracer/types/index.d.ts +0 -189
  240. package/dist/scaffold/templates/front-page.class.ts.tpl +0 -12
  241. package/dist/scaffold/templates/main.ts.tpl +0 -13
  242. package/dist/scaffold/templates/nodemon.json.tpl +0 -7
  243. package/dist/scaffold/templates/package.json.tpl +0 -16
  244. package/dist/scaffold/templates/tsconfig.json.tpl +0 -20
  245. /package/dist/{core.decorator.js → src/core.decorator.js} +0 -0
  246. /package/dist/{default → src/default}/default-authentication.class.js +0 -0
  247. /package/dist/{default → src/default}/log-default.class.js +0 -0
  248. /package/dist/{default → src/default}/node-cache.class.js +0 -0
  249. /package/dist/{default → src/default}/pages/404.html +0 -0
  250. /package/dist/{default → src/default}/pages/500.html +0 -0
  251. /package/dist/{default → src/default}/read-write-db.class.js +0 -0
  252. /package/dist/{factory → src/factory}/authentication-factory.class.js +0 -0
  253. /package/dist/{factory → src/factory}/cache-factory.class.js +0 -0
  254. /package/dist/{factory → src/factory}/data-source-factory.class.js +0 -0
  255. /package/dist/{factory → src/factory}/log-factory.class.js +0 -0
  256. /package/dist/{factory → src/factory}/server-factory.class.js +0 -0
  257. /package/dist/{route.decorator.js → src/route.decorator.js} +0 -0
  258. /package/dist/{scaffold → src/scaffold}/command.js +0 -0
@@ -1,3976 +0,0 @@
1
- /**
2
- * The `fs` module enables interacting with the file system in a
3
- * way modeled on standard POSIX functions.
4
- *
5
- * To use the promise-based APIs:
6
- *
7
- * ```js
8
- * import * as fs from 'fs/promises';
9
- * ```
10
- *
11
- * To use the callback and sync APIs:
12
- *
13
- * ```js
14
- * import * as fs from 'fs';
15
- * ```
16
- *
17
- * All file system operations have synchronous, callback, and promise-based
18
- * forms, and are accessible using both CommonJS syntax and ES6 Modules (ESM).
19
- * @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/fs.js)
20
- */
21
- declare module 'fs' {
22
- import * as stream from 'node:stream';
23
- import { Abortable, EventEmitter } from 'node:events';
24
- import { URL } from 'node:url';
25
- import * as promises from 'node:fs/promises';
26
- export { promises };
27
- /**
28
- * Valid types for path values in "fs".
29
- */
30
- export type PathLike = string | Buffer | URL;
31
- export type PathOrFileDescriptor = PathLike | number;
32
- export type TimeLike = string | number | Date;
33
- export type NoParamCallback = (err: NodeJS.ErrnoException | null) => void;
34
- export type BufferEncodingOption =
35
- | 'buffer'
36
- | {
37
- encoding: 'buffer';
38
- };
39
- export interface ObjectEncodingOptions {
40
- encoding?: BufferEncoding | null | undefined;
41
- }
42
- export type EncodingOption = ObjectEncodingOptions | BufferEncoding | undefined | null;
43
- export type OpenMode = number | string;
44
- export type Mode = number | string;
45
- export interface StatsBase<T> {
46
- isFile(): boolean;
47
- isDirectory(): boolean;
48
- isBlockDevice(): boolean;
49
- isCharacterDevice(): boolean;
50
- isSymbolicLink(): boolean;
51
- isFIFO(): boolean;
52
- isSocket(): boolean;
53
- dev: T;
54
- ino: T;
55
- mode: T;
56
- nlink: T;
57
- uid: T;
58
- gid: T;
59
- rdev: T;
60
- size: T;
61
- blksize: T;
62
- blocks: T;
63
- atimeMs: T;
64
- mtimeMs: T;
65
- ctimeMs: T;
66
- birthtimeMs: T;
67
- atime: Date;
68
- mtime: Date;
69
- ctime: Date;
70
- birthtime: Date;
71
- }
72
- export interface Stats extends StatsBase<number> {}
73
- /**
74
- * A `fs.Stats` object provides information about a file.
75
- *
76
- * Objects returned from {@link stat}, {@link lstat} and {@link fstat} and
77
- * their synchronous counterparts are of this type.
78
- * If `bigint` in the `options` passed to those methods is true, the numeric values
79
- * will be `bigint` instead of `number`, and the object will contain additional
80
- * nanosecond-precision properties suffixed with `Ns`.
81
- *
82
- * ```console
83
- * Stats {
84
- * dev: 2114,
85
- * ino: 48064969,
86
- * mode: 33188,
87
- * nlink: 1,
88
- * uid: 85,
89
- * gid: 100,
90
- * rdev: 0,
91
- * size: 527,
92
- * blksize: 4096,
93
- * blocks: 8,
94
- * atimeMs: 1318289051000.1,
95
- * mtimeMs: 1318289051000.1,
96
- * ctimeMs: 1318289051000.1,
97
- * birthtimeMs: 1318289051000.1,
98
- * atime: Mon, 10 Oct 2011 23:24:11 GMT,
99
- * mtime: Mon, 10 Oct 2011 23:24:11 GMT,
100
- * ctime: Mon, 10 Oct 2011 23:24:11 GMT,
101
- * birthtime: Mon, 10 Oct 2011 23:24:11 GMT }
102
- * ```
103
- *
104
- * `bigint` version:
105
- *
106
- * ```console
107
- * BigIntStats {
108
- * dev: 2114n,
109
- * ino: 48064969n,
110
- * mode: 33188n,
111
- * nlink: 1n,
112
- * uid: 85n,
113
- * gid: 100n,
114
- * rdev: 0n,
115
- * size: 527n,
116
- * blksize: 4096n,
117
- * blocks: 8n,
118
- * atimeMs: 1318289051000n,
119
- * mtimeMs: 1318289051000n,
120
- * ctimeMs: 1318289051000n,
121
- * birthtimeMs: 1318289051000n,
122
- * atimeNs: 1318289051000000000n,
123
- * mtimeNs: 1318289051000000000n,
124
- * ctimeNs: 1318289051000000000n,
125
- * birthtimeNs: 1318289051000000000n,
126
- * atime: Mon, 10 Oct 2011 23:24:11 GMT,
127
- * mtime: Mon, 10 Oct 2011 23:24:11 GMT,
128
- * ctime: Mon, 10 Oct 2011 23:24:11 GMT,
129
- * birthtime: Mon, 10 Oct 2011 23:24:11 GMT }
130
- * ```
131
- * @since v0.1.21
132
- */
133
- export class Stats {}
134
-
135
- export interface StatsFsBase<T> {
136
- /** Type of file system. */
137
- type: T;
138
- /** Optimal transfer block size. */
139
- bsize: T;
140
- /** Total data blocks in file system. */
141
- blocks: T;
142
- /** Free blocks in file system. */
143
- bfree: T;
144
- /** Available blocks for unprivileged users */
145
- bavail: T;
146
- /** Total file nodes in file system. */
147
- files: T;
148
- /** Free file nodes in file system. */
149
- ffree: T;
150
- }
151
-
152
- export interface StatsFs extends StatsFsBase<number> {}
153
-
154
- /**
155
- * Provides information about a mounted file system
156
- *
157
- * Objects returned from {@link statfs} and {@link statfsSync} are of this type.
158
- * If `bigint` in the `options` passed to those methods is true, the numeric values
159
- * will be `bigint` instead of `number`.
160
- * @since v18.15.0
161
- */
162
- export class StatsFs {}
163
-
164
- export interface BigIntStatsFs extends StatsFsBase<bigint> {}
165
-
166
- export interface StatFsOptions {
167
- bigint?: boolean | undefined;
168
- }
169
-
170
- /**
171
- * A representation of a directory entry, which can be a file or a subdirectory
172
- * within the directory, as returned by reading from an `fs.Dir`. The
173
- * directory entry is a combination of the file name and file type pairs.
174
- *
175
- * Additionally, when {@link readdir} or {@link readdirSync} is called with
176
- * the `withFileTypes` option set to `true`, the resulting array is filled with `fs.Dirent` objects, rather than strings or `Buffer` s.
177
- * @since v10.10.0
178
- */
179
- export class Dirent {
180
- /**
181
- * Returns `true` if the `fs.Dirent` object describes a regular file.
182
- * @since v10.10.0
183
- */
184
- isFile(): boolean;
185
- /**
186
- * Returns `true` if the `fs.Dirent` object describes a file system
187
- * directory.
188
- * @since v10.10.0
189
- */
190
- isDirectory(): boolean;
191
- /**
192
- * Returns `true` if the `fs.Dirent` object describes a block device.
193
- * @since v10.10.0
194
- */
195
- isBlockDevice(): boolean;
196
- /**
197
- * Returns `true` if the `fs.Dirent` object describes a character device.
198
- * @since v10.10.0
199
- */
200
- isCharacterDevice(): boolean;
201
- /**
202
- * Returns `true` if the `fs.Dirent` object describes a symbolic link.
203
- * @since v10.10.0
204
- */
205
- isSymbolicLink(): boolean;
206
- /**
207
- * Returns `true` if the `fs.Dirent` object describes a first-in-first-out
208
- * (FIFO) pipe.
209
- * @since v10.10.0
210
- */
211
- isFIFO(): boolean;
212
- /**
213
- * Returns `true` if the `fs.Dirent` object describes a socket.
214
- * @since v10.10.0
215
- */
216
- isSocket(): boolean;
217
- /**
218
- * The file name that this `fs.Dirent` object refers to. The type of this
219
- * value is determined by the `options.encoding` passed to {@link readdir} or {@link readdirSync}.
220
- * @since v10.10.0
221
- */
222
- name: string;
223
- }
224
- /**
225
- * A class representing a directory stream.
226
- *
227
- * Created by {@link opendir}, {@link opendirSync}, or `fsPromises.opendir()`.
228
- *
229
- * ```js
230
- * import { opendir } from 'fs/promises';
231
- *
232
- * try {
233
- * const dir = await opendir('./');
234
- * for await (const dirent of dir)
235
- * console.log(dirent.name);
236
- * } catch (err) {
237
- * console.error(err);
238
- * }
239
- * ```
240
- *
241
- * When using the async iterator, the `fs.Dir` object will be automatically
242
- * closed after the iterator exits.
243
- * @since v12.12.0
244
- */
245
- export class Dir implements AsyncIterable<Dirent> {
246
- /**
247
- * The read-only path of this directory as was provided to {@link opendir},{@link opendirSync}, or `fsPromises.opendir()`.
248
- * @since v12.12.0
249
- */
250
- readonly path: string;
251
- /**
252
- * Asynchronously iterates over the directory via `readdir(3)` until all entries have been read.
253
- */
254
- [Symbol.asyncIterator](): AsyncIterableIterator<Dirent>;
255
- /**
256
- * Asynchronously close the directory's underlying resource handle.
257
- * Subsequent reads will result in errors.
258
- *
259
- * A promise is returned that will be resolved after the resource has been
260
- * closed.
261
- * @since v12.12.0
262
- */
263
- close(): Promise<void>;
264
- close(cb: NoParamCallback): void;
265
- /**
266
- * Synchronously close the directory's underlying resource handle.
267
- * Subsequent reads will result in errors.
268
- * @since v12.12.0
269
- */
270
- closeSync(): void;
271
- /**
272
- * Asynchronously read the next directory entry via [`readdir(3)`](http://man7.org/linux/man-pages/man3/readdir.3.html) as an `fs.Dirent`.
273
- *
274
- * A promise is returned that will be resolved with an `fs.Dirent`, or `null`if there are no more directory entries to read.
275
- *
276
- * Directory entries returned by this function are in no particular order as
277
- * provided by the operating system's underlying directory mechanisms.
278
- * Entries added or removed while iterating over the directory might not be
279
- * included in the iteration results.
280
- * @since v12.12.0
281
- * @return containing {fs.Dirent|null}
282
- */
283
- read(): Promise<Dirent | null>;
284
- read(cb: (err: NodeJS.ErrnoException | null, dirEnt: Dirent | null) => void): void;
285
- /**
286
- * Synchronously read the next directory entry as an `fs.Dirent`. See the
287
- * POSIX [`readdir(3)`](http://man7.org/linux/man-pages/man3/readdir.3.html) documentation for more detail.
288
- *
289
- * If there are no more directory entries to read, `null` will be returned.
290
- *
291
- * Directory entries returned by this function are in no particular order as
292
- * provided by the operating system's underlying directory mechanisms.
293
- * Entries added or removed while iterating over the directory might not be
294
- * included in the iteration results.
295
- * @since v12.12.0
296
- */
297
- readSync(): Dirent | null;
298
- }
299
- /**
300
- * Class: fs.StatWatcher
301
- * @since v14.3.0, v12.20.0
302
- * Extends `EventEmitter`
303
- * A successful call to {@link watchFile} method will return a new fs.StatWatcher object.
304
- */
305
- export interface StatWatcher extends EventEmitter {
306
- /**
307
- * When called, requests that the Node.js event loop _not_ exit so long as the `fs.StatWatcher` is active. Calling `watcher.ref()` multiple times will have
308
- * no effect.
309
- *
310
- * By default, all `fs.StatWatcher` objects are "ref'ed", making it normally
311
- * unnecessary to call `watcher.ref()` unless `watcher.unref()` had been
312
- * called previously.
313
- * @since v14.3.0, v12.20.0
314
- */
315
- ref(): this;
316
- /**
317
- * When called, the active `fs.StatWatcher` object will not require the Node.js
318
- * event loop to remain active. If there is no other activity keeping the
319
- * event loop running, the process may exit before the `fs.StatWatcher` object's
320
- * callback is invoked. Calling `watcher.unref()` multiple times will have
321
- * no effect.
322
- * @since v14.3.0, v12.20.0
323
- */
324
- unref(): this;
325
- }
326
- export interface FSWatcher extends EventEmitter {
327
- /**
328
- * Stop watching for changes on the given `fs.FSWatcher`. Once stopped, the `fs.FSWatcher` object is no longer usable.
329
- * @since v0.5.8
330
- */
331
- close(): void;
332
- /**
333
- * events.EventEmitter
334
- * 1. change
335
- * 2. error
336
- */
337
- addListener(event: string, listener: (...args: any[]) => void): this;
338
- addListener(event: 'change', listener: (eventType: string, filename: string | Buffer) => void): this;
339
- addListener(event: 'error', listener: (error: Error) => void): this;
340
- addListener(event: 'close', listener: () => void): this;
341
- on(event: string, listener: (...args: any[]) => void): this;
342
- on(event: 'change', listener: (eventType: string, filename: string | Buffer) => void): this;
343
- on(event: 'error', listener: (error: Error) => void): this;
344
- on(event: 'close', listener: () => void): this;
345
- once(event: string, listener: (...args: any[]) => void): this;
346
- once(event: 'change', listener: (eventType: string, filename: string | Buffer) => void): this;
347
- once(event: 'error', listener: (error: Error) => void): this;
348
- once(event: 'close', listener: () => void): this;
349
- prependListener(event: string, listener: (...args: any[]) => void): this;
350
- prependListener(event: 'change', listener: (eventType: string, filename: string | Buffer) => void): this;
351
- prependListener(event: 'error', listener: (error: Error) => void): this;
352
- prependListener(event: 'close', listener: () => void): this;
353
- prependOnceListener(event: string, listener: (...args: any[]) => void): this;
354
- prependOnceListener(event: 'change', listener: (eventType: string, filename: string | Buffer) => void): this;
355
- prependOnceListener(event: 'error', listener: (error: Error) => void): this;
356
- prependOnceListener(event: 'close', listener: () => void): this;
357
- }
358
- /**
359
- * Instances of `fs.ReadStream` are created and returned using the {@link createReadStream} function.
360
- * @since v0.1.93
361
- */
362
- export class ReadStream extends stream.Readable {
363
- close(callback?: (err?: NodeJS.ErrnoException | null) => void): void;
364
- /**
365
- * The number of bytes that have been read so far.
366
- * @since v6.4.0
367
- */
368
- bytesRead: number;
369
- /**
370
- * The path to the file the stream is reading from as specified in the first
371
- * argument to `fs.createReadStream()`. If `path` is passed as a string, then`readStream.path` will be a string. If `path` is passed as a `Buffer`, then`readStream.path` will be a
372
- * `Buffer`. If `fd` is specified, then`readStream.path` will be `undefined`.
373
- * @since v0.1.93
374
- */
375
- path: string | Buffer;
376
- /**
377
- * This property is `true` if the underlying file has not been opened yet,
378
- * i.e. before the `'ready'` event is emitted.
379
- * @since v11.2.0, v10.16.0
380
- */
381
- pending: boolean;
382
- /**
383
- * events.EventEmitter
384
- * 1. open
385
- * 2. close
386
- * 3. ready
387
- */
388
- addListener(event: 'close', listener: () => void): this;
389
- addListener(event: 'data', listener: (chunk: Buffer | string) => void): this;
390
- addListener(event: 'end', listener: () => void): this;
391
- addListener(event: 'error', listener: (err: Error) => void): this;
392
- addListener(event: 'open', listener: (fd: number) => void): this;
393
- addListener(event: 'pause', listener: () => void): this;
394
- addListener(event: 'readable', listener: () => void): this;
395
- addListener(event: 'ready', listener: () => void): this;
396
- addListener(event: 'resume', listener: () => void): this;
397
- addListener(event: string | symbol, listener: (...args: any[]) => void): this;
398
- on(event: 'close', listener: () => void): this;
399
- on(event: 'data', listener: (chunk: Buffer | string) => void): this;
400
- on(event: 'end', listener: () => void): this;
401
- on(event: 'error', listener: (err: Error) => void): this;
402
- on(event: 'open', listener: (fd: number) => void): this;
403
- on(event: 'pause', listener: () => void): this;
404
- on(event: 'readable', listener: () => void): this;
405
- on(event: 'ready', listener: () => void): this;
406
- on(event: 'resume', listener: () => void): this;
407
- on(event: string | symbol, listener: (...args: any[]) => void): this;
408
- once(event: 'close', listener: () => void): this;
409
- once(event: 'data', listener: (chunk: Buffer | string) => void): this;
410
- once(event: 'end', listener: () => void): this;
411
- once(event: 'error', listener: (err: Error) => void): this;
412
- once(event: 'open', listener: (fd: number) => void): this;
413
- once(event: 'pause', listener: () => void): this;
414
- once(event: 'readable', listener: () => void): this;
415
- once(event: 'ready', listener: () => void): this;
416
- once(event: 'resume', listener: () => void): this;
417
- once(event: string | symbol, listener: (...args: any[]) => void): this;
418
- prependListener(event: 'close', listener: () => void): this;
419
- prependListener(event: 'data', listener: (chunk: Buffer | string) => void): this;
420
- prependListener(event: 'end', listener: () => void): this;
421
- prependListener(event: 'error', listener: (err: Error) => void): this;
422
- prependListener(event: 'open', listener: (fd: number) => void): this;
423
- prependListener(event: 'pause', listener: () => void): this;
424
- prependListener(event: 'readable', listener: () => void): this;
425
- prependListener(event: 'ready', listener: () => void): this;
426
- prependListener(event: 'resume', listener: () => void): this;
427
- prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
428
- prependOnceListener(event: 'close', listener: () => void): this;
429
- prependOnceListener(event: 'data', listener: (chunk: Buffer | string) => void): this;
430
- prependOnceListener(event: 'end', listener: () => void): this;
431
- prependOnceListener(event: 'error', listener: (err: Error) => void): this;
432
- prependOnceListener(event: 'open', listener: (fd: number) => void): this;
433
- prependOnceListener(event: 'pause', listener: () => void): this;
434
- prependOnceListener(event: 'readable', listener: () => void): this;
435
- prependOnceListener(event: 'ready', listener: () => void): this;
436
- prependOnceListener(event: 'resume', listener: () => void): this;
437
- prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
438
- }
439
- /**
440
- * * Extends `stream.Writable`
441
- *
442
- * Instances of `fs.WriteStream` are created and returned using the {@link createWriteStream} function.
443
- * @since v0.1.93
444
- */
445
- export class WriteStream extends stream.Writable {
446
- /**
447
- * Closes `writeStream`. Optionally accepts a
448
- * callback that will be executed once the `writeStream`is closed.
449
- * @since v0.9.4
450
- */
451
- close(callback?: (err?: NodeJS.ErrnoException | null) => void): void;
452
- /**
453
- * The number of bytes written so far. Does not include data that is still queued
454
- * for writing.
455
- * @since v0.4.7
456
- */
457
- bytesWritten: number;
458
- /**
459
- * The path to the file the stream is writing to as specified in the first
460
- * argument to {@link createWriteStream}. If `path` is passed as a string, then`writeStream.path` will be a string. If `path` is passed as a `Buffer`, then`writeStream.path` will be a
461
- * `Buffer`.
462
- * @since v0.1.93
463
- */
464
- path: string | Buffer;
465
- /**
466
- * This property is `true` if the underlying file has not been opened yet,
467
- * i.e. before the `'ready'` event is emitted.
468
- * @since v11.2.0
469
- */
470
- pending: boolean;
471
- /**
472
- * events.EventEmitter
473
- * 1. open
474
- * 2. close
475
- * 3. ready
476
- */
477
- addListener(event: 'close', listener: () => void): this;
478
- addListener(event: 'drain', listener: () => void): this;
479
- addListener(event: 'error', listener: (err: Error) => void): this;
480
- addListener(event: 'finish', listener: () => void): this;
481
- addListener(event: 'open', listener: (fd: number) => void): this;
482
- addListener(event: 'pipe', listener: (src: stream.Readable) => void): this;
483
- addListener(event: 'ready', listener: () => void): this;
484
- addListener(event: 'unpipe', listener: (src: stream.Readable) => void): this;
485
- addListener(event: string | symbol, listener: (...args: any[]) => void): this;
486
- on(event: 'close', listener: () => void): this;
487
- on(event: 'drain', listener: () => void): this;
488
- on(event: 'error', listener: (err: Error) => void): this;
489
- on(event: 'finish', listener: () => void): this;
490
- on(event: 'open', listener: (fd: number) => void): this;
491
- on(event: 'pipe', listener: (src: stream.Readable) => void): this;
492
- on(event: 'ready', listener: () => void): this;
493
- on(event: 'unpipe', listener: (src: stream.Readable) => void): this;
494
- on(event: string | symbol, listener: (...args: any[]) => void): this;
495
- once(event: 'close', listener: () => void): this;
496
- once(event: 'drain', listener: () => void): this;
497
- once(event: 'error', listener: (err: Error) => void): this;
498
- once(event: 'finish', listener: () => void): this;
499
- once(event: 'open', listener: (fd: number) => void): this;
500
- once(event: 'pipe', listener: (src: stream.Readable) => void): this;
501
- once(event: 'ready', listener: () => void): this;
502
- once(event: 'unpipe', listener: (src: stream.Readable) => void): this;
503
- once(event: string | symbol, listener: (...args: any[]) => void): this;
504
- prependListener(event: 'close', listener: () => void): this;
505
- prependListener(event: 'drain', listener: () => void): this;
506
- prependListener(event: 'error', listener: (err: Error) => void): this;
507
- prependListener(event: 'finish', listener: () => void): this;
508
- prependListener(event: 'open', listener: (fd: number) => void): this;
509
- prependListener(event: 'pipe', listener: (src: stream.Readable) => void): this;
510
- prependListener(event: 'ready', listener: () => void): this;
511
- prependListener(event: 'unpipe', listener: (src: stream.Readable) => void): this;
512
- prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
513
- prependOnceListener(event: 'close', listener: () => void): this;
514
- prependOnceListener(event: 'drain', listener: () => void): this;
515
- prependOnceListener(event: 'error', listener: (err: Error) => void): this;
516
- prependOnceListener(event: 'finish', listener: () => void): this;
517
- prependOnceListener(event: 'open', listener: (fd: number) => void): this;
518
- prependOnceListener(event: 'pipe', listener: (src: stream.Readable) => void): this;
519
- prependOnceListener(event: 'ready', listener: () => void): this;
520
- prependOnceListener(event: 'unpipe', listener: (src: stream.Readable) => void): this;
521
- prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
522
- }
523
- /**
524
- * Asynchronously rename file at `oldPath` to the pathname provided
525
- * as `newPath`. In the case that `newPath` already exists, it will
526
- * be overwritten. If there is a directory at `newPath`, an error will
527
- * be raised instead. No arguments other than a possible exception are
528
- * given to the completion callback.
529
- *
530
- * See also: [`rename(2)`](http://man7.org/linux/man-pages/man2/rename.2.html).
531
- *
532
- * ```js
533
- * import { rename } from 'fs';
534
- *
535
- * rename('oldFile.txt', 'newFile.txt', (err) => {
536
- * if (err) throw err;
537
- * console.log('Rename complete!');
538
- * });
539
- * ```
540
- * @since v0.0.2
541
- */
542
- export function rename(oldPath: PathLike, newPath: PathLike, callback: NoParamCallback): void;
543
- export namespace rename {
544
- /**
545
- * Asynchronous rename(2) - Change the name or location of a file or directory.
546
- * @param oldPath A path to a file. If a URL is provided, it must use the `file:` protocol.
547
- * URL support is _experimental_.
548
- * @param newPath A path to a file. If a URL is provided, it must use the `file:` protocol.
549
- * URL support is _experimental_.
550
- */
551
- function __promisify__(oldPath: PathLike, newPath: PathLike): Promise<void>;
552
- }
553
- /**
554
- * Renames the file from `oldPath` to `newPath`. Returns `undefined`.
555
- *
556
- * See the POSIX [`rename(2)`](http://man7.org/linux/man-pages/man2/rename.2.html) documentation for more details.
557
- * @since v0.1.21
558
- */
559
- export function renameSync(oldPath: PathLike, newPath: PathLike): void;
560
- /**
561
- * Truncates the file. No arguments other than a possible exception are
562
- * given to the completion callback. A file descriptor can also be passed as the
563
- * first argument. In this case, `fs.ftruncate()` is called.
564
- *
565
- * ```js
566
- * import { truncate } from 'fs';
567
- * // Assuming that 'path/file.txt' is a regular file.
568
- * truncate('path/file.txt', (err) => {
569
- * if (err) throw err;
570
- * console.log('path/file.txt was truncated');
571
- * });
572
- * ```
573
- *
574
- * Passing a file descriptor is deprecated and may result in an error being thrown
575
- * in the future.
576
- *
577
- * See the POSIX [`truncate(2)`](http://man7.org/linux/man-pages/man2/truncate.2.html) documentation for more details.
578
- * @since v0.8.6
579
- * @param [len=0]
580
- */
581
- export function truncate(path: PathLike, len: number | undefined | null, callback: NoParamCallback): void;
582
- /**
583
- * Asynchronous truncate(2) - Truncate a file to a specified length.
584
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
585
- */
586
- export function truncate(path: PathLike, callback: NoParamCallback): void;
587
- export namespace truncate {
588
- /**
589
- * Asynchronous truncate(2) - Truncate a file to a specified length.
590
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
591
- * @param len If not specified, defaults to `0`.
592
- */
593
- function __promisify__(path: PathLike, len?: number | null): Promise<void>;
594
- }
595
- /**
596
- * Truncates the file. Returns `undefined`. A file descriptor can also be
597
- * passed as the first argument. In this case, `fs.ftruncateSync()` is called.
598
- *
599
- * Passing a file descriptor is deprecated and may result in an error being thrown
600
- * in the future.
601
- * @since v0.8.6
602
- * @param [len=0]
603
- */
604
- export function truncateSync(path: PathLike, len?: number | null): void;
605
- /**
606
- * Truncates the file descriptor. No arguments other than a possible exception are
607
- * given to the completion callback.
608
- *
609
- * See the POSIX [`ftruncate(2)`](http://man7.org/linux/man-pages/man2/ftruncate.2.html) documentation for more detail.
610
- *
611
- * If the file referred to by the file descriptor was larger than `len` bytes, only
612
- * the first `len` bytes will be retained in the file.
613
- *
614
- * For example, the following program retains only the first four bytes of the
615
- * file:
616
- *
617
- * ```js
618
- * import { open, close, ftruncate } from 'fs';
619
- *
620
- * function closeFd(fd) {
621
- * close(fd, (err) => {
622
- * if (err) throw err;
623
- * });
624
- * }
625
- *
626
- * open('temp.txt', 'r+', (err, fd) => {
627
- * if (err) throw err;
628
- *
629
- * try {
630
- * ftruncate(fd, 4, (err) => {
631
- * closeFd(fd);
632
- * if (err) throw err;
633
- * });
634
- * } catch (err) {
635
- * closeFd(fd);
636
- * if (err) throw err;
637
- * }
638
- * });
639
- * ```
640
- *
641
- * If the file previously was shorter than `len` bytes, it is extended, and the
642
- * extended part is filled with null bytes (`'\0'`):
643
- *
644
- * If `len` is negative then `0` will be used.
645
- * @since v0.8.6
646
- * @param [len=0]
647
- */
648
- export function ftruncate(fd: number, len: number | undefined | null, callback: NoParamCallback): void;
649
- /**
650
- * Asynchronous ftruncate(2) - Truncate a file to a specified length.
651
- * @param fd A file descriptor.
652
- */
653
- export function ftruncate(fd: number, callback: NoParamCallback): void;
654
- export namespace ftruncate {
655
- /**
656
- * Asynchronous ftruncate(2) - Truncate a file to a specified length.
657
- * @param fd A file descriptor.
658
- * @param len If not specified, defaults to `0`.
659
- */
660
- function __promisify__(fd: number, len?: number | null): Promise<void>;
661
- }
662
- /**
663
- * Truncates the file descriptor. Returns `undefined`.
664
- *
665
- * For detailed information, see the documentation of the asynchronous version of
666
- * this API: {@link ftruncate}.
667
- * @since v0.8.6
668
- * @param [len=0]
669
- */
670
- export function ftruncateSync(fd: number, len?: number | null): void;
671
- /**
672
- * Asynchronously changes owner and group of a file. No arguments other than a
673
- * possible exception are given to the completion callback.
674
- *
675
- * See the POSIX [`chown(2)`](http://man7.org/linux/man-pages/man2/chown.2.html) documentation for more detail.
676
- * @since v0.1.97
677
- */
678
- export function chown(path: PathLike, uid: number, gid: number, callback: NoParamCallback): void;
679
- export namespace chown {
680
- /**
681
- * Asynchronous chown(2) - Change ownership of a file.
682
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
683
- */
684
- function __promisify__(path: PathLike, uid: number, gid: number): Promise<void>;
685
- }
686
- /**
687
- * Synchronously changes owner and group of a file. Returns `undefined`.
688
- * This is the synchronous version of {@link chown}.
689
- *
690
- * See the POSIX [`chown(2)`](http://man7.org/linux/man-pages/man2/chown.2.html) documentation for more detail.
691
- * @since v0.1.97
692
- */
693
- export function chownSync(path: PathLike, uid: number, gid: number): void;
694
- /**
695
- * Sets the owner of the file. No arguments other than a possible exception are
696
- * given to the completion callback.
697
- *
698
- * See the POSIX [`fchown(2)`](http://man7.org/linux/man-pages/man2/fchown.2.html) documentation for more detail.
699
- * @since v0.4.7
700
- */
701
- export function fchown(fd: number, uid: number, gid: number, callback: NoParamCallback): void;
702
- export namespace fchown {
703
- /**
704
- * Asynchronous fchown(2) - Change ownership of a file.
705
- * @param fd A file descriptor.
706
- */
707
- function __promisify__(fd: number, uid: number, gid: number): Promise<void>;
708
- }
709
- /**
710
- * Sets the owner of the file. Returns `undefined`.
711
- *
712
- * See the POSIX [`fchown(2)`](http://man7.org/linux/man-pages/man2/fchown.2.html) documentation for more detail.
713
- * @since v0.4.7
714
- * @param uid The file's new owner's user id.
715
- * @param gid The file's new group's group id.
716
- */
717
- export function fchownSync(fd: number, uid: number, gid: number): void;
718
- /**
719
- * Set the owner of the symbolic link. No arguments other than a possible
720
- * exception are given to the completion callback.
721
- *
722
- * See the POSIX [`lchown(2)`](http://man7.org/linux/man-pages/man2/lchown.2.html) documentation for more detail.
723
- */
724
- export function lchown(path: PathLike, uid: number, gid: number, callback: NoParamCallback): void;
725
- export namespace lchown {
726
- /**
727
- * Asynchronous lchown(2) - Change ownership of a file. Does not dereference symbolic links.
728
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
729
- */
730
- function __promisify__(path: PathLike, uid: number, gid: number): Promise<void>;
731
- }
732
- /**
733
- * Set the owner for the path. Returns `undefined`.
734
- *
735
- * See the POSIX [`lchown(2)`](http://man7.org/linux/man-pages/man2/lchown.2.html) documentation for more details.
736
- * @param uid The file's new owner's user id.
737
- * @param gid The file's new group's group id.
738
- */
739
- export function lchownSync(path: PathLike, uid: number, gid: number): void;
740
- /**
741
- * Changes the access and modification times of a file in the same way as {@link utimes}, with the difference that if the path refers to a symbolic
742
- * link, then the link is not dereferenced: instead, the timestamps of the
743
- * symbolic link itself are changed.
744
- *
745
- * No arguments other than a possible exception are given to the completion
746
- * callback.
747
- * @since v14.5.0, v12.19.0
748
- */
749
- export function lutimes(path: PathLike, atime: TimeLike, mtime: TimeLike, callback: NoParamCallback): void;
750
- export namespace lutimes {
751
- /**
752
- * Changes the access and modification times of a file in the same way as `fsPromises.utimes()`,
753
- * with the difference that if the path refers to a symbolic link, then the link is not
754
- * dereferenced: instead, the timestamps of the symbolic link itself are changed.
755
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
756
- * @param atime The last access time. If a string is provided, it will be coerced to number.
757
- * @param mtime The last modified time. If a string is provided, it will be coerced to number.
758
- */
759
- function __promisify__(path: PathLike, atime: TimeLike, mtime: TimeLike): Promise<void>;
760
- }
761
- /**
762
- * Change the file system timestamps of the symbolic link referenced by `path`.
763
- * Returns `undefined`, or throws an exception when parameters are incorrect or
764
- * the operation fails. This is the synchronous version of {@link lutimes}.
765
- * @since v14.5.0, v12.19.0
766
- */
767
- export function lutimesSync(path: PathLike, atime: TimeLike, mtime: TimeLike): void;
768
- /**
769
- * Asynchronously changes the permissions of a file. No arguments other than a
770
- * possible exception are given to the completion callback.
771
- *
772
- * See the POSIX [`chmod(2)`](http://man7.org/linux/man-pages/man2/chmod.2.html) documentation for more detail.
773
- *
774
- * ```js
775
- * import { chmod } from 'fs';
776
- *
777
- * chmod('my_file.txt', 0o775, (err) => {
778
- * if (err) throw err;
779
- * console.log('The permissions for file "my_file.txt" have been changed!');
780
- * });
781
- * ```
782
- * @since v0.1.30
783
- */
784
- export function chmod(path: PathLike, mode: Mode, callback: NoParamCallback): void;
785
- export namespace chmod {
786
- /**
787
- * Asynchronous chmod(2) - Change permissions of a file.
788
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
789
- * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
790
- */
791
- function __promisify__(path: PathLike, mode: Mode): Promise<void>;
792
- }
793
- /**
794
- * For detailed information, see the documentation of the asynchronous version of
795
- * this API: {@link chmod}.
796
- *
797
- * See the POSIX [`chmod(2)`](http://man7.org/linux/man-pages/man2/chmod.2.html) documentation for more detail.
798
- * @since v0.6.7
799
- */
800
- export function chmodSync(path: PathLike, mode: Mode): void;
801
- /**
802
- * Sets the permissions on the file. No arguments other than a possible exception
803
- * are given to the completion callback.
804
- *
805
- * See the POSIX [`fchmod(2)`](http://man7.org/linux/man-pages/man2/fchmod.2.html) documentation for more detail.
806
- * @since v0.4.7
807
- */
808
- export function fchmod(fd: number, mode: Mode, callback: NoParamCallback): void;
809
- export namespace fchmod {
810
- /**
811
- * Asynchronous fchmod(2) - Change permissions of a file.
812
- * @param fd A file descriptor.
813
- * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
814
- */
815
- function __promisify__(fd: number, mode: Mode): Promise<void>;
816
- }
817
- /**
818
- * Sets the permissions on the file. Returns `undefined`.
819
- *
820
- * See the POSIX [`fchmod(2)`](http://man7.org/linux/man-pages/man2/fchmod.2.html) documentation for more detail.
821
- * @since v0.4.7
822
- */
823
- export function fchmodSync(fd: number, mode: Mode): void;
824
- /**
825
- * Changes the permissions on a symbolic link. No arguments other than a possible
826
- * exception are given to the completion callback.
827
- *
828
- * This method is only implemented on macOS.
829
- *
830
- * See the POSIX [`lchmod(2)`](https://www.freebsd.org/cgi/man.cgi?query=lchmod&sektion=2) documentation for more detail.
831
- * @deprecated Since v0.4.7
832
- */
833
- export function lchmod(path: PathLike, mode: Mode, callback: NoParamCallback): void;
834
- /** @deprecated */
835
- export namespace lchmod {
836
- /**
837
- * Asynchronous lchmod(2) - Change permissions of a file. Does not dereference symbolic links.
838
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
839
- * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
840
- */
841
- function __promisify__(path: PathLike, mode: Mode): Promise<void>;
842
- }
843
- /**
844
- * Changes the permissions on a symbolic link. Returns `undefined`.
845
- *
846
- * This method is only implemented on macOS.
847
- *
848
- * See the POSIX [`lchmod(2)`](https://www.freebsd.org/cgi/man.cgi?query=lchmod&sektion=2) documentation for more detail.
849
- * @deprecated Since v0.4.7
850
- */
851
- export function lchmodSync(path: PathLike, mode: Mode): void;
852
- /**
853
- * Asynchronous [`stat(2)`](http://man7.org/linux/man-pages/man2/stat.2.html). The callback gets two arguments `(err, stats)` where`stats` is an `fs.Stats` object.
854
- *
855
- * In case of an error, the `err.code` will be one of `Common System Errors`.
856
- *
857
- * Using `fs.stat()` to check for the existence of a file before calling`fs.open()`, `fs.readFile()` or `fs.writeFile()` is not recommended.
858
- * Instead, user code should open/read/write the file directly and handle the
859
- * error raised if the file is not available.
860
- *
861
- * To check if a file exists without manipulating it afterwards, {@link access} is recommended.
862
- *
863
- * For example, given the following directory structure:
864
- *
865
- * ```text
866
- * - txtDir
867
- * -- file.txt
868
- * - app.js
869
- * ```
870
- *
871
- * The next program will check for the stats of the given paths:
872
- *
873
- * ```js
874
- * import { stat } from 'fs';
875
- *
876
- * const pathsToCheck = ['./txtDir', './txtDir/file.txt'];
877
- *
878
- * for (let i = 0; i < pathsToCheck.length; i++) {
879
- * stat(pathsToCheck[i], (err, stats) => {
880
- * console.log(stats.isDirectory());
881
- * console.log(stats);
882
- * });
883
- * }
884
- * ```
885
- *
886
- * The resulting output will resemble:
887
- *
888
- * ```console
889
- * true
890
- * Stats {
891
- * dev: 16777220,
892
- * mode: 16877,
893
- * nlink: 3,
894
- * uid: 501,
895
- * gid: 20,
896
- * rdev: 0,
897
- * blksize: 4096,
898
- * ino: 14214262,
899
- * size: 96,
900
- * blocks: 0,
901
- * atimeMs: 1561174653071.963,
902
- * mtimeMs: 1561174614583.3518,
903
- * ctimeMs: 1561174626623.5366,
904
- * birthtimeMs: 1561174126937.2893,
905
- * atime: 2019-06-22T03:37:33.072Z,
906
- * mtime: 2019-06-22T03:36:54.583Z,
907
- * ctime: 2019-06-22T03:37:06.624Z,
908
- * birthtime: 2019-06-22T03:28:46.937Z
909
- * }
910
- * false
911
- * Stats {
912
- * dev: 16777220,
913
- * mode: 33188,
914
- * nlink: 1,
915
- * uid: 501,
916
- * gid: 20,
917
- * rdev: 0,
918
- * blksize: 4096,
919
- * ino: 14214074,
920
- * size: 8,
921
- * blocks: 8,
922
- * atimeMs: 1561174616618.8555,
923
- * mtimeMs: 1561174614584,
924
- * ctimeMs: 1561174614583.8145,
925
- * birthtimeMs: 1561174007710.7478,
926
- * atime: 2019-06-22T03:36:56.619Z,
927
- * mtime: 2019-06-22T03:36:54.584Z,
928
- * ctime: 2019-06-22T03:36:54.584Z,
929
- * birthtime: 2019-06-22T03:26:47.711Z
930
- * }
931
- * ```
932
- * @since v0.0.2
933
- */
934
- export function stat(path: PathLike, callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void): void;
935
- export function stat(
936
- path: PathLike,
937
- options:
938
- | (StatOptions & {
939
- bigint?: false | undefined;
940
- })
941
- | undefined,
942
- callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void
943
- ): void;
944
- export function stat(
945
- path: PathLike,
946
- options: StatOptions & {
947
- bigint: true;
948
- },
949
- callback: (err: NodeJS.ErrnoException | null, stats: BigIntStats) => void
950
- ): void;
951
- export function stat(path: PathLike, options: StatOptions | undefined, callback: (err: NodeJS.ErrnoException | null, stats: Stats | BigIntStats) => void): void;
952
- export namespace stat {
953
- /**
954
- * Asynchronous stat(2) - Get file status.
955
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
956
- */
957
- function __promisify__(
958
- path: PathLike,
959
- options?: StatOptions & {
960
- bigint?: false | undefined;
961
- }
962
- ): Promise<Stats>;
963
- function __promisify__(
964
- path: PathLike,
965
- options: StatOptions & {
966
- bigint: true;
967
- }
968
- ): Promise<BigIntStats>;
969
- function __promisify__(path: PathLike, options?: StatOptions): Promise<Stats | BigIntStats>;
970
- }
971
- export interface StatSyncFn extends Function {
972
- (path: PathLike, options?: undefined): Stats;
973
- (
974
- path: PathLike,
975
- options?: StatSyncOptions & {
976
- bigint?: false | undefined;
977
- throwIfNoEntry: false;
978
- }
979
- ): Stats | undefined;
980
- (
981
- path: PathLike,
982
- options: StatSyncOptions & {
983
- bigint: true;
984
- throwIfNoEntry: false;
985
- }
986
- ): BigIntStats | undefined;
987
- (
988
- path: PathLike,
989
- options?: StatSyncOptions & {
990
- bigint?: false | undefined;
991
- }
992
- ): Stats;
993
- (
994
- path: PathLike,
995
- options: StatSyncOptions & {
996
- bigint: true;
997
- }
998
- ): BigIntStats;
999
- (
1000
- path: PathLike,
1001
- options: StatSyncOptions & {
1002
- bigint: boolean;
1003
- throwIfNoEntry?: false | undefined;
1004
- }
1005
- ): Stats | BigIntStats;
1006
- (path: PathLike, options?: StatSyncOptions): Stats | BigIntStats | undefined;
1007
- }
1008
- /**
1009
- * Synchronous stat(2) - Get file status.
1010
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1011
- */
1012
- export const statSync: StatSyncFn;
1013
- /**
1014
- * Invokes the callback with the `fs.Stats` for the file descriptor.
1015
- *
1016
- * See the POSIX [`fstat(2)`](http://man7.org/linux/man-pages/man2/fstat.2.html) documentation for more detail.
1017
- * @since v0.1.95
1018
- */
1019
- export function fstat(fd: number, callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void): void;
1020
- export function fstat(
1021
- fd: number,
1022
- options:
1023
- | (StatOptions & {
1024
- bigint?: false | undefined;
1025
- })
1026
- | undefined,
1027
- callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void
1028
- ): void;
1029
- export function fstat(
1030
- fd: number,
1031
- options: StatOptions & {
1032
- bigint: true;
1033
- },
1034
- callback: (err: NodeJS.ErrnoException | null, stats: BigIntStats) => void
1035
- ): void;
1036
- export function fstat(fd: number, options: StatOptions | undefined, callback: (err: NodeJS.ErrnoException | null, stats: Stats | BigIntStats) => void): void;
1037
- export namespace fstat {
1038
- /**
1039
- * Asynchronous fstat(2) - Get file status.
1040
- * @param fd A file descriptor.
1041
- */
1042
- function __promisify__(
1043
- fd: number,
1044
- options?: StatOptions & {
1045
- bigint?: false | undefined;
1046
- }
1047
- ): Promise<Stats>;
1048
- function __promisify__(
1049
- fd: number,
1050
- options: StatOptions & {
1051
- bigint: true;
1052
- }
1053
- ): Promise<BigIntStats>;
1054
- function __promisify__(fd: number, options?: StatOptions): Promise<Stats | BigIntStats>;
1055
- }
1056
- /**
1057
- * Retrieves the `fs.Stats` for the file descriptor.
1058
- *
1059
- * See the POSIX [`fstat(2)`](http://man7.org/linux/man-pages/man2/fstat.2.html) documentation for more detail.
1060
- * @since v0.1.95
1061
- */
1062
- export function fstatSync(
1063
- fd: number,
1064
- options?: StatOptions & {
1065
- bigint?: false | undefined;
1066
- }
1067
- ): Stats;
1068
- export function fstatSync(
1069
- fd: number,
1070
- options: StatOptions & {
1071
- bigint: true;
1072
- }
1073
- ): BigIntStats;
1074
- export function fstatSync(fd: number, options?: StatOptions): Stats | BigIntStats;
1075
- /**
1076
- * Retrieves the `fs.Stats` for the symbolic link referred to by the path.
1077
- * The callback gets two arguments `(err, stats)` where `stats` is a `fs.Stats` object. `lstat()` is identical to `stat()`, except that if `path` is a symbolic
1078
- * link, then the link itself is stat-ed, not the file that it refers to.
1079
- *
1080
- * See the POSIX [`lstat(2)`](http://man7.org/linux/man-pages/man2/lstat.2.html) documentation for more details.
1081
- * @since v0.1.30
1082
- */
1083
- export function lstat(path: PathLike, callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void): void;
1084
- export function lstat(
1085
- path: PathLike,
1086
- options:
1087
- | (StatOptions & {
1088
- bigint?: false | undefined;
1089
- })
1090
- | undefined,
1091
- callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void
1092
- ): void;
1093
- export function lstat(
1094
- path: PathLike,
1095
- options: StatOptions & {
1096
- bigint: true;
1097
- },
1098
- callback: (err: NodeJS.ErrnoException | null, stats: BigIntStats) => void
1099
- ): void;
1100
- export function lstat(path: PathLike, options: StatOptions | undefined, callback: (err: NodeJS.ErrnoException | null, stats: Stats | BigIntStats) => void): void;
1101
- export namespace lstat {
1102
- /**
1103
- * Asynchronous lstat(2) - Get file status. Does not dereference symbolic links.
1104
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1105
- */
1106
- function __promisify__(
1107
- path: PathLike,
1108
- options?: StatOptions & {
1109
- bigint?: false | undefined;
1110
- }
1111
- ): Promise<Stats>;
1112
- function __promisify__(
1113
- path: PathLike,
1114
- options: StatOptions & {
1115
- bigint: true;
1116
- }
1117
- ): Promise<BigIntStats>;
1118
- function __promisify__(path: PathLike, options?: StatOptions): Promise<Stats | BigIntStats>;
1119
- }
1120
- /**
1121
- * Asynchronous statfs(2). Returns information about the mounted file system which contains path. The callback gets two arguments (err, stats) where stats is an <fs.StatFs> object.
1122
- * In case of an error, the err.code will be one of Common System Errors.
1123
- * @param path A path to an existing file or directory on the file system to be queried.
1124
- * @param callback
1125
- */
1126
- export function statfs(path: PathLike, callback: (err: NodeJS.ErrnoException | null, stats: StatsFs) => void): void;
1127
- export function statfs(
1128
- path: PathLike,
1129
- options:
1130
- | (StatFsOptions & {
1131
- bigint?: false | undefined;
1132
- })
1133
- | undefined,
1134
- callback: (err: NodeJS.ErrnoException | null, stats: StatsFs) => void
1135
- ): void;
1136
- export function statfs(
1137
- path: PathLike,
1138
- options: StatFsOptions & {
1139
- bigint: true;
1140
- },
1141
- callback: (err: NodeJS.ErrnoException | null, stats: BigIntStatsFs) => void
1142
- ): void;
1143
- export function statfs(path: PathLike, options: StatFsOptions | undefined, callback: (err: NodeJS.ErrnoException | null, stats: StatsFs | BigIntStatsFs) => void): void;
1144
- export namespace statfs {
1145
- /**
1146
- * Asynchronous statfs(2) - Returns information about the mounted file system which contains path. The callback gets two arguments (err, stats) where stats is an <fs.StatFs> object.
1147
- * @param path A path to an existing file or directory on the file system to be queried.
1148
- */
1149
- function __promisify__(
1150
- path: PathLike,
1151
- options?: StatFsOptions & {
1152
- bigint?: false | undefined;
1153
- }
1154
- ): Promise<StatsFs>;
1155
- function __promisify__(
1156
- path: PathLike,
1157
- options: StatFsOptions & {
1158
- bigint: true;
1159
- }
1160
- ): Promise<BigIntStatsFs>;
1161
- function __promisify__(path: PathLike, options?: StatFsOptions): Promise<StatsFs | BigIntStatsFs>;
1162
- }
1163
-
1164
- /**
1165
- * Synchronous statfs(2). Returns information about the mounted file system which contains path. The callback gets two arguments (err, stats) where stats is an <fs.StatFs> object.
1166
- * In case of an error, the err.code will be one of Common System Errors.
1167
- * @param path A path to an existing file or directory on the file system to be queried.
1168
- * @param callback
1169
- */
1170
- export function statfsSync(
1171
- path: PathLike,
1172
- options?: StatFsOptions & {
1173
- bigint?: false | undefined;
1174
- }
1175
- ): StatsFs;
1176
- export function statfsSync(
1177
- path: PathLike,
1178
- options: StatFsOptions & {
1179
- bigint: true;
1180
- }
1181
- ): BigIntStatsFs;
1182
-
1183
- export function statfsSync(path: PathLike, options?: StatFsOptions): StatsFs | BigIntStatsFs;
1184
- /**
1185
- * Synchronous lstat(2) - Get file status. Does not dereference symbolic links.
1186
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1187
- */
1188
- export const lstatSync: StatSyncFn;
1189
- /**
1190
- * Creates a new link from the `existingPath` to the `newPath`. See the POSIX [`link(2)`](http://man7.org/linux/man-pages/man2/link.2.html) documentation for more detail. No arguments other than
1191
- * a possible
1192
- * exception are given to the completion callback.
1193
- * @since v0.1.31
1194
- */
1195
- export function link(existingPath: PathLike, newPath: PathLike, callback: NoParamCallback): void;
1196
- export namespace link {
1197
- /**
1198
- * Asynchronous link(2) - Create a new link (also known as a hard link) to an existing file.
1199
- * @param existingPath A path to a file. If a URL is provided, it must use the `file:` protocol.
1200
- * @param newPath A path to a file. If a URL is provided, it must use the `file:` protocol.
1201
- */
1202
- function __promisify__(existingPath: PathLike, newPath: PathLike): Promise<void>;
1203
- }
1204
- /**
1205
- * Creates a new link from the `existingPath` to the `newPath`. See the POSIX [`link(2)`](http://man7.org/linux/man-pages/man2/link.2.html) documentation for more detail. Returns `undefined`.
1206
- * @since v0.1.31
1207
- */
1208
- export function linkSync(existingPath: PathLike, newPath: PathLike): void;
1209
- /**
1210
- * Creates the link called `path` pointing to `target`. No arguments other than a
1211
- * possible exception are given to the completion callback.
1212
- *
1213
- * See the POSIX [`symlink(2)`](http://man7.org/linux/man-pages/man2/symlink.2.html) documentation for more details.
1214
- *
1215
- * The `type` argument is only available on Windows and ignored on other platforms.
1216
- * It can be set to `'dir'`, `'file'`, or `'junction'`. If the `type` argument is
1217
- * not set, Node.js will autodetect `target` type and use `'file'` or `'dir'`. If
1218
- * the `target` does not exist, `'file'` will be used. Windows junction points
1219
- * require the destination path to be absolute. When using `'junction'`, the`target` argument will automatically be normalized to absolute path.
1220
- *
1221
- * Relative targets are relative to the link’s parent directory.
1222
- *
1223
- * ```js
1224
- * import { symlink } from 'fs';
1225
- *
1226
- * symlink('./mew', './mewtwo', callback);
1227
- * ```
1228
- *
1229
- * The above example creates a symbolic link `mewtwo` which points to `mew` in the
1230
- * same directory:
1231
- *
1232
- * ```bash
1233
- * $ tree .
1234
- * .
1235
- * ├── mew
1236
- * └── mewtwo -> ./mew
1237
- * ```
1238
- * @since v0.1.31
1239
- */
1240
- export function symlink(target: PathLike, path: PathLike, type: symlink.Type | undefined | null, callback: NoParamCallback): void;
1241
- /**
1242
- * Asynchronous symlink(2) - Create a new symbolic link to an existing file.
1243
- * @param target A path to an existing file. If a URL is provided, it must use the `file:` protocol.
1244
- * @param path A path to the new symlink. If a URL is provided, it must use the `file:` protocol.
1245
- */
1246
- export function symlink(target: PathLike, path: PathLike, callback: NoParamCallback): void;
1247
- export namespace symlink {
1248
- /**
1249
- * Asynchronous symlink(2) - Create a new symbolic link to an existing file.
1250
- * @param target A path to an existing file. If a URL is provided, it must use the `file:` protocol.
1251
- * @param path A path to the new symlink. If a URL is provided, it must use the `file:` protocol.
1252
- * @param type May be set to `'dir'`, `'file'`, or `'junction'` (default is `'file'`) and is only available on Windows (ignored on other platforms).
1253
- * When using `'junction'`, the `target` argument will automatically be normalized to an absolute path.
1254
- */
1255
- function __promisify__(target: PathLike, path: PathLike, type?: string | null): Promise<void>;
1256
- type Type = 'dir' | 'file' | 'junction';
1257
- }
1258
- /**
1259
- * Returns `undefined`.
1260
- *
1261
- * For detailed information, see the documentation of the asynchronous version of
1262
- * this API: {@link symlink}.
1263
- * @since v0.1.31
1264
- */
1265
- export function symlinkSync(target: PathLike, path: PathLike, type?: symlink.Type | null): void;
1266
- /**
1267
- * Reads the contents of the symbolic link referred to by `path`. The callback gets
1268
- * two arguments `(err, linkString)`.
1269
- *
1270
- * See the POSIX [`readlink(2)`](http://man7.org/linux/man-pages/man2/readlink.2.html) documentation for more details.
1271
- *
1272
- * The optional `options` argument can be a string specifying an encoding, or an
1273
- * object with an `encoding` property specifying the character encoding to use for
1274
- * the link path passed to the callback. If the `encoding` is set to `'buffer'`,
1275
- * the link path returned will be passed as a `Buffer` object.
1276
- * @since v0.1.31
1277
- */
1278
- export function readlink(path: PathLike, options: EncodingOption, callback: (err: NodeJS.ErrnoException | null, linkString: string) => void): void;
1279
- /**
1280
- * Asynchronous readlink(2) - read value of a symbolic link.
1281
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1282
- * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1283
- */
1284
- export function readlink(path: PathLike, options: BufferEncodingOption, callback: (err: NodeJS.ErrnoException | null, linkString: Buffer) => void): void;
1285
- /**
1286
- * Asynchronous readlink(2) - read value of a symbolic link.
1287
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1288
- * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1289
- */
1290
- export function readlink(path: PathLike, options: EncodingOption, callback: (err: NodeJS.ErrnoException | null, linkString: string | Buffer) => void): void;
1291
- /**
1292
- * Asynchronous readlink(2) - read value of a symbolic link.
1293
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1294
- */
1295
- export function readlink(path: PathLike, callback: (err: NodeJS.ErrnoException | null, linkString: string) => void): void;
1296
- export namespace readlink {
1297
- /**
1298
- * Asynchronous readlink(2) - read value of a symbolic link.
1299
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1300
- * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1301
- */
1302
- function __promisify__(path: PathLike, options?: EncodingOption): Promise<string>;
1303
- /**
1304
- * Asynchronous readlink(2) - read value of a symbolic link.
1305
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1306
- * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1307
- */
1308
- function __promisify__(path: PathLike, options: BufferEncodingOption): Promise<Buffer>;
1309
- /**
1310
- * Asynchronous readlink(2) - read value of a symbolic link.
1311
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1312
- * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1313
- */
1314
- function __promisify__(path: PathLike, options?: EncodingOption): Promise<string | Buffer>;
1315
- }
1316
- /**
1317
- * Returns the symbolic link's string value.
1318
- *
1319
- * See the POSIX [`readlink(2)`](http://man7.org/linux/man-pages/man2/readlink.2.html) documentation for more details.
1320
- *
1321
- * The optional `options` argument can be a string specifying an encoding, or an
1322
- * object with an `encoding` property specifying the character encoding to use for
1323
- * the link path returned. If the `encoding` is set to `'buffer'`,
1324
- * the link path returned will be passed as a `Buffer` object.
1325
- * @since v0.1.31
1326
- */
1327
- export function readlinkSync(path: PathLike, options?: EncodingOption): string;
1328
- /**
1329
- * Synchronous readlink(2) - read value of a symbolic link.
1330
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1331
- * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1332
- */
1333
- export function readlinkSync(path: PathLike, options: BufferEncodingOption): Buffer;
1334
- /**
1335
- * Synchronous readlink(2) - read value of a symbolic link.
1336
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1337
- * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1338
- */
1339
- export function readlinkSync(path: PathLike, options?: EncodingOption): string | Buffer;
1340
- /**
1341
- * Asynchronously computes the canonical pathname by resolving `.`, `..` and
1342
- * symbolic links.
1343
- *
1344
- * A canonical pathname is not necessarily unique. Hard links and bind mounts can
1345
- * expose a file system entity through many pathnames.
1346
- *
1347
- * This function behaves like [`realpath(3)`](http://man7.org/linux/man-pages/man3/realpath.3.html), with some exceptions:
1348
- *
1349
- * 1. No case conversion is performed on case-insensitive file systems.
1350
- * 2. The maximum number of symbolic links is platform-independent and generally
1351
- * (much) higher than what the native [`realpath(3)`](http://man7.org/linux/man-pages/man3/realpath.3.html) implementation supports.
1352
- *
1353
- * The `callback` gets two arguments `(err, resolvedPath)`. May use `process.cwd`to resolve relative paths.
1354
- *
1355
- * Only paths that can be converted to UTF8 strings are supported.
1356
- *
1357
- * The optional `options` argument can be a string specifying an encoding, or an
1358
- * object with an `encoding` property specifying the character encoding to use for
1359
- * the path passed to the callback. If the `encoding` is set to `'buffer'`,
1360
- * the path returned will be passed as a `Buffer` object.
1361
- *
1362
- * If `path` resolves to a socket or a pipe, the function will return a system
1363
- * dependent name for that object.
1364
- * @since v0.1.31
1365
- */
1366
- export function realpath(path: PathLike, options: EncodingOption, callback: (err: NodeJS.ErrnoException | null, resolvedPath: string) => void): void;
1367
- /**
1368
- * Asynchronous realpath(3) - return the canonicalized absolute pathname.
1369
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1370
- * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1371
- */
1372
- export function realpath(path: PathLike, options: BufferEncodingOption, callback: (err: NodeJS.ErrnoException | null, resolvedPath: Buffer) => void): void;
1373
- /**
1374
- * Asynchronous realpath(3) - return the canonicalized absolute pathname.
1375
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1376
- * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1377
- */
1378
- export function realpath(path: PathLike, options: EncodingOption, callback: (err: NodeJS.ErrnoException | null, resolvedPath: string | Buffer) => void): void;
1379
- /**
1380
- * Asynchronous realpath(3) - return the canonicalized absolute pathname.
1381
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1382
- */
1383
- export function realpath(path: PathLike, callback: (err: NodeJS.ErrnoException | null, resolvedPath: string) => void): void;
1384
- export namespace realpath {
1385
- /**
1386
- * Asynchronous realpath(3) - return the canonicalized absolute pathname.
1387
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1388
- * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1389
- */
1390
- function __promisify__(path: PathLike, options?: EncodingOption): Promise<string>;
1391
- /**
1392
- * Asynchronous realpath(3) - return the canonicalized absolute pathname.
1393
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1394
- * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1395
- */
1396
- function __promisify__(path: PathLike, options: BufferEncodingOption): Promise<Buffer>;
1397
- /**
1398
- * Asynchronous realpath(3) - return the canonicalized absolute pathname.
1399
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1400
- * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1401
- */
1402
- function __promisify__(path: PathLike, options?: EncodingOption): Promise<string | Buffer>;
1403
- /**
1404
- * Asynchronous [`realpath(3)`](http://man7.org/linux/man-pages/man3/realpath.3.html).
1405
- *
1406
- * The `callback` gets two arguments `(err, resolvedPath)`.
1407
- *
1408
- * Only paths that can be converted to UTF8 strings are supported.
1409
- *
1410
- * The optional `options` argument can be a string specifying an encoding, or an
1411
- * object with an `encoding` property specifying the character encoding to use for
1412
- * the path passed to the callback. If the `encoding` is set to `'buffer'`,
1413
- * the path returned will be passed as a `Buffer` object.
1414
- *
1415
- * On Linux, when Node.js is linked against musl libc, the procfs file system must
1416
- * be mounted on `/proc` in order for this function to work. Glibc does not have
1417
- * this restriction.
1418
- * @since v9.2.0
1419
- */
1420
- function native(path: PathLike, options: EncodingOption, callback: (err: NodeJS.ErrnoException | null, resolvedPath: string) => void): void;
1421
- function native(path: PathLike, options: BufferEncodingOption, callback: (err: NodeJS.ErrnoException | null, resolvedPath: Buffer) => void): void;
1422
- function native(path: PathLike, options: EncodingOption, callback: (err: NodeJS.ErrnoException | null, resolvedPath: string | Buffer) => void): void;
1423
- function native(path: PathLike, callback: (err: NodeJS.ErrnoException | null, resolvedPath: string) => void): void;
1424
- }
1425
- /**
1426
- * Returns the resolved pathname.
1427
- *
1428
- * For detailed information, see the documentation of the asynchronous version of
1429
- * this API: {@link realpath}.
1430
- * @since v0.1.31
1431
- */
1432
- export function realpathSync(path: PathLike, options?: EncodingOption): string;
1433
- /**
1434
- * Synchronous realpath(3) - return the canonicalized absolute pathname.
1435
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1436
- * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1437
- */
1438
- export function realpathSync(path: PathLike, options: BufferEncodingOption): Buffer;
1439
- /**
1440
- * Synchronous realpath(3) - return the canonicalized absolute pathname.
1441
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1442
- * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1443
- */
1444
- export function realpathSync(path: PathLike, options?: EncodingOption): string | Buffer;
1445
- export namespace realpathSync {
1446
- function native(path: PathLike, options?: EncodingOption): string;
1447
- function native(path: PathLike, options: BufferEncodingOption): Buffer;
1448
- function native(path: PathLike, options?: EncodingOption): string | Buffer;
1449
- }
1450
- /**
1451
- * Asynchronously removes a file or symbolic link. No arguments other than a
1452
- * possible exception are given to the completion callback.
1453
- *
1454
- * ```js
1455
- * import { unlink } from 'fs';
1456
- * // Assuming that 'path/file.txt' is a regular file.
1457
- * unlink('path/file.txt', (err) => {
1458
- * if (err) throw err;
1459
- * console.log('path/file.txt was deleted');
1460
- * });
1461
- * ```
1462
- *
1463
- * `fs.unlink()` will not work on a directory, empty or otherwise. To remove a
1464
- * directory, use {@link rmdir}.
1465
- *
1466
- * See the POSIX [`unlink(2)`](http://man7.org/linux/man-pages/man2/unlink.2.html) documentation for more details.
1467
- * @since v0.0.2
1468
- */
1469
- export function unlink(path: PathLike, callback: NoParamCallback): void;
1470
- export namespace unlink {
1471
- /**
1472
- * Asynchronous unlink(2) - delete a name and possibly the file it refers to.
1473
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1474
- */
1475
- function __promisify__(path: PathLike): Promise<void>;
1476
- }
1477
- /**
1478
- * Synchronous [`unlink(2)`](http://man7.org/linux/man-pages/man2/unlink.2.html). Returns `undefined`.
1479
- * @since v0.1.21
1480
- */
1481
- export function unlinkSync(path: PathLike): void;
1482
- export interface RmDirOptions {
1483
- /**
1484
- * If an `EBUSY`, `EMFILE`, `ENFILE`, `ENOTEMPTY`, or
1485
- * `EPERM` error is encountered, Node.js will retry the operation with a linear
1486
- * backoff wait of `retryDelay` ms longer on each try. This option represents the
1487
- * number of retries. This option is ignored if the `recursive` option is not
1488
- * `true`.
1489
- * @default 0
1490
- */
1491
- maxRetries?: number | undefined;
1492
- /**
1493
- * @deprecated since v14.14.0 In future versions of Node.js and will trigger a warning
1494
- * `fs.rmdir(path, { recursive: true })` will throw if `path` does not exist or is a file.
1495
- * Use `fs.rm(path, { recursive: true, force: true })` instead.
1496
- *
1497
- * If `true`, perform a recursive directory removal. In
1498
- * recursive mode, operations are retried on failure.
1499
- * @default false
1500
- */
1501
- recursive?: boolean | undefined;
1502
- /**
1503
- * The amount of time in milliseconds to wait between retries.
1504
- * This option is ignored if the `recursive` option is not `true`.
1505
- * @default 100
1506
- */
1507
- retryDelay?: number | undefined;
1508
- }
1509
- /**
1510
- * Asynchronous [`rmdir(2)`](http://man7.org/linux/man-pages/man2/rmdir.2.html). No arguments other than a possible exception are given
1511
- * to the completion callback.
1512
- *
1513
- * Using `fs.rmdir()` on a file (not a directory) results in an `ENOENT` error on
1514
- * Windows and an `ENOTDIR` error on POSIX.
1515
- *
1516
- * To get a behavior similar to the `rm -rf` Unix command, use {@link rm} with options `{ recursive: true, force: true }`.
1517
- * @since v0.0.2
1518
- */
1519
- export function rmdir(path: PathLike, callback: NoParamCallback): void;
1520
- export function rmdir(path: PathLike, options: RmDirOptions, callback: NoParamCallback): void;
1521
- export namespace rmdir {
1522
- /**
1523
- * Asynchronous rmdir(2) - delete a directory.
1524
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1525
- */
1526
- function __promisify__(path: PathLike, options?: RmDirOptions): Promise<void>;
1527
- }
1528
- /**
1529
- * Synchronous [`rmdir(2)`](http://man7.org/linux/man-pages/man2/rmdir.2.html). Returns `undefined`.
1530
- *
1531
- * Using `fs.rmdirSync()` on a file (not a directory) results in an `ENOENT` error
1532
- * on Windows and an `ENOTDIR` error on POSIX.
1533
- *
1534
- * To get a behavior similar to the `rm -rf` Unix command, use {@link rmSync} with options `{ recursive: true, force: true }`.
1535
- * @since v0.1.21
1536
- */
1537
- export function rmdirSync(path: PathLike, options?: RmDirOptions): void;
1538
- export interface RmOptions {
1539
- /**
1540
- * When `true`, exceptions will be ignored if `path` does not exist.
1541
- * @default false
1542
- */
1543
- force?: boolean | undefined;
1544
- /**
1545
- * If an `EBUSY`, `EMFILE`, `ENFILE`, `ENOTEMPTY`, or
1546
- * `EPERM` error is encountered, Node.js will retry the operation with a linear
1547
- * backoff wait of `retryDelay` ms longer on each try. This option represents the
1548
- * number of retries. This option is ignored if the `recursive` option is not
1549
- * `true`.
1550
- * @default 0
1551
- */
1552
- maxRetries?: number | undefined;
1553
- /**
1554
- * If `true`, perform a recursive directory removal. In
1555
- * recursive mode, operations are retried on failure.
1556
- * @default false
1557
- */
1558
- recursive?: boolean | undefined;
1559
- /**
1560
- * The amount of time in milliseconds to wait between retries.
1561
- * This option is ignored if the `recursive` option is not `true`.
1562
- * @default 100
1563
- */
1564
- retryDelay?: number | undefined;
1565
- }
1566
- /**
1567
- * Asynchronously removes files and directories (modeled on the standard POSIX `rm`utility). No arguments other than a possible exception are given to the
1568
- * completion callback.
1569
- * @since v14.14.0
1570
- */
1571
- export function rm(path: PathLike, callback: NoParamCallback): void;
1572
- export function rm(path: PathLike, options: RmOptions, callback: NoParamCallback): void;
1573
- export namespace rm {
1574
- /**
1575
- * Asynchronously removes files and directories (modeled on the standard POSIX `rm` utility).
1576
- */
1577
- function __promisify__(path: PathLike, options?: RmOptions): Promise<void>;
1578
- }
1579
- /**
1580
- * Synchronously removes files and directories (modeled on the standard POSIX `rm`utility). Returns `undefined`.
1581
- * @since v14.14.0
1582
- */
1583
- export function rmSync(path: PathLike, options?: RmOptions): void;
1584
- export interface MakeDirectoryOptions {
1585
- /**
1586
- * Indicates whether parent folders should be created.
1587
- * If a folder was created, the path to the first created folder will be returned.
1588
- * @default false
1589
- */
1590
- recursive?: boolean | undefined;
1591
- /**
1592
- * A file mode. If a string is passed, it is parsed as an octal integer. If not specified
1593
- * @default 0o777
1594
- */
1595
- mode?: Mode | undefined;
1596
- }
1597
- /**
1598
- * Asynchronously creates a directory.
1599
- *
1600
- * The callback is given a possible exception and, if `recursive` is `true`, the
1601
- * first directory path created, `(err[, path])`.`path` can still be `undefined` when `recursive` is `true`, if no directory was
1602
- * created.
1603
- *
1604
- * The optional `options` argument can be an integer specifying `mode` (permission
1605
- * and sticky bits), or an object with a `mode` property and a `recursive`property indicating whether parent directories should be created. Calling`fs.mkdir()` when `path` is a directory that
1606
- * exists results in an error only
1607
- * when `recursive` is false.
1608
- *
1609
- * ```js
1610
- * import { mkdir } from 'fs';
1611
- *
1612
- * // Creates /tmp/a/apple, regardless of whether `/tmp` and /tmp/a exist.
1613
- * mkdir('/tmp/a/apple', { recursive: true }, (err) => {
1614
- * if (err) throw err;
1615
- * });
1616
- * ```
1617
- *
1618
- * On Windows, using `fs.mkdir()` on the root directory even with recursion will
1619
- * result in an error:
1620
- *
1621
- * ```js
1622
- * import { mkdir } from 'fs';
1623
- *
1624
- * mkdir('/', { recursive: true }, (err) => {
1625
- * // => [Error: EPERM: operation not permitted, mkdir 'C:\']
1626
- * });
1627
- * ```
1628
- *
1629
- * See the POSIX [`mkdir(2)`](http://man7.org/linux/man-pages/man2/mkdir.2.html) documentation for more details.
1630
- * @since v0.1.8
1631
- */
1632
- export function mkdir(
1633
- path: PathLike,
1634
- options: MakeDirectoryOptions & {
1635
- recursive: true;
1636
- },
1637
- callback: (err: NodeJS.ErrnoException | null, path?: string) => void
1638
- ): void;
1639
- /**
1640
- * Asynchronous mkdir(2) - create a directory.
1641
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1642
- * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
1643
- * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
1644
- */
1645
- export function mkdir(
1646
- path: PathLike,
1647
- options:
1648
- | Mode
1649
- | (MakeDirectoryOptions & {
1650
- recursive?: false | undefined;
1651
- })
1652
- | null
1653
- | undefined,
1654
- callback: NoParamCallback
1655
- ): void;
1656
- /**
1657
- * Asynchronous mkdir(2) - create a directory.
1658
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1659
- * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
1660
- * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
1661
- */
1662
- export function mkdir(path: PathLike, options: Mode | MakeDirectoryOptions | null | undefined, callback: (err: NodeJS.ErrnoException | null, path?: string) => void): void;
1663
- /**
1664
- * Asynchronous mkdir(2) - create a directory with a mode of `0o777`.
1665
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1666
- */
1667
- export function mkdir(path: PathLike, callback: NoParamCallback): void;
1668
- export namespace mkdir {
1669
- /**
1670
- * Asynchronous mkdir(2) - create a directory.
1671
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1672
- * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
1673
- * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
1674
- */
1675
- function __promisify__(
1676
- path: PathLike,
1677
- options: MakeDirectoryOptions & {
1678
- recursive: true;
1679
- }
1680
- ): Promise<string | undefined>;
1681
- /**
1682
- * Asynchronous mkdir(2) - create a directory.
1683
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1684
- * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
1685
- * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
1686
- */
1687
- function __promisify__(
1688
- path: PathLike,
1689
- options?:
1690
- | Mode
1691
- | (MakeDirectoryOptions & {
1692
- recursive?: false | undefined;
1693
- })
1694
- | null
1695
- ): Promise<void>;
1696
- /**
1697
- * Asynchronous mkdir(2) - create a directory.
1698
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1699
- * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
1700
- * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
1701
- */
1702
- function __promisify__(path: PathLike, options?: Mode | MakeDirectoryOptions | null): Promise<string | undefined>;
1703
- }
1704
- /**
1705
- * Synchronously creates a directory. Returns `undefined`, or if `recursive` is`true`, the first directory path created.
1706
- * This is the synchronous version of {@link mkdir}.
1707
- *
1708
- * See the POSIX [`mkdir(2)`](http://man7.org/linux/man-pages/man2/mkdir.2.html) documentation for more details.
1709
- * @since v0.1.21
1710
- */
1711
- export function mkdirSync(
1712
- path: PathLike,
1713
- options: MakeDirectoryOptions & {
1714
- recursive: true;
1715
- }
1716
- ): string | undefined;
1717
- /**
1718
- * Synchronous mkdir(2) - create a directory.
1719
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1720
- * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
1721
- * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
1722
- */
1723
- export function mkdirSync(
1724
- path: PathLike,
1725
- options?:
1726
- | Mode
1727
- | (MakeDirectoryOptions & {
1728
- recursive?: false | undefined;
1729
- })
1730
- | null
1731
- ): void;
1732
- /**
1733
- * Synchronous mkdir(2) - create a directory.
1734
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1735
- * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
1736
- * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
1737
- */
1738
- export function mkdirSync(path: PathLike, options?: Mode | MakeDirectoryOptions | null): string | undefined;
1739
- /**
1740
- * Creates a unique temporary directory.
1741
- *
1742
- * Generates six random characters to be appended behind a required`prefix` to create a unique temporary directory. Due to platform
1743
- * inconsistencies, avoid trailing `X` characters in `prefix`. Some platforms,
1744
- * notably the BSDs, can return more than six random characters, and replace
1745
- * trailing `X` characters in `prefix` with random characters.
1746
- *
1747
- * The created directory path is passed as a string to the callback's second
1748
- * parameter.
1749
- *
1750
- * The optional `options` argument can be a string specifying an encoding, or an
1751
- * object with an `encoding` property specifying the character encoding to use.
1752
- *
1753
- * ```js
1754
- * import { mkdtemp } from 'fs';
1755
- *
1756
- * mkdtemp(path.join(os.tmpdir(), 'foo-'), (err, directory) => {
1757
- * if (err) throw err;
1758
- * console.log(directory);
1759
- * // Prints: /tmp/foo-itXde2 or C:\Users\...\AppData\Local\Temp\foo-itXde2
1760
- * });
1761
- * ```
1762
- *
1763
- * The `fs.mkdtemp()` method will append the six randomly selected characters
1764
- * directly to the `prefix` string. For instance, given a directory `/tmp`, if the
1765
- * intention is to create a temporary directory _within_`/tmp`, the `prefix`must end with a trailing platform-specific path separator
1766
- * (`require('path').sep`).
1767
- *
1768
- * ```js
1769
- * import { tmpdir } from 'os';
1770
- * import { mkdtemp } from 'fs';
1771
- *
1772
- * // The parent directory for the new temporary directory
1773
- * const tmpDir = tmpdir();
1774
- *
1775
- * // This method is *INCORRECT*:
1776
- * mkdtemp(tmpDir, (err, directory) => {
1777
- * if (err) throw err;
1778
- * console.log(directory);
1779
- * // Will print something similar to `/tmpabc123`.
1780
- * // A new temporary directory is created at the file system root
1781
- * // rather than *within* the /tmp directory.
1782
- * });
1783
- *
1784
- * // This method is *CORRECT*:
1785
- * import { sep } from 'path';
1786
- * mkdtemp(`${tmpDir}${sep}`, (err, directory) => {
1787
- * if (err) throw err;
1788
- * console.log(directory);
1789
- * // Will print something similar to `/tmp/abc123`.
1790
- * // A new temporary directory is created within
1791
- * // the /tmp directory.
1792
- * });
1793
- * ```
1794
- * @since v5.10.0
1795
- */
1796
- export function mkdtemp(prefix: string, options: EncodingOption, callback: (err: NodeJS.ErrnoException | null, folder: string) => void): void;
1797
- /**
1798
- * Asynchronously creates a unique temporary directory.
1799
- * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
1800
- * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1801
- */
1802
- export function mkdtemp(
1803
- prefix: string,
1804
- options:
1805
- | 'buffer'
1806
- | {
1807
- encoding: 'buffer';
1808
- },
1809
- callback: (err: NodeJS.ErrnoException | null, folder: Buffer) => void
1810
- ): void;
1811
- /**
1812
- * Asynchronously creates a unique temporary directory.
1813
- * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
1814
- * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1815
- */
1816
- export function mkdtemp(prefix: string, options: EncodingOption, callback: (err: NodeJS.ErrnoException | null, folder: string | Buffer) => void): void;
1817
- /**
1818
- * Asynchronously creates a unique temporary directory.
1819
- * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
1820
- */
1821
- export function mkdtemp(prefix: string, callback: (err: NodeJS.ErrnoException | null, folder: string) => void): void;
1822
- export namespace mkdtemp {
1823
- /**
1824
- * Asynchronously creates a unique temporary directory.
1825
- * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
1826
- * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1827
- */
1828
- function __promisify__(prefix: string, options?: EncodingOption): Promise<string>;
1829
- /**
1830
- * Asynchronously creates a unique temporary directory.
1831
- * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
1832
- * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1833
- */
1834
- function __promisify__(prefix: string, options: BufferEncodingOption): Promise<Buffer>;
1835
- /**
1836
- * Asynchronously creates a unique temporary directory.
1837
- * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
1838
- * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1839
- */
1840
- function __promisify__(prefix: string, options?: EncodingOption): Promise<string | Buffer>;
1841
- }
1842
- /**
1843
- * Returns the created directory path.
1844
- *
1845
- * For detailed information, see the documentation of the asynchronous version of
1846
- * this API: {@link mkdtemp}.
1847
- *
1848
- * The optional `options` argument can be a string specifying an encoding, or an
1849
- * object with an `encoding` property specifying the character encoding to use.
1850
- * @since v5.10.0
1851
- */
1852
- export function mkdtempSync(prefix: string, options?: EncodingOption): string;
1853
- /**
1854
- * Synchronously creates a unique temporary directory.
1855
- * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
1856
- * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1857
- */
1858
- export function mkdtempSync(prefix: string, options: BufferEncodingOption): Buffer;
1859
- /**
1860
- * Synchronously creates a unique temporary directory.
1861
- * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
1862
- * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1863
- */
1864
- export function mkdtempSync(prefix: string, options?: EncodingOption): string | Buffer;
1865
- /**
1866
- * Reads the contents of a directory. The callback gets two arguments `(err, files)`where `files` is an array of the names of the files in the directory excluding`'.'` and `'..'`.
1867
- *
1868
- * See the POSIX [`readdir(3)`](http://man7.org/linux/man-pages/man3/readdir.3.html) documentation for more details.
1869
- *
1870
- * The optional `options` argument can be a string specifying an encoding, or an
1871
- * object with an `encoding` property specifying the character encoding to use for
1872
- * the filenames passed to the callback. If the `encoding` is set to `'buffer'`,
1873
- * the filenames returned will be passed as `Buffer` objects.
1874
- *
1875
- * If `options.withFileTypes` is set to `true`, the `files` array will contain `fs.Dirent` objects.
1876
- * @since v0.1.8
1877
- */
1878
- export function readdir(
1879
- path: PathLike,
1880
- options:
1881
- | {
1882
- encoding: BufferEncoding | null;
1883
- withFileTypes?: false | undefined;
1884
- }
1885
- | BufferEncoding
1886
- | undefined
1887
- | null,
1888
- callback: (err: NodeJS.ErrnoException | null, files: string[]) => void
1889
- ): void;
1890
- /**
1891
- * Asynchronous readdir(3) - read a directory.
1892
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1893
- * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1894
- */
1895
- export function readdir(
1896
- path: PathLike,
1897
- options:
1898
- | {
1899
- encoding: 'buffer';
1900
- withFileTypes?: false | undefined;
1901
- }
1902
- | 'buffer',
1903
- callback: (err: NodeJS.ErrnoException | null, files: Buffer[]) => void
1904
- ): void;
1905
- /**
1906
- * Asynchronous readdir(3) - read a directory.
1907
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1908
- * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1909
- */
1910
- export function readdir(
1911
- path: PathLike,
1912
- options:
1913
- | (ObjectEncodingOptions & {
1914
- withFileTypes?: false | undefined;
1915
- })
1916
- | BufferEncoding
1917
- | undefined
1918
- | null,
1919
- callback: (err: NodeJS.ErrnoException | null, files: string[] | Buffer[]) => void
1920
- ): void;
1921
- /**
1922
- * Asynchronous readdir(3) - read a directory.
1923
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1924
- */
1925
- export function readdir(path: PathLike, callback: (err: NodeJS.ErrnoException | null, files: string[]) => void): void;
1926
- /**
1927
- * Asynchronous readdir(3) - read a directory.
1928
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1929
- * @param options If called with `withFileTypes: true` the result data will be an array of Dirent.
1930
- */
1931
- export function readdir(
1932
- path: PathLike,
1933
- options: ObjectEncodingOptions & {
1934
- withFileTypes: true;
1935
- },
1936
- callback: (err: NodeJS.ErrnoException | null, files: Dirent[]) => void
1937
- ): void;
1938
- export namespace readdir {
1939
- /**
1940
- * Asynchronous readdir(3) - read a directory.
1941
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1942
- * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1943
- */
1944
- function __promisify__(
1945
- path: PathLike,
1946
- options?:
1947
- | {
1948
- encoding: BufferEncoding | null;
1949
- withFileTypes?: false | undefined;
1950
- }
1951
- | BufferEncoding
1952
- | null
1953
- ): Promise<string[]>;
1954
- /**
1955
- * Asynchronous readdir(3) - read a directory.
1956
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1957
- * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1958
- */
1959
- function __promisify__(
1960
- path: PathLike,
1961
- options:
1962
- | 'buffer'
1963
- | {
1964
- encoding: 'buffer';
1965
- withFileTypes?: false | undefined;
1966
- }
1967
- ): Promise<Buffer[]>;
1968
- /**
1969
- * Asynchronous readdir(3) - read a directory.
1970
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1971
- * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
1972
- */
1973
- function __promisify__(
1974
- path: PathLike,
1975
- options?:
1976
- | (ObjectEncodingOptions & {
1977
- withFileTypes?: false | undefined;
1978
- })
1979
- | BufferEncoding
1980
- | null
1981
- ): Promise<string[] | Buffer[]>;
1982
- /**
1983
- * Asynchronous readdir(3) - read a directory.
1984
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
1985
- * @param options If called with `withFileTypes: true` the result data will be an array of Dirent
1986
- */
1987
- function __promisify__(
1988
- path: PathLike,
1989
- options: ObjectEncodingOptions & {
1990
- withFileTypes: true;
1991
- }
1992
- ): Promise<Dirent[]>;
1993
- }
1994
- /**
1995
- * Reads the contents of the directory.
1996
- *
1997
- * See the POSIX [`readdir(3)`](http://man7.org/linux/man-pages/man3/readdir.3.html) documentation for more details.
1998
- *
1999
- * The optional `options` argument can be a string specifying an encoding, or an
2000
- * object with an `encoding` property specifying the character encoding to use for
2001
- * the filenames returned. If the `encoding` is set to `'buffer'`,
2002
- * the filenames returned will be passed as `Buffer` objects.
2003
- *
2004
- * If `options.withFileTypes` is set to `true`, the result will contain `fs.Dirent` objects.
2005
- * @since v0.1.21
2006
- */
2007
- export function readdirSync(
2008
- path: PathLike,
2009
- options?:
2010
- | {
2011
- encoding: BufferEncoding | null;
2012
- withFileTypes?: false | undefined;
2013
- }
2014
- | BufferEncoding
2015
- | null
2016
- ): string[];
2017
- /**
2018
- * Synchronous readdir(3) - read a directory.
2019
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2020
- * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
2021
- */
2022
- export function readdirSync(
2023
- path: PathLike,
2024
- options:
2025
- | {
2026
- encoding: 'buffer';
2027
- withFileTypes?: false | undefined;
2028
- }
2029
- | 'buffer'
2030
- ): Buffer[];
2031
- /**
2032
- * Synchronous readdir(3) - read a directory.
2033
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2034
- * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
2035
- */
2036
- export function readdirSync(
2037
- path: PathLike,
2038
- options?:
2039
- | (ObjectEncodingOptions & {
2040
- withFileTypes?: false | undefined;
2041
- })
2042
- | BufferEncoding
2043
- | null
2044
- ): string[] | Buffer[];
2045
- /**
2046
- * Synchronous readdir(3) - read a directory.
2047
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2048
- * @param options If called with `withFileTypes: true` the result data will be an array of Dirent.
2049
- */
2050
- export function readdirSync(
2051
- path: PathLike,
2052
- options: ObjectEncodingOptions & {
2053
- withFileTypes: true;
2054
- }
2055
- ): Dirent[];
2056
- /**
2057
- * Closes the file descriptor. No arguments other than a possible exception are
2058
- * given to the completion callback.
2059
- *
2060
- * Calling `fs.close()` on any file descriptor (`fd`) that is currently in use
2061
- * through any other `fs` operation may lead to undefined behavior.
2062
- *
2063
- * See the POSIX [`close(2)`](http://man7.org/linux/man-pages/man2/close.2.html) documentation for more detail.
2064
- * @since v0.0.2
2065
- */
2066
- export function close(fd: number, callback?: NoParamCallback): void;
2067
- export namespace close {
2068
- /**
2069
- * Asynchronous close(2) - close a file descriptor.
2070
- * @param fd A file descriptor.
2071
- */
2072
- function __promisify__(fd: number): Promise<void>;
2073
- }
2074
- /**
2075
- * Closes the file descriptor. Returns `undefined`.
2076
- *
2077
- * Calling `fs.closeSync()` on any file descriptor (`fd`) that is currently in use
2078
- * through any other `fs` operation may lead to undefined behavior.
2079
- *
2080
- * See the POSIX [`close(2)`](http://man7.org/linux/man-pages/man2/close.2.html) documentation for more detail.
2081
- * @since v0.1.21
2082
- */
2083
- export function closeSync(fd: number): void;
2084
- /**
2085
- * Asynchronous file open. See the POSIX [`open(2)`](http://man7.org/linux/man-pages/man2/open.2.html) documentation for more details.
2086
- *
2087
- * `mode` sets the file mode (permission and sticky bits), but only if the file was
2088
- * created. On Windows, only the write permission can be manipulated; see {@link chmod}.
2089
- *
2090
- * The callback gets two arguments `(err, fd)`.
2091
- *
2092
- * Some characters (`< > : " / \ | ? *`) are reserved under Windows as documented
2093
- * by [Naming Files, Paths, and Namespaces](https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file). Under NTFS, if the filename contains
2094
- * a colon, Node.js will open a file system stream, as described by [this MSDN page](https://docs.microsoft.com/en-us/windows/desktop/FileIO/using-streams).
2095
- *
2096
- * Functions based on `fs.open()` exhibit this behavior as well:`fs.writeFile()`, `fs.readFile()`, etc.
2097
- * @since v0.0.2
2098
- * @param [flags='r'] See `support of file system `flags``.
2099
- * @param [mode=0o666]
2100
- */
2101
- export function open(path: PathLike, flags: OpenMode | undefined, mode: Mode | undefined | null, callback: (err: NodeJS.ErrnoException | null, fd: number) => void): void;
2102
- /**
2103
- * Asynchronous open(2) - open and possibly create a file. If the file is created, its mode will be `0o666`.
2104
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2105
- * @param [flags='r'] See `support of file system `flags``.
2106
- */
2107
- export function open(path: PathLike, flags: OpenMode | undefined, callback: (err: NodeJS.ErrnoException | null, fd: number) => void): void;
2108
- /**
2109
- * Asynchronous open(2) - open and possibly create a file. If the file is created, its mode will be `0o666`.
2110
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2111
- */
2112
- export function open(path: PathLike, callback: (err: NodeJS.ErrnoException | null, fd: number) => void): void;
2113
-
2114
- export namespace open {
2115
- /**
2116
- * Asynchronous open(2) - open and possibly create a file.
2117
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2118
- * @param mode A file mode. If a string is passed, it is parsed as an octal integer. If not supplied, defaults to `0o666`.
2119
- */
2120
- function __promisify__(path: PathLike, flags: OpenMode, mode?: Mode | null): Promise<number>;
2121
- }
2122
- /**
2123
- * Returns an integer representing the file descriptor.
2124
- *
2125
- * For detailed information, see the documentation of the asynchronous version of
2126
- * this API: {@link open}.
2127
- * @since v0.1.21
2128
- * @param [flags='r']
2129
- * @param [mode=0o666]
2130
- */
2131
- export function openSync(path: PathLike, flags: OpenMode, mode?: Mode | null): number;
2132
- /**
2133
- * Change the file system timestamps of the object referenced by `path`.
2134
- *
2135
- * The `atime` and `mtime` arguments follow these rules:
2136
- *
2137
- * * Values can be either numbers representing Unix epoch time in seconds,`Date`s, or a numeric string like `'123456789.0'`.
2138
- * * If the value can not be converted to a number, or is `NaN`, `Infinity` or`-Infinity`, an `Error` will be thrown.
2139
- * @since v0.4.2
2140
- */
2141
- export function utimes(path: PathLike, atime: TimeLike, mtime: TimeLike, callback: NoParamCallback): void;
2142
- export namespace utimes {
2143
- /**
2144
- * Asynchronously change file timestamps of the file referenced by the supplied path.
2145
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2146
- * @param atime The last access time. If a string is provided, it will be coerced to number.
2147
- * @param mtime The last modified time. If a string is provided, it will be coerced to number.
2148
- */
2149
- function __promisify__(path: PathLike, atime: TimeLike, mtime: TimeLike): Promise<void>;
2150
- }
2151
- /**
2152
- * Returns `undefined`.
2153
- *
2154
- * For detailed information, see the documentation of the asynchronous version of
2155
- * this API: {@link utimes}.
2156
- * @since v0.4.2
2157
- */
2158
- export function utimesSync(path: PathLike, atime: TimeLike, mtime: TimeLike): void;
2159
- /**
2160
- * Change the file system timestamps of the object referenced by the supplied file
2161
- * descriptor. See {@link utimes}.
2162
- * @since v0.4.2
2163
- */
2164
- export function futimes(fd: number, atime: TimeLike, mtime: TimeLike, callback: NoParamCallback): void;
2165
- export namespace futimes {
2166
- /**
2167
- * Asynchronously change file timestamps of the file referenced by the supplied file descriptor.
2168
- * @param fd A file descriptor.
2169
- * @param atime The last access time. If a string is provided, it will be coerced to number.
2170
- * @param mtime The last modified time. If a string is provided, it will be coerced to number.
2171
- */
2172
- function __promisify__(fd: number, atime: TimeLike, mtime: TimeLike): Promise<void>;
2173
- }
2174
- /**
2175
- * Synchronous version of {@link futimes}. Returns `undefined`.
2176
- * @since v0.4.2
2177
- */
2178
- export function futimesSync(fd: number, atime: TimeLike, mtime: TimeLike): void;
2179
- /**
2180
- * Request that all data for the open file descriptor is flushed to the storage
2181
- * device. The specific implementation is operating system and device specific.
2182
- * Refer to the POSIX [`fsync(2)`](http://man7.org/linux/man-pages/man2/fsync.2.html) documentation for more detail. No arguments other
2183
- * than a possible exception are given to the completion callback.
2184
- * @since v0.1.96
2185
- */
2186
- export function fsync(fd: number, callback: NoParamCallback): void;
2187
- export namespace fsync {
2188
- /**
2189
- * Asynchronous fsync(2) - synchronize a file's in-core state with the underlying storage device.
2190
- * @param fd A file descriptor.
2191
- */
2192
- function __promisify__(fd: number): Promise<void>;
2193
- }
2194
- /**
2195
- * Request that all data for the open file descriptor is flushed to the storage
2196
- * device. The specific implementation is operating system and device specific.
2197
- * Refer to the POSIX [`fsync(2)`](http://man7.org/linux/man-pages/man2/fsync.2.html) documentation for more detail. Returns `undefined`.
2198
- * @since v0.1.96
2199
- */
2200
- export function fsyncSync(fd: number): void;
2201
- /**
2202
- * Write `buffer` to the file specified by `fd`.
2203
- *
2204
- * `offset` determines the part of the buffer to be written, and `length` is
2205
- * an integer specifying the number of bytes to write.
2206
- *
2207
- * `position` refers to the offset from the beginning of the file where this data
2208
- * should be written. If `typeof position !== 'number'`, the data will be written
2209
- * at the current position. See [`pwrite(2)`](http://man7.org/linux/man-pages/man2/pwrite.2.html).
2210
- *
2211
- * The callback will be given three arguments `(err, bytesWritten, buffer)` where`bytesWritten` specifies how many _bytes_ were written from `buffer`.
2212
- *
2213
- * If this method is invoked as its `util.promisify()` ed version, it returns
2214
- * a promise for an `Object` with `bytesWritten` and `buffer` properties.
2215
- *
2216
- * It is unsafe to use `fs.write()` multiple times on the same file without waiting
2217
- * for the callback. For this scenario, {@link createWriteStream} is
2218
- * recommended.
2219
- *
2220
- * On Linux, positional writes don't work when the file is opened in append mode.
2221
- * The kernel ignores the position argument and always appends the data to
2222
- * the end of the file.
2223
- * @since v0.0.2
2224
- */
2225
- export function write<TBuffer extends NodeJS.ArrayBufferView>(
2226
- fd: number,
2227
- buffer: TBuffer,
2228
- offset: number | undefined | null,
2229
- length: number | undefined | null,
2230
- position: number | undefined | null,
2231
- callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void
2232
- ): void;
2233
- /**
2234
- * Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
2235
- * @param fd A file descriptor.
2236
- * @param offset The part of the buffer to be written. If not supplied, defaults to `0`.
2237
- * @param length The number of bytes to write. If not supplied, defaults to `buffer.length - offset`.
2238
- */
2239
- export function write<TBuffer extends NodeJS.ArrayBufferView>(
2240
- fd: number,
2241
- buffer: TBuffer,
2242
- offset: number | undefined | null,
2243
- length: number | undefined | null,
2244
- callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void
2245
- ): void;
2246
- /**
2247
- * Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
2248
- * @param fd A file descriptor.
2249
- * @param offset The part of the buffer to be written. If not supplied, defaults to `0`.
2250
- */
2251
- export function write<TBuffer extends NodeJS.ArrayBufferView>(
2252
- fd: number,
2253
- buffer: TBuffer,
2254
- offset: number | undefined | null,
2255
- callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void
2256
- ): void;
2257
- /**
2258
- * Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
2259
- * @param fd A file descriptor.
2260
- */
2261
- export function write<TBuffer extends NodeJS.ArrayBufferView>(fd: number, buffer: TBuffer, callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void): void;
2262
- /**
2263
- * Asynchronously writes `string` to the file referenced by the supplied file descriptor.
2264
- * @param fd A file descriptor.
2265
- * @param string A string to write.
2266
- * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
2267
- * @param encoding The expected string encoding.
2268
- */
2269
- export function write(
2270
- fd: number,
2271
- string: string,
2272
- position: number | undefined | null,
2273
- encoding: BufferEncoding | undefined | null,
2274
- callback: (err: NodeJS.ErrnoException | null, written: number, str: string) => void
2275
- ): void;
2276
- /**
2277
- * Asynchronously writes `string` to the file referenced by the supplied file descriptor.
2278
- * @param fd A file descriptor.
2279
- * @param string A string to write.
2280
- * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
2281
- */
2282
- export function write(fd: number, string: string, position: number | undefined | null, callback: (err: NodeJS.ErrnoException | null, written: number, str: string) => void): void;
2283
- /**
2284
- * Asynchronously writes `string` to the file referenced by the supplied file descriptor.
2285
- * @param fd A file descriptor.
2286
- * @param string A string to write.
2287
- */
2288
- export function write(fd: number, string: string, callback: (err: NodeJS.ErrnoException | null, written: number, str: string) => void): void;
2289
- export namespace write {
2290
- /**
2291
- * Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
2292
- * @param fd A file descriptor.
2293
- * @param offset The part of the buffer to be written. If not supplied, defaults to `0`.
2294
- * @param length The number of bytes to write. If not supplied, defaults to `buffer.length - offset`.
2295
- * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
2296
- */
2297
- function __promisify__<TBuffer extends NodeJS.ArrayBufferView>(
2298
- fd: number,
2299
- buffer?: TBuffer,
2300
- offset?: number,
2301
- length?: number,
2302
- position?: number | null
2303
- ): Promise<{
2304
- bytesWritten: number;
2305
- buffer: TBuffer;
2306
- }>;
2307
- /**
2308
- * Asynchronously writes `string` to the file referenced by the supplied file descriptor.
2309
- * @param fd A file descriptor.
2310
- * @param string A string to write.
2311
- * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
2312
- * @param encoding The expected string encoding.
2313
- */
2314
- function __promisify__(
2315
- fd: number,
2316
- string: string,
2317
- position?: number | null,
2318
- encoding?: BufferEncoding | null
2319
- ): Promise<{
2320
- bytesWritten: number;
2321
- buffer: string;
2322
- }>;
2323
- }
2324
- /**
2325
- * For detailed information, see the documentation of the asynchronous version of
2326
- * this API: {@link write}.
2327
- * @since v0.1.21
2328
- * @return The number of bytes written.
2329
- */
2330
- export function writeSync(fd: number, buffer: NodeJS.ArrayBufferView, offset?: number | null, length?: number | null, position?: number | null): number;
2331
- /**
2332
- * Synchronously writes `string` to the file referenced by the supplied file descriptor, returning the number of bytes written.
2333
- * @param fd A file descriptor.
2334
- * @param string A string to write.
2335
- * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
2336
- * @param encoding The expected string encoding.
2337
- */
2338
- export function writeSync(fd: number, string: string, position?: number | null, encoding?: BufferEncoding | null): number;
2339
- export type ReadPosition = number | bigint;
2340
- export interface ReadSyncOptions {
2341
- /**
2342
- * @default 0
2343
- */
2344
- offset?: number | undefined;
2345
- /**
2346
- * @default `length of buffer`
2347
- */
2348
- length?: number | undefined;
2349
- /**
2350
- * @default null
2351
- */
2352
- position?: ReadPosition | null | undefined;
2353
- }
2354
- export interface ReadAsyncOptions<TBuffer extends NodeJS.ArrayBufferView> extends ReadSyncOptions {
2355
- buffer?: TBuffer;
2356
- }
2357
- /**
2358
- * Read data from the file specified by `fd`.
2359
- *
2360
- * The callback is given the three arguments, `(err, bytesRead, buffer)`.
2361
- *
2362
- * If the file is not modified concurrently, the end-of-file is reached when the
2363
- * number of bytes read is zero.
2364
- *
2365
- * If this method is invoked as its `util.promisify()` ed version, it returns
2366
- * a promise for an `Object` with `bytesRead` and `buffer` properties.
2367
- * @since v0.0.2
2368
- * @param buffer The buffer that the data will be written to.
2369
- * @param offset The position in `buffer` to write the data to.
2370
- * @param length The number of bytes to read.
2371
- * @param position Specifies where to begin reading from in the file. If `position` is `null` or `-1 `, data will be read from the current file position, and the file position will be updated. If
2372
- * `position` is an integer, the file position will be unchanged.
2373
- */
2374
- export function read<TBuffer extends NodeJS.ArrayBufferView>(
2375
- fd: number,
2376
- buffer: TBuffer,
2377
- offset: number,
2378
- length: number,
2379
- position: ReadPosition | null,
2380
- callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: TBuffer) => void
2381
- ): void;
2382
- /**
2383
- * Similar to the above `fs.read` function, this version takes an optional `options` object.
2384
- * If not otherwise specified in an `options` object,
2385
- * `buffer` defaults to `Buffer.alloc(16384)`,
2386
- * `offset` defaults to `0`,
2387
- * `length` defaults to `buffer.byteLength`, `- offset` as of Node 17.6.0
2388
- * `position` defaults to `null`
2389
- * @since v12.17.0, 13.11.0
2390
- */
2391
- export function read<TBuffer extends NodeJS.ArrayBufferView>(
2392
- fd: number,
2393
- options: ReadAsyncOptions<TBuffer>,
2394
- callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: TBuffer) => void
2395
- ): void;
2396
- export function read(fd: number, callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: NodeJS.ArrayBufferView) => void): void;
2397
- export namespace read {
2398
- /**
2399
- * @param fd A file descriptor.
2400
- * @param buffer The buffer that the data will be written to.
2401
- * @param offset The offset in the buffer at which to start writing.
2402
- * @param length The number of bytes to read.
2403
- * @param position The offset from the beginning of the file from which data should be read. If `null`, data will be read from the current position.
2404
- */
2405
- function __promisify__<TBuffer extends NodeJS.ArrayBufferView>(
2406
- fd: number,
2407
- buffer: TBuffer,
2408
- offset: number,
2409
- length: number,
2410
- position: number | null
2411
- ): Promise<{
2412
- bytesRead: number;
2413
- buffer: TBuffer;
2414
- }>;
2415
- function __promisify__<TBuffer extends NodeJS.ArrayBufferView>(
2416
- fd: number,
2417
- options: ReadAsyncOptions<TBuffer>
2418
- ): Promise<{
2419
- bytesRead: number;
2420
- buffer: TBuffer;
2421
- }>;
2422
- function __promisify__(fd: number): Promise<{
2423
- bytesRead: number;
2424
- buffer: NodeJS.ArrayBufferView;
2425
- }>;
2426
- }
2427
- /**
2428
- * Returns the number of `bytesRead`.
2429
- *
2430
- * For detailed information, see the documentation of the asynchronous version of
2431
- * this API: {@link read}.
2432
- * @since v0.1.21
2433
- */
2434
- export function readSync(fd: number, buffer: NodeJS.ArrayBufferView, offset: number, length: number, position: ReadPosition | null): number;
2435
- /**
2436
- * Similar to the above `fs.readSync` function, this version takes an optional `options` object.
2437
- * If no `options` object is specified, it will default with the above values.
2438
- */
2439
- export function readSync(fd: number, buffer: NodeJS.ArrayBufferView, opts?: ReadSyncOptions): number;
2440
- /**
2441
- * Asynchronously reads the entire contents of a file.
2442
- *
2443
- * ```js
2444
- * import { readFile } from 'fs';
2445
- *
2446
- * readFile('/etc/passwd', (err, data) => {
2447
- * if (err) throw err;
2448
- * console.log(data);
2449
- * });
2450
- * ```
2451
- *
2452
- * The callback is passed two arguments `(err, data)`, where `data` is the
2453
- * contents of the file.
2454
- *
2455
- * If no encoding is specified, then the raw buffer is returned.
2456
- *
2457
- * If `options` is a string, then it specifies the encoding:
2458
- *
2459
- * ```js
2460
- * import { readFile } from 'fs';
2461
- *
2462
- * readFile('/etc/passwd', 'utf8', callback);
2463
- * ```
2464
- *
2465
- * When the path is a directory, the behavior of `fs.readFile()` and {@link readFileSync} is platform-specific. On macOS, Linux, and Windows, an
2466
- * error will be returned. On FreeBSD, a representation of the directory's contents
2467
- * will be returned.
2468
- *
2469
- * ```js
2470
- * import { readFile } from 'fs';
2471
- *
2472
- * // macOS, Linux, and Windows
2473
- * readFile('<directory>', (err, data) => {
2474
- * // => [Error: EISDIR: illegal operation on a directory, read <directory>]
2475
- * });
2476
- *
2477
- * // FreeBSD
2478
- * readFile('<directory>', (err, data) => {
2479
- * // => null, <data>
2480
- * });
2481
- * ```
2482
- *
2483
- * It is possible to abort an ongoing request using an `AbortSignal`. If a
2484
- * request is aborted the callback is called with an `AbortError`:
2485
- *
2486
- * ```js
2487
- * import { readFile } from 'fs';
2488
- *
2489
- * const controller = new AbortController();
2490
- * const signal = controller.signal;
2491
- * readFile(fileInfo[0].name, { signal }, (err, buf) => {
2492
- * // ...
2493
- * });
2494
- * // When you want to abort the request
2495
- * controller.abort();
2496
- * ```
2497
- *
2498
- * The `fs.readFile()` function buffers the entire file. To minimize memory costs,
2499
- * when possible prefer streaming via `fs.createReadStream()`.
2500
- *
2501
- * Aborting an ongoing request does not abort individual operating
2502
- * system requests but rather the internal buffering `fs.readFile` performs.
2503
- * @since v0.1.29
2504
- * @param path filename or file descriptor
2505
- */
2506
- export function readFile(
2507
- path: PathOrFileDescriptor,
2508
- options:
2509
- | ({
2510
- encoding?: null | undefined;
2511
- flag?: string | undefined;
2512
- } & Abortable)
2513
- | undefined
2514
- | null,
2515
- callback: (err: NodeJS.ErrnoException | null, data: Buffer) => void
2516
- ): void;
2517
- /**
2518
- * Asynchronously reads the entire contents of a file.
2519
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2520
- * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
2521
- * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
2522
- * If a flag is not provided, it defaults to `'r'`.
2523
- */
2524
- export function readFile(
2525
- path: PathOrFileDescriptor,
2526
- options:
2527
- | ({
2528
- encoding: BufferEncoding;
2529
- flag?: string | undefined;
2530
- } & Abortable)
2531
- | BufferEncoding,
2532
- callback: (err: NodeJS.ErrnoException | null, data: string) => void
2533
- ): void;
2534
- /**
2535
- * Asynchronously reads the entire contents of a file.
2536
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2537
- * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
2538
- * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
2539
- * If a flag is not provided, it defaults to `'r'`.
2540
- */
2541
- export function readFile(
2542
- path: PathOrFileDescriptor,
2543
- options:
2544
- | (ObjectEncodingOptions & {
2545
- flag?: string | undefined;
2546
- } & Abortable)
2547
- | BufferEncoding
2548
- | undefined
2549
- | null,
2550
- callback: (err: NodeJS.ErrnoException | null, data: string | Buffer) => void
2551
- ): void;
2552
- /**
2553
- * Asynchronously reads the entire contents of a file.
2554
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2555
- * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
2556
- */
2557
- export function readFile(path: PathOrFileDescriptor, callback: (err: NodeJS.ErrnoException | null, data: Buffer) => void): void;
2558
- export namespace readFile {
2559
- /**
2560
- * Asynchronously reads the entire contents of a file.
2561
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2562
- * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
2563
- * @param options An object that may contain an optional flag.
2564
- * If a flag is not provided, it defaults to `'r'`.
2565
- */
2566
- function __promisify__(
2567
- path: PathOrFileDescriptor,
2568
- options?: {
2569
- encoding?: null | undefined;
2570
- flag?: string | undefined;
2571
- } | null
2572
- ): Promise<Buffer>;
2573
- /**
2574
- * Asynchronously reads the entire contents of a file.
2575
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2576
- * URL support is _experimental_.
2577
- * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
2578
- * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
2579
- * If a flag is not provided, it defaults to `'r'`.
2580
- */
2581
- function __promisify__(
2582
- path: PathOrFileDescriptor,
2583
- options:
2584
- | {
2585
- encoding: BufferEncoding;
2586
- flag?: string | undefined;
2587
- }
2588
- | BufferEncoding
2589
- ): Promise<string>;
2590
- /**
2591
- * Asynchronously reads the entire contents of a file.
2592
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2593
- * URL support is _experimental_.
2594
- * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
2595
- * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
2596
- * If a flag is not provided, it defaults to `'r'`.
2597
- */
2598
- function __promisify__(
2599
- path: PathOrFileDescriptor,
2600
- options?:
2601
- | (ObjectEncodingOptions & {
2602
- flag?: string | undefined;
2603
- })
2604
- | BufferEncoding
2605
- | null
2606
- ): Promise<string | Buffer>;
2607
- }
2608
- /**
2609
- * Returns the contents of the `path`.
2610
- *
2611
- * For detailed information, see the documentation of the asynchronous version of
2612
- * this API: {@link readFile}.
2613
- *
2614
- * If the `encoding` option is specified then this function returns a
2615
- * string. Otherwise it returns a buffer.
2616
- *
2617
- * Similar to {@link readFile}, when the path is a directory, the behavior of`fs.readFileSync()` is platform-specific.
2618
- *
2619
- * ```js
2620
- * import { readFileSync } from 'fs';
2621
- *
2622
- * // macOS, Linux, and Windows
2623
- * readFileSync('<directory>');
2624
- * // => [Error: EISDIR: illegal operation on a directory, read <directory>]
2625
- *
2626
- * // FreeBSD
2627
- * readFileSync('<directory>'); // => <data>
2628
- * ```
2629
- * @since v0.1.8
2630
- * @param path filename or file descriptor
2631
- */
2632
- export function readFileSync(
2633
- path: PathOrFileDescriptor,
2634
- options?: {
2635
- encoding?: null | undefined;
2636
- flag?: string | undefined;
2637
- } | null
2638
- ): Buffer;
2639
- /**
2640
- * Synchronously reads the entire contents of a file.
2641
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2642
- * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
2643
- * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
2644
- * If a flag is not provided, it defaults to `'r'`.
2645
- */
2646
- export function readFileSync(
2647
- path: PathOrFileDescriptor,
2648
- options:
2649
- | {
2650
- encoding: BufferEncoding;
2651
- flag?: string | undefined;
2652
- }
2653
- | BufferEncoding
2654
- ): string;
2655
- /**
2656
- * Synchronously reads the entire contents of a file.
2657
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2658
- * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
2659
- * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
2660
- * If a flag is not provided, it defaults to `'r'`.
2661
- */
2662
- export function readFileSync(
2663
- path: PathOrFileDescriptor,
2664
- options?:
2665
- | (ObjectEncodingOptions & {
2666
- flag?: string | undefined;
2667
- })
2668
- | BufferEncoding
2669
- | null
2670
- ): string | Buffer;
2671
- export type WriteFileOptions =
2672
- | (ObjectEncodingOptions &
2673
- Abortable & {
2674
- mode?: Mode | undefined;
2675
- flag?: string | undefined;
2676
- })
2677
- | BufferEncoding
2678
- | null;
2679
- /**
2680
- * When `file` is a filename, asynchronously writes data to the file, replacing the
2681
- * file if it already exists. `data` can be a string or a buffer.
2682
- *
2683
- * When `file` is a file descriptor, the behavior is similar to calling`fs.write()` directly (which is recommended). See the notes below on using
2684
- * a file descriptor.
2685
- *
2686
- * The `encoding` option is ignored if `data` is a buffer.
2687
- *
2688
- * The `mode` option only affects the newly created file. See {@link open} for more details.
2689
- *
2690
- * ```js
2691
- * import { writeFile } from 'fs';
2692
- * import { Buffer } from 'buffer';
2693
- *
2694
- * const data = new Uint8Array(Buffer.from('Hello Node.js'));
2695
- * writeFile('message.txt', data, (err) => {
2696
- * if (err) throw err;
2697
- * console.log('The file has been saved!');
2698
- * });
2699
- * ```
2700
- *
2701
- * If `options` is a string, then it specifies the encoding:
2702
- *
2703
- * ```js
2704
- * import { writeFile } from 'fs';
2705
- *
2706
- * writeFile('message.txt', 'Hello Node.js', 'utf8', callback);
2707
- * ```
2708
- *
2709
- * It is unsafe to use `fs.writeFile()` multiple times on the same file without
2710
- * waiting for the callback. For this scenario, {@link createWriteStream} is
2711
- * recommended.
2712
- *
2713
- * Similarly to `fs.readFile` \- `fs.writeFile` is a convenience method that
2714
- * performs multiple `write` calls internally to write the buffer passed to it.
2715
- * For performance sensitive code consider using {@link createWriteStream}.
2716
- *
2717
- * It is possible to use an `AbortSignal` to cancel an `fs.writeFile()`.
2718
- * Cancelation is "best effort", and some amount of data is likely still
2719
- * to be written.
2720
- *
2721
- * ```js
2722
- * import { writeFile } from 'fs';
2723
- * import { Buffer } from 'buffer';
2724
- *
2725
- * const controller = new AbortController();
2726
- * const { signal } = controller;
2727
- * const data = new Uint8Array(Buffer.from('Hello Node.js'));
2728
- * writeFile('message.txt', data, { signal }, (err) => {
2729
- * // When a request is aborted - the callback is called with an AbortError
2730
- * });
2731
- * // When the request should be aborted
2732
- * controller.abort();
2733
- * ```
2734
- *
2735
- * Aborting an ongoing request does not abort individual operating
2736
- * system requests but rather the internal buffering `fs.writeFile` performs.
2737
- * @since v0.1.29
2738
- * @param file filename or file descriptor
2739
- */
2740
- export function writeFile(file: PathOrFileDescriptor, data: string | NodeJS.ArrayBufferView, options: WriteFileOptions, callback: NoParamCallback): void;
2741
- /**
2742
- * Asynchronously writes data to a file, replacing the file if it already exists.
2743
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2744
- * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
2745
- * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
2746
- */
2747
- export function writeFile(path: PathOrFileDescriptor, data: string | NodeJS.ArrayBufferView, callback: NoParamCallback): void;
2748
- export namespace writeFile {
2749
- /**
2750
- * Asynchronously writes data to a file, replacing the file if it already exists.
2751
- * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
2752
- * URL support is _experimental_.
2753
- * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
2754
- * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
2755
- * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
2756
- * If `encoding` is not supplied, the default of `'utf8'` is used.
2757
- * If `mode` is not supplied, the default of `0o666` is used.
2758
- * If `mode` is a string, it is parsed as an octal integer.
2759
- * If `flag` is not supplied, the default of `'w'` is used.
2760
- */
2761
- function __promisify__(path: PathOrFileDescriptor, data: string | NodeJS.ArrayBufferView, options?: WriteFileOptions): Promise<void>;
2762
- }
2763
- /**
2764
- * Returns `undefined`.
2765
- *
2766
- * The `mode` option only affects the newly created file. See {@link open} for more details.
2767
- *
2768
- * For detailed information, see the documentation of the asynchronous version of
2769
- * this API: {@link writeFile}.
2770
- * @since v0.1.29
2771
- * @param file filename or file descriptor
2772
- */
2773
- export function writeFileSync(file: PathOrFileDescriptor, data: string | NodeJS.ArrayBufferView, options?: WriteFileOptions): void;
2774
- /**
2775
- * Asynchronously append data to a file, creating the file if it does not yet
2776
- * exist. `data` can be a string or a `Buffer`.
2777
- *
2778
- * The `mode` option only affects the newly created file. See {@link open} for more details.
2779
- *
2780
- * ```js
2781
- * import { appendFile } from 'fs';
2782
- *
2783
- * appendFile('message.txt', 'data to append', (err) => {
2784
- * if (err) throw err;
2785
- * console.log('The "data to append" was appended to file!');
2786
- * });
2787
- * ```
2788
- *
2789
- * If `options` is a string, then it specifies the encoding:
2790
- *
2791
- * ```js
2792
- * import { appendFile } from 'fs';
2793
- *
2794
- * appendFile('message.txt', 'data to append', 'utf8', callback);
2795
- * ```
2796
- *
2797
- * The `path` may be specified as a numeric file descriptor that has been opened
2798
- * for appending (using `fs.open()` or `fs.openSync()`). The file descriptor will
2799
- * not be closed automatically.
2800
- *
2801
- * ```js
2802
- * import { open, close, appendFile } from 'fs';
2803
- *
2804
- * function closeFd(fd) {
2805
- * close(fd, (err) => {
2806
- * if (err) throw err;
2807
- * });
2808
- * }
2809
- *
2810
- * open('message.txt', 'a', (err, fd) => {
2811
- * if (err) throw err;
2812
- *
2813
- * try {
2814
- * appendFile(fd, 'data to append', 'utf8', (err) => {
2815
- * closeFd(fd);
2816
- * if (err) throw err;
2817
- * });
2818
- * } catch (err) {
2819
- * closeFd(fd);
2820
- * throw err;
2821
- * }
2822
- * });
2823
- * ```
2824
- * @since v0.6.7
2825
- * @param path filename or file descriptor
2826
- */
2827
- export function appendFile(path: PathOrFileDescriptor, data: string | Uint8Array, options: WriteFileOptions, callback: NoParamCallback): void;
2828
- /**
2829
- * Asynchronously append data to a file, creating the file if it does not exist.
2830
- * @param file A path to a file. If a URL is provided, it must use the `file:` protocol.
2831
- * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
2832
- * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
2833
- */
2834
- export function appendFile(file: PathOrFileDescriptor, data: string | Uint8Array, callback: NoParamCallback): void;
2835
- export namespace appendFile {
2836
- /**
2837
- * Asynchronously append data to a file, creating the file if it does not exist.
2838
- * @param file A path to a file. If a URL is provided, it must use the `file:` protocol.
2839
- * URL support is _experimental_.
2840
- * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
2841
- * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
2842
- * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
2843
- * If `encoding` is not supplied, the default of `'utf8'` is used.
2844
- * If `mode` is not supplied, the default of `0o666` is used.
2845
- * If `mode` is a string, it is parsed as an octal integer.
2846
- * If `flag` is not supplied, the default of `'a'` is used.
2847
- */
2848
- function __promisify__(file: PathOrFileDescriptor, data: string | Uint8Array, options?: WriteFileOptions): Promise<void>;
2849
- }
2850
- /**
2851
- * Synchronously append data to a file, creating the file if it does not yet
2852
- * exist. `data` can be a string or a `Buffer`.
2853
- *
2854
- * The `mode` option only affects the newly created file. See {@link open} for more details.
2855
- *
2856
- * ```js
2857
- * import { appendFileSync } from 'fs';
2858
- *
2859
- * try {
2860
- * appendFileSync('message.txt', 'data to append');
2861
- * console.log('The "data to append" was appended to file!');
2862
- * } catch (err) {
2863
- * // Handle the error
2864
- * }
2865
- * ```
2866
- *
2867
- * If `options` is a string, then it specifies the encoding:
2868
- *
2869
- * ```js
2870
- * import { appendFileSync } from 'fs';
2871
- *
2872
- * appendFileSync('message.txt', 'data to append', 'utf8');
2873
- * ```
2874
- *
2875
- * The `path` may be specified as a numeric file descriptor that has been opened
2876
- * for appending (using `fs.open()` or `fs.openSync()`). The file descriptor will
2877
- * not be closed automatically.
2878
- *
2879
- * ```js
2880
- * import { openSync, closeSync, appendFileSync } from 'fs';
2881
- *
2882
- * let fd;
2883
- *
2884
- * try {
2885
- * fd = openSync('message.txt', 'a');
2886
- * appendFileSync(fd, 'data to append', 'utf8');
2887
- * } catch (err) {
2888
- * // Handle the error
2889
- * } finally {
2890
- * if (fd !== undefined)
2891
- * closeSync(fd);
2892
- * }
2893
- * ```
2894
- * @since v0.6.7
2895
- * @param path filename or file descriptor
2896
- */
2897
- export function appendFileSync(path: PathOrFileDescriptor, data: string | Uint8Array, options?: WriteFileOptions): void;
2898
- /**
2899
- * Watch for changes on `filename`. The callback `listener` will be called each
2900
- * time the file is accessed.
2901
- *
2902
- * The `options` argument may be omitted. If provided, it should be an object. The`options` object may contain a boolean named `persistent` that indicates
2903
- * whether the process should continue to run as long as files are being watched.
2904
- * The `options` object may specify an `interval` property indicating how often the
2905
- * target should be polled in milliseconds.
2906
- *
2907
- * The `listener` gets two arguments the current stat object and the previous
2908
- * stat object:
2909
- *
2910
- * ```js
2911
- * import { watchFile } from 'fs';
2912
- *
2913
- * watchFile('message.text', (curr, prev) => {
2914
- * console.log(`the current mtime is: ${curr.mtime}`);
2915
- * console.log(`the previous mtime was: ${prev.mtime}`);
2916
- * });
2917
- * ```
2918
- *
2919
- * These stat objects are instances of `fs.Stat`. If the `bigint` option is `true`,
2920
- * the numeric values in these objects are specified as `BigInt`s.
2921
- *
2922
- * To be notified when the file was modified, not just accessed, it is necessary
2923
- * to compare `curr.mtimeMs` and `prev.mtimeMs`.
2924
- *
2925
- * When an `fs.watchFile` operation results in an `ENOENT` error, it
2926
- * will invoke the listener once, with all the fields zeroed (or, for dates, the
2927
- * Unix Epoch). If the file is created later on, the listener will be called
2928
- * again, with the latest stat objects. This is a change in functionality since
2929
- * v0.10.
2930
- *
2931
- * Using {@link watch} is more efficient than `fs.watchFile` and`fs.unwatchFile`. `fs.watch` should be used instead of `fs.watchFile` and`fs.unwatchFile` when possible.
2932
- *
2933
- * When a file being watched by `fs.watchFile()` disappears and reappears,
2934
- * then the contents of `previous` in the second callback event (the file's
2935
- * reappearance) will be the same as the contents of `previous` in the first
2936
- * callback event (its disappearance).
2937
- *
2938
- * This happens when:
2939
- *
2940
- * * the file is deleted, followed by a restore
2941
- * * the file is renamed and then renamed a second time back to its original name
2942
- * @since v0.1.31
2943
- */
2944
- export interface WatchFileOptions {
2945
- bigint?: boolean | undefined;
2946
- persistent?: boolean | undefined;
2947
- interval?: number | undefined;
2948
- }
2949
- /**
2950
- * Watch for changes on `filename`. The callback `listener` will be called each
2951
- * time the file is accessed.
2952
- *
2953
- * The `options` argument may be omitted. If provided, it should be an object. The`options` object may contain a boolean named `persistent` that indicates
2954
- * whether the process should continue to run as long as files are being watched.
2955
- * The `options` object may specify an `interval` property indicating how often the
2956
- * target should be polled in milliseconds.
2957
- *
2958
- * The `listener` gets two arguments the current stat object and the previous
2959
- * stat object:
2960
- *
2961
- * ```js
2962
- * import { watchFile } from 'fs';
2963
- *
2964
- * watchFile('message.text', (curr, prev) => {
2965
- * console.log(`the current mtime is: ${curr.mtime}`);
2966
- * console.log(`the previous mtime was: ${prev.mtime}`);
2967
- * });
2968
- * ```
2969
- *
2970
- * These stat objects are instances of `fs.Stat`. If the `bigint` option is `true`,
2971
- * the numeric values in these objects are specified as `BigInt`s.
2972
- *
2973
- * To be notified when the file was modified, not just accessed, it is necessary
2974
- * to compare `curr.mtimeMs` and `prev.mtimeMs`.
2975
- *
2976
- * When an `fs.watchFile` operation results in an `ENOENT` error, it
2977
- * will invoke the listener once, with all the fields zeroed (or, for dates, the
2978
- * Unix Epoch). If the file is created later on, the listener will be called
2979
- * again, with the latest stat objects. This is a change in functionality since
2980
- * v0.10.
2981
- *
2982
- * Using {@link watch} is more efficient than `fs.watchFile` and`fs.unwatchFile`. `fs.watch` should be used instead of `fs.watchFile` and`fs.unwatchFile` when possible.
2983
- *
2984
- * When a file being watched by `fs.watchFile()` disappears and reappears,
2985
- * then the contents of `previous` in the second callback event (the file's
2986
- * reappearance) will be the same as the contents of `previous` in the first
2987
- * callback event (its disappearance).
2988
- *
2989
- * This happens when:
2990
- *
2991
- * * the file is deleted, followed by a restore
2992
- * * the file is renamed and then renamed a second time back to its original name
2993
- * @since v0.1.31
2994
- */
2995
- export function watchFile(
2996
- filename: PathLike,
2997
- options:
2998
- | (WatchFileOptions & {
2999
- bigint?: false | undefined;
3000
- })
3001
- | undefined,
3002
- listener: StatsListener
3003
- ): StatWatcher;
3004
- export function watchFile(
3005
- filename: PathLike,
3006
- options:
3007
- | (WatchFileOptions & {
3008
- bigint: true;
3009
- })
3010
- | undefined,
3011
- listener: BigIntStatsListener
3012
- ): StatWatcher;
3013
- /**
3014
- * Watch for changes on `filename`. The callback `listener` will be called each time the file is accessed.
3015
- * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
3016
- * @param listener The callback listener will be called each time the file is accessed.
3017
- */
3018
- export function watchFile(filename: PathLike, listener: StatsListener): StatWatcher;
3019
- /**
3020
- * Stop watching for changes on `filename`. If `listener` is specified, only that
3021
- * particular listener is removed. Otherwise, _all_ listeners are removed,
3022
- * effectively stopping watching of `filename`.
3023
- *
3024
- * Calling `fs.unwatchFile()` with a filename that is not being watched is a
3025
- * no-op, not an error.
3026
- *
3027
- * Using {@link watch} is more efficient than `fs.watchFile()` and`fs.unwatchFile()`. `fs.watch()` should be used instead of `fs.watchFile()`and `fs.unwatchFile()` when possible.
3028
- * @since v0.1.31
3029
- * @param listener Optional, a listener previously attached using `fs.watchFile()`
3030
- */
3031
- export function unwatchFile(filename: PathLike, listener?: StatsListener): void;
3032
- export function unwatchFile(filename: PathLike, listener?: BigIntStatsListener): void;
3033
- export interface WatchOptions extends Abortable {
3034
- encoding?: BufferEncoding | 'buffer' | undefined;
3035
- persistent?: boolean | undefined;
3036
- recursive?: boolean | undefined;
3037
- }
3038
- export type WatchEventType = 'rename' | 'change';
3039
- export type WatchListener<T> = (event: WatchEventType, filename: T) => void;
3040
- export type StatsListener = (curr: Stats, prev: Stats) => void;
3041
- export type BigIntStatsListener = (curr: BigIntStats, prev: BigIntStats) => void;
3042
- /**
3043
- * Watch for changes on `filename`, where `filename` is either a file or a
3044
- * directory.
3045
- *
3046
- * The second argument is optional. If `options` is provided as a string, it
3047
- * specifies the `encoding`. Otherwise `options` should be passed as an object.
3048
- *
3049
- * The listener callback gets two arguments `(eventType, filename)`. `eventType`is either `'rename'` or `'change'`, and `filename` is the name of the file
3050
- * which triggered the event.
3051
- *
3052
- * On most platforms, `'rename'` is emitted whenever a filename appears or
3053
- * disappears in the directory.
3054
- *
3055
- * The listener callback is attached to the `'change'` event fired by `fs.FSWatcher`, but it is not the same thing as the `'change'` value of`eventType`.
3056
- *
3057
- * If a `signal` is passed, aborting the corresponding AbortController will close
3058
- * the returned `fs.FSWatcher`.
3059
- * @since v0.5.10
3060
- * @param listener
3061
- */
3062
- export function watch(
3063
- filename: PathLike,
3064
- options:
3065
- | (WatchOptions & {
3066
- encoding: 'buffer';
3067
- })
3068
- | 'buffer',
3069
- listener?: WatchListener<Buffer>
3070
- ): FSWatcher;
3071
- /**
3072
- * Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
3073
- * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
3074
- * @param options Either the encoding for the filename provided to the listener, or an object optionally specifying encoding, persistent, and recursive options.
3075
- * If `encoding` is not supplied, the default of `'utf8'` is used.
3076
- * If `persistent` is not supplied, the default of `true` is used.
3077
- * If `recursive` is not supplied, the default of `false` is used.
3078
- */
3079
- export function watch(filename: PathLike, options?: WatchOptions | BufferEncoding | null, listener?: WatchListener<string>): FSWatcher;
3080
- /**
3081
- * Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
3082
- * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
3083
- * @param options Either the encoding for the filename provided to the listener, or an object optionally specifying encoding, persistent, and recursive options.
3084
- * If `encoding` is not supplied, the default of `'utf8'` is used.
3085
- * If `persistent` is not supplied, the default of `true` is used.
3086
- * If `recursive` is not supplied, the default of `false` is used.
3087
- */
3088
- export function watch(filename: PathLike, options: WatchOptions | string, listener?: WatchListener<string | Buffer>): FSWatcher;
3089
- /**
3090
- * Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
3091
- * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
3092
- */
3093
- export function watch(filename: PathLike, listener?: WatchListener<string>): FSWatcher;
3094
- /**
3095
- * Test whether or not the given path exists by checking with the file system.
3096
- * Then call the `callback` argument with either true or false:
3097
- *
3098
- * ```js
3099
- * import { exists } from 'fs';
3100
- *
3101
- * exists('/etc/passwd', (e) => {
3102
- * console.log(e ? 'it exists' : 'no passwd!');
3103
- * });
3104
- * ```
3105
- *
3106
- * **The parameters for this callback are not consistent with other Node.js**
3107
- * **callbacks.** Normally, the first parameter to a Node.js callback is an `err`parameter, optionally followed by other parameters. The `fs.exists()` callback
3108
- * has only one boolean parameter. This is one reason `fs.access()` is recommended
3109
- * instead of `fs.exists()`.
3110
- *
3111
- * Using `fs.exists()` to check for the existence of a file before calling`fs.open()`, `fs.readFile()` or `fs.writeFile()` is not recommended. Doing
3112
- * so introduces a race condition, since other processes may change the file's
3113
- * state between the two calls. Instead, user code should open/read/write the
3114
- * file directly and handle the error raised if the file does not exist.
3115
- *
3116
- * **write (NOT RECOMMENDED)**
3117
- *
3118
- * ```js
3119
- * import { exists, open, close } from 'fs';
3120
- *
3121
- * exists('myfile', (e) => {
3122
- * if (e) {
3123
- * console.error('myfile already exists');
3124
- * } else {
3125
- * open('myfile', 'wx', (err, fd) => {
3126
- * if (err) throw err;
3127
- *
3128
- * try {
3129
- * writeMyData(fd);
3130
- * } finally {
3131
- * close(fd, (err) => {
3132
- * if (err) throw err;
3133
- * });
3134
- * }
3135
- * });
3136
- * }
3137
- * });
3138
- * ```
3139
- *
3140
- * **write (RECOMMENDED)**
3141
- *
3142
- * ```js
3143
- * import { open, close } from 'fs';
3144
- * open('myfile', 'wx', (err, fd) => {
3145
- * if (err) {
3146
- * if (err.code === 'EEXIST') {
3147
- * console.error('myfile already exists');
3148
- * return;
3149
- * }
3150
- *
3151
- * throw err;
3152
- * }
3153
- *
3154
- * try {
3155
- * writeMyData(fd);
3156
- * } finally {
3157
- * close(fd, (err) => {
3158
- * if (err) throw err;
3159
- * });
3160
- * }
3161
- * });
3162
- * ```
3163
- *
3164
- * **read (NOT RECOMMENDED)**
3165
- *
3166
- * ```js
3167
- * import { open, close, exists } from 'fs';
3168
- *
3169
- * exists('myfile', (e) => {
3170
- * if (e) {
3171
- * open('myfile', 'r', (err, fd) => {
3172
- * if (err) throw err;
3173
- *
3174
- * try {
3175
- * readMyData(fd);
3176
- * } finally {
3177
- * close(fd, (err) => {
3178
- * if (err) throw err;
3179
- * });
3180
- * }
3181
- * });
3182
- * } else {
3183
- * console.error('myfile does not exist');
3184
- * }
3185
- * });
3186
- * ```
3187
- *
3188
- * **read (RECOMMENDED)**
3189
- *
3190
- * ```js
3191
- * import { open, close } from 'fs';
3192
- *
3193
- * open('myfile', 'r', (err, fd) => {
3194
- * if (err) {
3195
- * if (err.code === 'ENOENT') {
3196
- * console.error('myfile does not exist');
3197
- * return;
3198
- * }
3199
- *
3200
- * throw err;
3201
- * }
3202
- *
3203
- * try {
3204
- * readMyData(fd);
3205
- * } finally {
3206
- * close(fd, (err) => {
3207
- * if (err) throw err;
3208
- * });
3209
- * }
3210
- * });
3211
- * ```
3212
- *
3213
- * The "not recommended" examples above check for existence and then use the
3214
- * file; the "recommended" examples are better because they use the file directly
3215
- * and handle the error, if any.
3216
- *
3217
- * In general, check for the existence of a file only if the file won’t be
3218
- * used directly, for example when its existence is a signal from another
3219
- * process.
3220
- * @since v0.0.2
3221
- * @deprecated Since v1.0.0 - Use {@link stat} or {@link access} instead.
3222
- */
3223
- export function exists(path: PathLike, callback: (exists: boolean) => void): void;
3224
- /** @deprecated */
3225
- export namespace exists {
3226
- /**
3227
- * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
3228
- * URL support is _experimental_.
3229
- */
3230
- function __promisify__(path: PathLike): Promise<boolean>;
3231
- }
3232
- /**
3233
- * Returns `true` if the path exists, `false` otherwise.
3234
- *
3235
- * For detailed information, see the documentation of the asynchronous version of
3236
- * this API: {@link exists}.
3237
- *
3238
- * `fs.exists()` is deprecated, but `fs.existsSync()` is not. The `callback`parameter to `fs.exists()` accepts parameters that are inconsistent with other
3239
- * Node.js callbacks. `fs.existsSync()` does not use a callback.
3240
- *
3241
- * ```js
3242
- * import { existsSync } from 'fs';
3243
- *
3244
- * if (existsSync('/etc/passwd'))
3245
- * console.log('The path exists.');
3246
- * ```
3247
- * @since v0.1.21
3248
- */
3249
- export function existsSync(path: PathLike): boolean;
3250
- export namespace constants {
3251
- // File Access Constants
3252
- /** Constant for fs.access(). File is visible to the calling process. */
3253
- const F_OK: number;
3254
- /** Constant for fs.access(). File can be read by the calling process. */
3255
- const R_OK: number;
3256
- /** Constant for fs.access(). File can be written by the calling process. */
3257
- const W_OK: number;
3258
- /** Constant for fs.access(). File can be executed by the calling process. */
3259
- const X_OK: number;
3260
- // File Copy Constants
3261
- /** Constant for fs.copyFile. Flag indicating the destination file should not be overwritten if it already exists. */
3262
- const COPYFILE_EXCL: number;
3263
- /**
3264
- * Constant for fs.copyFile. copy operation will attempt to create a copy-on-write reflink.
3265
- * If the underlying platform does not support copy-on-write, then a fallback copy mechanism is used.
3266
- */
3267
- const COPYFILE_FICLONE: number;
3268
- /**
3269
- * Constant for fs.copyFile. Copy operation will attempt to create a copy-on-write reflink.
3270
- * If the underlying platform does not support copy-on-write, then the operation will fail with an error.
3271
- */
3272
- const COPYFILE_FICLONE_FORCE: number;
3273
- // File Open Constants
3274
- /** Constant for fs.open(). Flag indicating to open a file for read-only access. */
3275
- const O_RDONLY: number;
3276
- /** Constant for fs.open(). Flag indicating to open a file for write-only access. */
3277
- const O_WRONLY: number;
3278
- /** Constant for fs.open(). Flag indicating to open a file for read-write access. */
3279
- const O_RDWR: number;
3280
- /** Constant for fs.open(). Flag indicating to create the file if it does not already exist. */
3281
- const O_CREAT: number;
3282
- /** Constant for fs.open(). Flag indicating that opening a file should fail if the O_CREAT flag is set and the file already exists. */
3283
- const O_EXCL: number;
3284
- /**
3285
- * Constant for fs.open(). Flag indicating that if path identifies a terminal device,
3286
- * opening the path shall not cause that terminal to become the controlling terminal for the process
3287
- * (if the process does not already have one).
3288
- */
3289
- const O_NOCTTY: number;
3290
- /** Constant for fs.open(). Flag indicating that if the file exists and is a regular file, and the file is opened successfully for write access, its length shall be truncated to zero. */
3291
- const O_TRUNC: number;
3292
- /** Constant for fs.open(). Flag indicating that data will be appended to the end of the file. */
3293
- const O_APPEND: number;
3294
- /** Constant for fs.open(). Flag indicating that the open should fail if the path is not a directory. */
3295
- const O_DIRECTORY: number;
3296
- /**
3297
- * constant for fs.open().
3298
- * Flag indicating reading accesses to the file system will no longer result in
3299
- * an update to the atime information associated with the file.
3300
- * This flag is available on Linux operating systems only.
3301
- */
3302
- const O_NOATIME: number;
3303
- /** Constant for fs.open(). Flag indicating that the open should fail if the path is a symbolic link. */
3304
- const O_NOFOLLOW: number;
3305
- /** Constant for fs.open(). Flag indicating that the file is opened for synchronous I/O. */
3306
- const O_SYNC: number;
3307
- /** Constant for fs.open(). Flag indicating that the file is opened for synchronous I/O with write operations waiting for data integrity. */
3308
- const O_DSYNC: number;
3309
- /** Constant for fs.open(). Flag indicating to open the symbolic link itself rather than the resource it is pointing to. */
3310
- const O_SYMLINK: number;
3311
- /** Constant for fs.open(). When set, an attempt will be made to minimize caching effects of file I/O. */
3312
- const O_DIRECT: number;
3313
- /** Constant for fs.open(). Flag indicating to open the file in nonblocking mode when possible. */
3314
- const O_NONBLOCK: number;
3315
- // File Type Constants
3316
- /** Constant for fs.Stats mode property for determining a file's type. Bit mask used to extract the file type code. */
3317
- const S_IFMT: number;
3318
- /** Constant for fs.Stats mode property for determining a file's type. File type constant for a regular file. */
3319
- const S_IFREG: number;
3320
- /** Constant for fs.Stats mode property for determining a file's type. File type constant for a directory. */
3321
- const S_IFDIR: number;
3322
- /** Constant for fs.Stats mode property for determining a file's type. File type constant for a character-oriented device file. */
3323
- const S_IFCHR: number;
3324
- /** Constant for fs.Stats mode property for determining a file's type. File type constant for a block-oriented device file. */
3325
- const S_IFBLK: number;
3326
- /** Constant for fs.Stats mode property for determining a file's type. File type constant for a FIFO/pipe. */
3327
- const S_IFIFO: number;
3328
- /** Constant for fs.Stats mode property for determining a file's type. File type constant for a symbolic link. */
3329
- const S_IFLNK: number;
3330
- /** Constant for fs.Stats mode property for determining a file's type. File type constant for a socket. */
3331
- const S_IFSOCK: number;
3332
- // File Mode Constants
3333
- /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable, writable and executable by owner. */
3334
- const S_IRWXU: number;
3335
- /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable by owner. */
3336
- const S_IRUSR: number;
3337
- /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating writable by owner. */
3338
- const S_IWUSR: number;
3339
- /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating executable by owner. */
3340
- const S_IXUSR: number;
3341
- /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable, writable and executable by group. */
3342
- const S_IRWXG: number;
3343
- /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable by group. */
3344
- const S_IRGRP: number;
3345
- /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating writable by group. */
3346
- const S_IWGRP: number;
3347
- /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating executable by group. */
3348
- const S_IXGRP: number;
3349
- /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable, writable and executable by others. */
3350
- const S_IRWXO: number;
3351
- /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable by others. */
3352
- const S_IROTH: number;
3353
- /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating writable by others. */
3354
- const S_IWOTH: number;
3355
- /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating executable by others. */
3356
- const S_IXOTH: number;
3357
- /**
3358
- * When set, a memory file mapping is used to access the file. This flag
3359
- * is available on Windows operating systems only. On other operating systems,
3360
- * this flag is ignored.
3361
- */
3362
- const UV_FS_O_FILEMAP: number;
3363
- }
3364
- /**
3365
- * Tests a user's permissions for the file or directory specified by `path`.
3366
- * The `mode` argument is an optional integer that specifies the accessibility
3367
- * checks to be performed. `mode` should be either the value `fs.constants.F_OK`or a mask consisting of the bitwise OR of any of `fs.constants.R_OK`,`fs.constants.W_OK`, and `fs.constants.X_OK`
3368
- * (e.g.`fs.constants.W_OK | fs.constants.R_OK`). Check `File access constants` for
3369
- * possible values of `mode`.
3370
- *
3371
- * The final argument, `callback`, is a callback function that is invoked with
3372
- * a possible error argument. If any of the accessibility checks fail, the error
3373
- * argument will be an `Error` object. The following examples check if`package.json` exists, and if it is readable or writable.
3374
- *
3375
- * ```js
3376
- * import { access, constants } from 'fs';
3377
- *
3378
- * const file = 'package.json';
3379
- *
3380
- * // Check if the file exists in the current directory.
3381
- * access(file, constants.F_OK, (err) => {
3382
- * console.log(`${file} ${err ? 'does not exist' : 'exists'}`);
3383
- * });
3384
- *
3385
- * // Check if the file is readable.
3386
- * access(file, constants.R_OK, (err) => {
3387
- * console.log(`${file} ${err ? 'is not readable' : 'is readable'}`);
3388
- * });
3389
- *
3390
- * // Check if the file is writable.
3391
- * access(file, constants.W_OK, (err) => {
3392
- * console.log(`${file} ${err ? 'is not writable' : 'is writable'}`);
3393
- * });
3394
- *
3395
- * // Check if the file is readable and writable.
3396
- * access(file, constants.R_OK | constants.W_OK, (err) => {
3397
- * console.log(`${file} ${err ? 'is not' : 'is'} readable and writable`);
3398
- * });
3399
- * ```
3400
- *
3401
- * Do not use `fs.access()` to check for the accessibility of a file before calling`fs.open()`, `fs.readFile()` or `fs.writeFile()`. Doing
3402
- * so introduces a race condition, since other processes may change the file's
3403
- * state between the two calls. Instead, user code should open/read/write the
3404
- * file directly and handle the error raised if the file is not accessible.
3405
- *
3406
- * **write (NOT RECOMMENDED)**
3407
- *
3408
- * ```js
3409
- * import { access, open, close } from 'fs';
3410
- *
3411
- * access('myfile', (err) => {
3412
- * if (!err) {
3413
- * console.error('myfile already exists');
3414
- * return;
3415
- * }
3416
- *
3417
- * open('myfile', 'wx', (err, fd) => {
3418
- * if (err) throw err;
3419
- *
3420
- * try {
3421
- * writeMyData(fd);
3422
- * } finally {
3423
- * close(fd, (err) => {
3424
- * if (err) throw err;
3425
- * });
3426
- * }
3427
- * });
3428
- * });
3429
- * ```
3430
- *
3431
- * **write (RECOMMENDED)**
3432
- *
3433
- * ```js
3434
- * import { open, close } from 'fs';
3435
- *
3436
- * open('myfile', 'wx', (err, fd) => {
3437
- * if (err) {
3438
- * if (err.code === 'EEXIST') {
3439
- * console.error('myfile already exists');
3440
- * return;
3441
- * }
3442
- *
3443
- * throw err;
3444
- * }
3445
- *
3446
- * try {
3447
- * writeMyData(fd);
3448
- * } finally {
3449
- * close(fd, (err) => {
3450
- * if (err) throw err;
3451
- * });
3452
- * }
3453
- * });
3454
- * ```
3455
- *
3456
- * **read (NOT RECOMMENDED)**
3457
- *
3458
- * ```js
3459
- * import { access, open, close } from 'fs';
3460
- * access('myfile', (err) => {
3461
- * if (err) {
3462
- * if (err.code === 'ENOENT') {
3463
- * console.error('myfile does not exist');
3464
- * return;
3465
- * }
3466
- *
3467
- * throw err;
3468
- * }
3469
- *
3470
- * open('myfile', 'r', (err, fd) => {
3471
- * if (err) throw err;
3472
- *
3473
- * try {
3474
- * readMyData(fd);
3475
- * } finally {
3476
- * close(fd, (err) => {
3477
- * if (err) throw err;
3478
- * });
3479
- * }
3480
- * });
3481
- * });
3482
- * ```
3483
- *
3484
- * **read (RECOMMENDED)**
3485
- *
3486
- * ```js
3487
- * import { open, close } from 'fs';
3488
- *
3489
- * open('myfile', 'r', (err, fd) => {
3490
- * if (err) {
3491
- * if (err.code === 'ENOENT') {
3492
- * console.error('myfile does not exist');
3493
- * return;
3494
- * }
3495
- *
3496
- * throw err;
3497
- * }
3498
- *
3499
- * try {
3500
- * readMyData(fd);
3501
- * } finally {
3502
- * close(fd, (err) => {
3503
- * if (err) throw err;
3504
- * });
3505
- * }
3506
- * });
3507
- * ```
3508
- *
3509
- * The "not recommended" examples above check for accessibility and then use the
3510
- * file; the "recommended" examples are better because they use the file directly
3511
- * and handle the error, if any.
3512
- *
3513
- * In general, check for the accessibility of a file only if the file will not be
3514
- * used directly, for example when its accessibility is a signal from another
3515
- * process.
3516
- *
3517
- * On Windows, access-control policies (ACLs) on a directory may limit access to
3518
- * a file or directory. The `fs.access()` function, however, does not check the
3519
- * ACL and therefore may report that a path is accessible even if the ACL restricts
3520
- * the user from reading or writing to it.
3521
- * @since v0.11.15
3522
- * @param [mode=fs.constants.F_OK]
3523
- */
3524
- export function access(path: PathLike, mode: number | undefined, callback: NoParamCallback): void;
3525
- /**
3526
- * Asynchronously tests a user's permissions for the file specified by path.
3527
- * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
3528
- */
3529
- export function access(path: PathLike, callback: NoParamCallback): void;
3530
- export namespace access {
3531
- /**
3532
- * Asynchronously tests a user's permissions for the file specified by path.
3533
- * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
3534
- * URL support is _experimental_.
3535
- */
3536
- function __promisify__(path: PathLike, mode?: number): Promise<void>;
3537
- }
3538
- /**
3539
- * Synchronously tests a user's permissions for the file or directory specified
3540
- * by `path`. The `mode` argument is an optional integer that specifies the
3541
- * accessibility checks to be performed. `mode` should be either the value`fs.constants.F_OK` or a mask consisting of the bitwise OR of any of`fs.constants.R_OK`, `fs.constants.W_OK`, and
3542
- * `fs.constants.X_OK` (e.g.`fs.constants.W_OK | fs.constants.R_OK`). Check `File access constants` for
3543
- * possible values of `mode`.
3544
- *
3545
- * If any of the accessibility checks fail, an `Error` will be thrown. Otherwise,
3546
- * the method will return `undefined`.
3547
- *
3548
- * ```js
3549
- * import { accessSync, constants } from 'fs';
3550
- *
3551
- * try {
3552
- * accessSync('etc/passwd', constants.R_OK | constants.W_OK);
3553
- * console.log('can read/write');
3554
- * } catch (err) {
3555
- * console.error('no access!');
3556
- * }
3557
- * ```
3558
- * @since v0.11.15
3559
- * @param [mode=fs.constants.F_OK]
3560
- */
3561
- export function accessSync(path: PathLike, mode?: number): void;
3562
- interface StreamOptions {
3563
- flags?: string | undefined;
3564
- encoding?: BufferEncoding | undefined;
3565
- fd?: number | promises.FileHandle | undefined;
3566
- mode?: number | undefined;
3567
- autoClose?: boolean | undefined;
3568
- /**
3569
- * @default false
3570
- */
3571
- emitClose?: boolean | undefined;
3572
- start?: number | undefined;
3573
- highWaterMark?: number | undefined;
3574
- }
3575
- interface ReadStreamOptions extends StreamOptions {
3576
- end?: number | undefined;
3577
- }
3578
- /**
3579
- * Unlike the 16 kb default `highWaterMark` for a `stream.Readable`, the stream
3580
- * returned by this method has a default `highWaterMark` of 64 kb.
3581
- *
3582
- * `options` can include `start` and `end` values to read a range of bytes from
3583
- * the file instead of the entire file. Both `start` and `end` are inclusive and
3584
- * start counting at 0, allowed values are in the
3585
- * \[0, [`Number.MAX_SAFE_INTEGER`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)\] range. If `fd` is specified and `start` is
3586
- * omitted or `undefined`, `fs.createReadStream()` reads sequentially from the
3587
- * current file position. The `encoding` can be any one of those accepted by `Buffer`.
3588
- *
3589
- * If `fd` is specified, `ReadStream` will ignore the `path` argument and will use
3590
- * the specified file descriptor. This means that no `'open'` event will be
3591
- * emitted. `fd` should be blocking; non-blocking `fd`s should be passed to `net.Socket`.
3592
- *
3593
- * If `fd` points to a character device that only supports blocking reads
3594
- * (such as keyboard or sound card), read operations do not finish until data is
3595
- * available. This can prevent the process from exiting and the stream from
3596
- * closing naturally.
3597
- *
3598
- * By default, the stream will emit a `'close'` event after it has been
3599
- * destroyed. Set the `emitClose` option to `false` to change this behavior.
3600
- *
3601
- * By providing the `fs` option, it is possible to override the corresponding `fs`implementations for `open`, `read`, and `close`. When providing the `fs` option,
3602
- * an override for `read` is required. If no `fd` is provided, an override for`open` is also required. If `autoClose` is `true`, an override for `close` is
3603
- * also required.
3604
- *
3605
- * ```js
3606
- * import { createReadStream } from 'fs';
3607
- *
3608
- * // Create a stream from some character device.
3609
- * const stream = createReadStream('/dev/input/event0');
3610
- * setTimeout(() => {
3611
- * stream.close(); // This may not close the stream.
3612
- * // Artificially marking end-of-stream, as if the underlying resource had
3613
- * // indicated end-of-file by itself, allows the stream to close.
3614
- * // This does not cancel pending read operations, and if there is such an
3615
- * // operation, the process may still not be able to exit successfully
3616
- * // until it finishes.
3617
- * stream.push(null);
3618
- * stream.read(0);
3619
- * }, 100);
3620
- * ```
3621
- *
3622
- * If `autoClose` is false, then the file descriptor won't be closed, even if
3623
- * there's an error. It is the application's responsibility to close it and make
3624
- * sure there's no file descriptor leak. If `autoClose` is set to true (default
3625
- * behavior), on `'error'` or `'end'` the file descriptor will be closed
3626
- * automatically.
3627
- *
3628
- * `mode` sets the file mode (permission and sticky bits), but only if the
3629
- * file was created.
3630
- *
3631
- * An example to read the last 10 bytes of a file which is 100 bytes long:
3632
- *
3633
- * ```js
3634
- * import { createReadStream } from 'fs';
3635
- *
3636
- * createReadStream('sample.txt', { start: 90, end: 99 });
3637
- * ```
3638
- *
3639
- * If `options` is a string, then it specifies the encoding.
3640
- * @since v0.1.31
3641
- */
3642
- export function createReadStream(path: PathLike, options?: BufferEncoding | ReadStreamOptions): ReadStream;
3643
- /**
3644
- * `options` may also include a `start` option to allow writing data at some
3645
- * position past the beginning of the file, allowed values are in the
3646
- * \[0, [`Number.MAX_SAFE_INTEGER`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)\] range. Modifying a file rather than
3647
- * replacing it may require the `flags` option to be set to `r+` rather than the
3648
- * default `w`. The `encoding` can be any one of those accepted by `Buffer`.
3649
- *
3650
- * If `autoClose` is set to true (default behavior) on `'error'` or `'finish'`the file descriptor will be closed automatically. If `autoClose` is false,
3651
- * then the file descriptor won't be closed, even if there's an error.
3652
- * It is the application's responsibility to close it and make sure there's no
3653
- * file descriptor leak.
3654
- *
3655
- * By default, the stream will emit a `'close'` event after it has been
3656
- * destroyed. Set the `emitClose` option to `false` to change this behavior.
3657
- *
3658
- * By providing the `fs` option it is possible to override the corresponding `fs`implementations for `open`, `write`, `writev` and `close`. Overriding `write()`without `writev()` can reduce
3659
- * performance as some optimizations (`_writev()`)
3660
- * will be disabled. When providing the `fs` option, overrides for at least one of`write` and `writev` are required. If no `fd` option is supplied, an override
3661
- * for `open` is also required. If `autoClose` is `true`, an override for `close`is also required.
3662
- *
3663
- * Like `fs.ReadStream`, if `fd` is specified, `fs.WriteStream` will ignore the`path` argument and will use the specified file descriptor. This means that no`'open'` event will be
3664
- * emitted. `fd` should be blocking; non-blocking `fd`s
3665
- * should be passed to `net.Socket`.
3666
- *
3667
- * If `options` is a string, then it specifies the encoding.
3668
- * @since v0.1.31
3669
- */
3670
- export function createWriteStream(path: PathLike, options?: BufferEncoding | StreamOptions): WriteStream;
3671
- /**
3672
- * Forces all currently queued I/O operations associated with the file to the
3673
- * operating system's synchronized I/O completion state. Refer to the POSIX [`fdatasync(2)`](http://man7.org/linux/man-pages/man2/fdatasync.2.html) documentation for details. No arguments other
3674
- * than a possible
3675
- * exception are given to the completion callback.
3676
- * @since v0.1.96
3677
- */
3678
- export function fdatasync(fd: number, callback: NoParamCallback): void;
3679
- export namespace fdatasync {
3680
- /**
3681
- * Asynchronous fdatasync(2) - synchronize a file's in-core state with storage device.
3682
- * @param fd A file descriptor.
3683
- */
3684
- function __promisify__(fd: number): Promise<void>;
3685
- }
3686
- /**
3687
- * Forces all currently queued I/O operations associated with the file to the
3688
- * operating system's synchronized I/O completion state. Refer to the POSIX [`fdatasync(2)`](http://man7.org/linux/man-pages/man2/fdatasync.2.html) documentation for details. Returns `undefined`.
3689
- * @since v0.1.96
3690
- */
3691
- export function fdatasyncSync(fd: number): void;
3692
- /**
3693
- * Asynchronously copies `src` to `dest`. By default, `dest` is overwritten if it
3694
- * already exists. No arguments other than a possible exception are given to the
3695
- * callback function. Node.js makes no guarantees about the atomicity of the copy
3696
- * operation. If an error occurs after the destination file has been opened for
3697
- * writing, Node.js will attempt to remove the destination.
3698
- *
3699
- * `mode` is an optional integer that specifies the behavior
3700
- * of the copy operation. It is possible to create a mask consisting of the bitwise
3701
- * OR of two or more values (e.g.`fs.constants.COPYFILE_EXCL | fs.constants.COPYFILE_FICLONE`).
3702
- *
3703
- * * `fs.constants.COPYFILE_EXCL`: The copy operation will fail if `dest` already
3704
- * exists.
3705
- * * `fs.constants.COPYFILE_FICLONE`: The copy operation will attempt to create a
3706
- * copy-on-write reflink. If the platform does not support copy-on-write, then a
3707
- * fallback copy mechanism is used.
3708
- * * `fs.constants.COPYFILE_FICLONE_FORCE`: The copy operation will attempt to
3709
- * create a copy-on-write reflink. If the platform does not support
3710
- * copy-on-write, then the operation will fail.
3711
- *
3712
- * ```js
3713
- * import { copyFile, constants } from 'fs';
3714
- *
3715
- * function callback(err) {
3716
- * if (err) throw err;
3717
- * console.log('source.txt was copied to destination.txt');
3718
- * }
3719
- *
3720
- * // destination.txt will be created or overwritten by default.
3721
- * copyFile('source.txt', 'destination.txt', callback);
3722
- *
3723
- * // By using COPYFILE_EXCL, the operation will fail if destination.txt exists.
3724
- * copyFile('source.txt', 'destination.txt', constants.COPYFILE_EXCL, callback);
3725
- * ```
3726
- * @since v8.5.0
3727
- * @param src source filename to copy
3728
- * @param dest destination filename of the copy operation
3729
- * @param [mode=0] modifiers for copy operation.
3730
- */
3731
- export function copyFile(src: PathLike, dest: PathLike, callback: NoParamCallback): void;
3732
- export function copyFile(src: PathLike, dest: PathLike, mode: number, callback: NoParamCallback): void;
3733
- export namespace copyFile {
3734
- function __promisify__(src: PathLike, dst: PathLike, mode?: number): Promise<void>;
3735
- }
3736
- /**
3737
- * Synchronously copies `src` to `dest`. By default, `dest` is overwritten if it
3738
- * already exists. Returns `undefined`. Node.js makes no guarantees about the
3739
- * atomicity of the copy operation. If an error occurs after the destination file
3740
- * has been opened for writing, Node.js will attempt to remove the destination.
3741
- *
3742
- * `mode` is an optional integer that specifies the behavior
3743
- * of the copy operation. It is possible to create a mask consisting of the bitwise
3744
- * OR of two or more values (e.g.`fs.constants.COPYFILE_EXCL | fs.constants.COPYFILE_FICLONE`).
3745
- *
3746
- * * `fs.constants.COPYFILE_EXCL`: The copy operation will fail if `dest` already
3747
- * exists.
3748
- * * `fs.constants.COPYFILE_FICLONE`: The copy operation will attempt to create a
3749
- * copy-on-write reflink. If the platform does not support copy-on-write, then a
3750
- * fallback copy mechanism is used.
3751
- * * `fs.constants.COPYFILE_FICLONE_FORCE`: The copy operation will attempt to
3752
- * create a copy-on-write reflink. If the platform does not support
3753
- * copy-on-write, then the operation will fail.
3754
- *
3755
- * ```js
3756
- * import { copyFileSync, constants } from 'fs';
3757
- *
3758
- * // destination.txt will be created or overwritten by default.
3759
- * copyFileSync('source.txt', 'destination.txt');
3760
- * console.log('source.txt was copied to destination.txt');
3761
- *
3762
- * // By using COPYFILE_EXCL, the operation will fail if destination.txt exists.
3763
- * copyFileSync('source.txt', 'destination.txt', constants.COPYFILE_EXCL);
3764
- * ```
3765
- * @since v8.5.0
3766
- * @param src source filename to copy
3767
- * @param dest destination filename of the copy operation
3768
- * @param [mode=0] modifiers for copy operation.
3769
- */
3770
- export function copyFileSync(src: PathLike, dest: PathLike, mode?: number): void;
3771
- /**
3772
- * Write an array of `ArrayBufferView`s to the file specified by `fd` using`writev()`.
3773
- *
3774
- * `position` is the offset from the beginning of the file where this data
3775
- * should be written. If `typeof position !== 'number'`, the data will be written
3776
- * at the current position.
3777
- *
3778
- * The callback will be given three arguments: `err`, `bytesWritten`, and`buffers`. `bytesWritten` is how many bytes were written from `buffers`.
3779
- *
3780
- * If this method is `util.promisify()` ed, it returns a promise for an`Object` with `bytesWritten` and `buffers` properties.
3781
- *
3782
- * It is unsafe to use `fs.writev()` multiple times on the same file without
3783
- * waiting for the callback. For this scenario, use {@link createWriteStream}.
3784
- *
3785
- * On Linux, positional writes don't work when the file is opened in append mode.
3786
- * The kernel ignores the position argument and always appends the data to
3787
- * the end of the file.
3788
- * @since v12.9.0
3789
- */
3790
- export function writev(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => void): void;
3791
- export function writev(
3792
- fd: number,
3793
- buffers: ReadonlyArray<NodeJS.ArrayBufferView>,
3794
- position: number,
3795
- cb: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffers: NodeJS.ArrayBufferView[]) => void
3796
- ): void;
3797
- export interface WriteVResult {
3798
- bytesWritten: number;
3799
- buffers: NodeJS.ArrayBufferView[];
3800
- }
3801
- export namespace writev {
3802
- function __promisify__(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, position?: number): Promise<WriteVResult>;
3803
- }
3804
- /**
3805
- * For detailed information, see the documentation of the asynchronous version of
3806
- * this API: {@link writev}.
3807
- * @since v12.9.0
3808
- * @return The number of bytes written.
3809
- */
3810
- export function writevSync(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, position?: number): number;
3811
- /**
3812
- * Read from a file specified by `fd` and write to an array of `ArrayBufferView`s
3813
- * using `readv()`.
3814
- *
3815
- * `position` is the offset from the beginning of the file from where data
3816
- * should be read. If `typeof position !== 'number'`, the data will be read
3817
- * from the current position.
3818
- *
3819
- * The callback will be given three arguments: `err`, `bytesRead`, and`buffers`. `bytesRead` is how many bytes were read from the file.
3820
- *
3821
- * If this method is invoked as its `util.promisify()` ed version, it returns
3822
- * a promise for an `Object` with `bytesRead` and `buffers` properties.
3823
- * @since v13.13.0, v12.17.0
3824
- */
3825
- export function readv(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, cb: (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: NodeJS.ArrayBufferView[]) => void): void;
3826
- export function readv(
3827
- fd: number,
3828
- buffers: ReadonlyArray<NodeJS.ArrayBufferView>,
3829
- position: number,
3830
- cb: (err: NodeJS.ErrnoException | null, bytesRead: number, buffers: NodeJS.ArrayBufferView[]) => void
3831
- ): void;
3832
- export interface ReadVResult {
3833
- bytesRead: number;
3834
- buffers: NodeJS.ArrayBufferView[];
3835
- }
3836
- export namespace readv {
3837
- function __promisify__(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, position?: number): Promise<ReadVResult>;
3838
- }
3839
- /**
3840
- * For detailed information, see the documentation of the asynchronous version of
3841
- * this API: {@link readv}.
3842
- * @since v13.13.0, v12.17.0
3843
- * @return The number of bytes read.
3844
- */
3845
- export function readvSync(fd: number, buffers: ReadonlyArray<NodeJS.ArrayBufferView>, position?: number): number;
3846
- export interface OpenDirOptions {
3847
- encoding?: BufferEncoding | undefined;
3848
- /**
3849
- * Number of directory entries that are buffered
3850
- * internally when reading from the directory. Higher values lead to better
3851
- * performance but higher memory usage.
3852
- * @default 32
3853
- */
3854
- bufferSize?: number | undefined;
3855
- }
3856
- /**
3857
- * Synchronously open a directory. See [`opendir(3)`](http://man7.org/linux/man-pages/man3/opendir.3.html).
3858
- *
3859
- * Creates an `fs.Dir`, which contains all further functions for reading from
3860
- * and cleaning up the directory.
3861
- *
3862
- * The `encoding` option sets the encoding for the `path` while opening the
3863
- * directory and subsequent read operations.
3864
- * @since v12.12.0
3865
- */
3866
- export function opendirSync(path: PathLike, options?: OpenDirOptions): Dir;
3867
- /**
3868
- * Asynchronously open a directory. See the POSIX [`opendir(3)`](http://man7.org/linux/man-pages/man3/opendir.3.html) documentation for
3869
- * more details.
3870
- *
3871
- * Creates an `fs.Dir`, which contains all further functions for reading from
3872
- * and cleaning up the directory.
3873
- *
3874
- * The `encoding` option sets the encoding for the `path` while opening the
3875
- * directory and subsequent read operations.
3876
- * @since v12.12.0
3877
- */
3878
- export function opendir(path: PathLike, cb: (err: NodeJS.ErrnoException | null, dir: Dir) => void): void;
3879
- export function opendir(path: PathLike, options: OpenDirOptions, cb: (err: NodeJS.ErrnoException | null, dir: Dir) => void): void;
3880
- export namespace opendir {
3881
- function __promisify__(path: PathLike, options?: OpenDirOptions): Promise<Dir>;
3882
- }
3883
- export interface BigIntStats extends StatsBase<bigint> {
3884
- atimeNs: bigint;
3885
- mtimeNs: bigint;
3886
- ctimeNs: bigint;
3887
- birthtimeNs: bigint;
3888
- }
3889
- export interface BigIntOptions {
3890
- bigint: true;
3891
- }
3892
- export interface StatOptions {
3893
- bigint?: boolean | undefined;
3894
- }
3895
- export interface StatSyncOptions extends StatOptions {
3896
- throwIfNoEntry?: boolean | undefined;
3897
- }
3898
- interface CopyOptionsBase {
3899
- /**
3900
- * Dereference symlinks
3901
- * @default false
3902
- */
3903
- dereference?: boolean;
3904
- /**
3905
- * When `force` is `false`, and the destination
3906
- * exists, throw an error.
3907
- * @default false
3908
- */
3909
- errorOnExist?: boolean;
3910
- /**
3911
- * Overwrite existing file or directory. _The copy
3912
- * operation will ignore errors if you set this to false and the destination
3913
- * exists. Use the `errorOnExist` option to change this behavior.
3914
- * @default true
3915
- */
3916
- force?: boolean;
3917
- /**
3918
- * When `true` timestamps from `src` will
3919
- * be preserved.
3920
- * @default false
3921
- */
3922
- preserveTimestamps?: boolean;
3923
- /**
3924
- * Copy directories recursively.
3925
- * @default false
3926
- */
3927
- recursive?: boolean;
3928
- /**
3929
- * When true, path resolution for symlinks will be skipped
3930
- * @default false
3931
- */
3932
- verbatimSymlinks?: boolean;
3933
- }
3934
- export interface CopyOptions extends CopyOptionsBase {
3935
- /**
3936
- * Function to filter copied files/directories. Return
3937
- * `true` to copy the item, `false` to ignore it.
3938
- */
3939
- filter?(source: string, destination: string): boolean | Promise<boolean>;
3940
- }
3941
- export interface CopySyncOptions extends CopyOptionsBase {
3942
- /**
3943
- * Function to filter copied files/directories. Return
3944
- * `true` to copy the item, `false` to ignore it.
3945
- */
3946
- filter?(source: string, destination: string): boolean;
3947
- }
3948
- /**
3949
- * Asynchronously copies the entire directory structure from `src` to `dest`,
3950
- * including subdirectories and files.
3951
- *
3952
- * When copying a directory to another directory, globs are not supported and
3953
- * behavior is similar to `cp dir1/ dir2/`.
3954
- * @since v16.7.0
3955
- * @experimental
3956
- * @param src source path to copy.
3957
- * @param dest destination path to copy to.
3958
- */
3959
- export function cp(source: string | URL, destination: string | URL, callback: (err: NodeJS.ErrnoException | null) => void): void;
3960
- export function cp(source: string | URL, destination: string | URL, opts: CopyOptions, callback: (err: NodeJS.ErrnoException | null) => void): void;
3961
- /**
3962
- * Synchronously copies the entire directory structure from `src` to `dest`,
3963
- * including subdirectories and files.
3964
- *
3965
- * When copying a directory to another directory, globs are not supported and
3966
- * behavior is similar to `cp dir1/ dir2/`.
3967
- * @since v16.7.0
3968
- * @experimental
3969
- * @param src source path to copy.
3970
- * @param dest destination path to copy to.
3971
- */
3972
- export function cpSync(source: string | URL, destination: string | URL, opts?: CopySyncOptions): void;
3973
- }
3974
- declare module 'node:fs' {
3975
- export * from 'fs';
3976
- }