cloudstructs 0.1.37 → 0.1.41

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