You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fs.d.ts 123KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297
  1. declare module "fs" {
  2. import * as stream from "stream";
  3. import * as events from "events";
  4. import { URL } from "url";
  5. /**
  6. * Valid types for path values in "fs".
  7. */
  8. type PathLike = string | Buffer | URL;
  9. type BinaryData = Buffer | DataView | NodeJS.TypedArray;
  10. class Stats {
  11. isFile(): boolean;
  12. isDirectory(): boolean;
  13. isBlockDevice(): boolean;
  14. isCharacterDevice(): boolean;
  15. isSymbolicLink(): boolean;
  16. isFIFO(): boolean;
  17. isSocket(): boolean;
  18. dev: number;
  19. ino: number;
  20. mode: number;
  21. nlink: number;
  22. uid: number;
  23. gid: number;
  24. rdev: number;
  25. size: number;
  26. blksize: number;
  27. blocks: number;
  28. atimeMs: number;
  29. mtimeMs: number;
  30. ctimeMs: number;
  31. birthtimeMs: number;
  32. atime: Date;
  33. mtime: Date;
  34. ctime: Date;
  35. birthtime: Date;
  36. }
  37. class Dirent {
  38. isFile(): boolean;
  39. isDirectory(): boolean;
  40. isBlockDevice(): boolean;
  41. isCharacterDevice(): boolean;
  42. isSymbolicLink(): boolean;
  43. isFIFO(): boolean;
  44. isSocket(): boolean;
  45. name: string;
  46. }
  47. interface FSWatcher extends events.EventEmitter {
  48. close(): void;
  49. /**
  50. * events.EventEmitter
  51. * 1. change
  52. * 2. error
  53. */
  54. addListener(event: string, listener: (...args: any[]) => void): this;
  55. addListener(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
  56. addListener(event: "error", listener: (error: Error) => void): this;
  57. on(event: string, listener: (...args: any[]) => void): this;
  58. on(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
  59. on(event: "error", listener: (error: Error) => void): this;
  60. once(event: string, listener: (...args: any[]) => void): this;
  61. once(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
  62. once(event: "error", listener: (error: Error) => void): this;
  63. prependListener(event: string, listener: (...args: any[]) => void): this;
  64. prependListener(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
  65. prependListener(event: "error", listener: (error: Error) => void): this;
  66. prependOnceListener(event: string, listener: (...args: any[]) => void): this;
  67. prependOnceListener(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
  68. prependOnceListener(event: "error", listener: (error: Error) => void): this;
  69. }
  70. class ReadStream extends stream.Readable {
  71. close(): void;
  72. bytesRead: number;
  73. path: string | Buffer;
  74. /**
  75. * events.EventEmitter
  76. * 1. open
  77. * 2. close
  78. */
  79. addListener(event: string, listener: (...args: any[]) => void): this;
  80. addListener(event: "open", listener: (fd: number) => void): this;
  81. addListener(event: "close", listener: () => void): this;
  82. on(event: string, listener: (...args: any[]) => void): this;
  83. on(event: "open", listener: (fd: number) => void): this;
  84. on(event: "close", listener: () => void): this;
  85. once(event: string, listener: (...args: any[]) => void): this;
  86. once(event: "open", listener: (fd: number) => void): this;
  87. once(event: "close", listener: () => void): this;
  88. prependListener(event: string, listener: (...args: any[]) => void): this;
  89. prependListener(event: "open", listener: (fd: number) => void): this;
  90. prependListener(event: "close", listener: () => void): this;
  91. prependOnceListener(event: string, listener: (...args: any[]) => void): this;
  92. prependOnceListener(event: "open", listener: (fd: number) => void): this;
  93. prependOnceListener(event: "close", listener: () => void): this;
  94. }
  95. class WriteStream extends stream.Writable {
  96. close(): void;
  97. bytesWritten: number;
  98. path: string | Buffer;
  99. /**
  100. * events.EventEmitter
  101. * 1. open
  102. * 2. close
  103. */
  104. addListener(event: string, listener: (...args: any[]) => void): this;
  105. addListener(event: "open", listener: (fd: number) => void): this;
  106. addListener(event: "close", listener: () => void): this;
  107. on(event: string, listener: (...args: any[]) => void): this;
  108. on(event: "open", listener: (fd: number) => void): this;
  109. on(event: "close", listener: () => void): this;
  110. once(event: string, listener: (...args: any[]) => void): this;
  111. once(event: "open", listener: (fd: number) => void): this;
  112. once(event: "close", listener: () => void): this;
  113. prependListener(event: string, listener: (...args: any[]) => void): this;
  114. prependListener(event: "open", listener: (fd: number) => void): this;
  115. prependListener(event: "close", listener: () => void): this;
  116. prependOnceListener(event: string, listener: (...args: any[]) => void): this;
  117. prependOnceListener(event: "open", listener: (fd: number) => void): this;
  118. prependOnceListener(event: "close", listener: () => void): this;
  119. }
  120. /**
  121. * Asynchronous rename(2) - Change the name or location of a file or directory.
  122. * @param oldPath A path to a file. If a URL is provided, it must use the `file:` protocol.
  123. * URL support is _experimental_.
  124. * @param newPath A path to a file. If a URL is provided, it must use the `file:` protocol.
  125. * URL support is _experimental_.
  126. */
  127. function rename(oldPath: PathLike, newPath: PathLike, callback: (err: NodeJS.ErrnoException | null) => void): void;
  128. // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
  129. namespace rename {
  130. /**
  131. * Asynchronous rename(2) - Change the name or location of a file or directory.
  132. * @param oldPath A path to a file. If a URL is provided, it must use the `file:` protocol.
  133. * URL support is _experimental_.
  134. * @param newPath A path to a file. If a URL is provided, it must use the `file:` protocol.
  135. * URL support is _experimental_.
  136. */
  137. function __promisify__(oldPath: PathLike, newPath: PathLike): Promise<void>;
  138. }
  139. /**
  140. * Synchronous rename(2) - Change the name or location of a file or directory.
  141. * @param oldPath A path to a file. If a URL is provided, it must use the `file:` protocol.
  142. * URL support is _experimental_.
  143. * @param newPath A path to a file. If a URL is provided, it must use the `file:` protocol.
  144. * URL support is _experimental_.
  145. */
  146. function renameSync(oldPath: PathLike, newPath: PathLike): void;
  147. /**
  148. * Asynchronous truncate(2) - Truncate a file to a specified length.
  149. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  150. * @param len If not specified, defaults to `0`.
  151. */
  152. function truncate(path: PathLike, len: number | undefined | null, callback: (err: NodeJS.ErrnoException | null) => void): void;
  153. /**
  154. * Asynchronous truncate(2) - Truncate a file to a specified length.
  155. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  156. * URL support is _experimental_.
  157. */
  158. function truncate(path: PathLike, callback: (err: NodeJS.ErrnoException | null) => void): void;
  159. // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
  160. namespace truncate {
  161. /**
  162. * Asynchronous truncate(2) - Truncate a file to a specified length.
  163. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  164. * @param len If not specified, defaults to `0`.
  165. */
  166. function __promisify__(path: PathLike, len?: number | null): Promise<void>;
  167. }
  168. /**
  169. * Synchronous truncate(2) - Truncate a file to a specified length.
  170. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  171. * @param len If not specified, defaults to `0`.
  172. */
  173. function truncateSync(path: PathLike, len?: number | null): void;
  174. /**
  175. * Asynchronous ftruncate(2) - Truncate a file to a specified length.
  176. * @param fd A file descriptor.
  177. * @param len If not specified, defaults to `0`.
  178. */
  179. function ftruncate(fd: number, len: number | undefined | null, callback: (err: NodeJS.ErrnoException | null) => void): void;
  180. /**
  181. * Asynchronous ftruncate(2) - Truncate a file to a specified length.
  182. * @param fd A file descriptor.
  183. */
  184. function ftruncate(fd: number, callback: (err: NodeJS.ErrnoException | null) => void): void;
  185. // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
  186. namespace ftruncate {
  187. /**
  188. * Asynchronous ftruncate(2) - Truncate a file to a specified length.
  189. * @param fd A file descriptor.
  190. * @param len If not specified, defaults to `0`.
  191. */
  192. function __promisify__(fd: number, len?: number | null): Promise<void>;
  193. }
  194. /**
  195. * Synchronous ftruncate(2) - Truncate a file to a specified length.
  196. * @param fd A file descriptor.
  197. * @param len If not specified, defaults to `0`.
  198. */
  199. function ftruncateSync(fd: number, len?: number | null): void;
  200. /**
  201. * Asynchronous chown(2) - Change ownership of a file.
  202. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  203. */
  204. function chown(path: PathLike, uid: number, gid: number, callback: (err: NodeJS.ErrnoException | null) => void): void;
  205. // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
  206. namespace chown {
  207. /**
  208. * Asynchronous chown(2) - Change ownership of a file.
  209. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  210. */
  211. function __promisify__(path: PathLike, uid: number, gid: number): Promise<void>;
  212. }
  213. /**
  214. * Synchronous chown(2) - Change ownership of a file.
  215. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  216. */
  217. function chownSync(path: PathLike, uid: number, gid: number): void;
  218. /**
  219. * Asynchronous fchown(2) - Change ownership of a file.
  220. * @param fd A file descriptor.
  221. */
  222. function fchown(fd: number, uid: number, gid: number, callback: (err: NodeJS.ErrnoException | null) => void): void;
  223. // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
  224. namespace fchown {
  225. /**
  226. * Asynchronous fchown(2) - Change ownership of a file.
  227. * @param fd A file descriptor.
  228. */
  229. function __promisify__(fd: number, uid: number, gid: number): Promise<void>;
  230. }
  231. /**
  232. * Synchronous fchown(2) - Change ownership of a file.
  233. * @param fd A file descriptor.
  234. */
  235. function fchownSync(fd: number, uid: number, gid: number): void;
  236. /**
  237. * Asynchronous lchown(2) - Change ownership of a file. Does not dereference symbolic links.
  238. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  239. */
  240. function lchown(path: PathLike, uid: number, gid: number, callback: (err: NodeJS.ErrnoException | null) => void): void;
  241. // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
  242. namespace lchown {
  243. /**
  244. * Asynchronous lchown(2) - Change ownership of a file. Does not dereference symbolic links.
  245. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  246. */
  247. function __promisify__(path: PathLike, uid: number, gid: number): Promise<void>;
  248. }
  249. /**
  250. * Synchronous lchown(2) - Change ownership of a file. Does not dereference symbolic links.
  251. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  252. */
  253. function lchownSync(path: PathLike, uid: number, gid: number): void;
  254. /**
  255. * Asynchronous chmod(2) - Change permissions of a file.
  256. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  257. * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
  258. */
  259. function chmod(path: PathLike, mode: string | number, callback: (err: NodeJS.ErrnoException | null) => void): void;
  260. // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
  261. namespace chmod {
  262. /**
  263. * Asynchronous chmod(2) - Change permissions of a file.
  264. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  265. * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
  266. */
  267. function __promisify__(path: PathLike, mode: string | number): Promise<void>;
  268. }
  269. /**
  270. * Synchronous chmod(2) - Change permissions of a file.
  271. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  272. * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
  273. */
  274. function chmodSync(path: PathLike, mode: string | number): void;
  275. /**
  276. * Asynchronous fchmod(2) - Change permissions of a file.
  277. * @param fd A file descriptor.
  278. * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
  279. */
  280. function fchmod(fd: number, mode: string | number, callback: (err: NodeJS.ErrnoException | null) => void): void;
  281. // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
  282. namespace fchmod {
  283. /**
  284. * Asynchronous fchmod(2) - Change permissions of a file.
  285. * @param fd A file descriptor.
  286. * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
  287. */
  288. function __promisify__(fd: number, mode: string | number): Promise<void>;
  289. }
  290. /**
  291. * Synchronous fchmod(2) - Change permissions of a file.
  292. * @param fd A file descriptor.
  293. * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
  294. */
  295. function fchmodSync(fd: number, mode: string | number): void;
  296. /**
  297. * Asynchronous lchmod(2) - Change permissions of a file. Does not dereference symbolic links.
  298. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  299. * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
  300. */
  301. function lchmod(path: PathLike, mode: string | number, callback: (err: NodeJS.ErrnoException | null) => void): void;
  302. // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
  303. namespace lchmod {
  304. /**
  305. * Asynchronous lchmod(2) - Change permissions of a file. Does not dereference symbolic links.
  306. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  307. * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
  308. */
  309. function __promisify__(path: PathLike, mode: string | number): Promise<void>;
  310. }
  311. /**
  312. * Synchronous lchmod(2) - Change permissions of a file. Does not dereference symbolic links.
  313. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  314. * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
  315. */
  316. function lchmodSync(path: PathLike, mode: string | number): void;
  317. /**
  318. * Asynchronous stat(2) - Get file status.
  319. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  320. */
  321. function stat(path: PathLike, callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void): void;
  322. // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
  323. namespace stat {
  324. /**
  325. * Asynchronous stat(2) - Get file status.
  326. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  327. */
  328. function __promisify__(path: PathLike): Promise<Stats>;
  329. }
  330. /**
  331. * Synchronous stat(2) - Get file status.
  332. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  333. */
  334. function statSync(path: PathLike): Stats;
  335. /**
  336. * Asynchronous fstat(2) - Get file status.
  337. * @param fd A file descriptor.
  338. */
  339. function fstat(fd: number, callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void): void;
  340. // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
  341. namespace fstat {
  342. /**
  343. * Asynchronous fstat(2) - Get file status.
  344. * @param fd A file descriptor.
  345. */
  346. function __promisify__(fd: number): Promise<Stats>;
  347. }
  348. /**
  349. * Synchronous fstat(2) - Get file status.
  350. * @param fd A file descriptor.
  351. */
  352. function fstatSync(fd: number): Stats;
  353. /**
  354. * Asynchronous lstat(2) - Get file status. Does not dereference symbolic links.
  355. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  356. */
  357. function lstat(path: PathLike, callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void): void;
  358. // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
  359. namespace lstat {
  360. /**
  361. * Asynchronous lstat(2) - Get file status. Does not dereference symbolic links.
  362. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  363. */
  364. function __promisify__(path: PathLike): Promise<Stats>;
  365. }
  366. /**
  367. * Synchronous lstat(2) - Get file status. Does not dereference symbolic links.
  368. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  369. */
  370. function lstatSync(path: PathLike): Stats;
  371. /**
  372. * Asynchronous link(2) - Create a new link (also known as a hard link) to an existing file.
  373. * @param existingPath A path to a file. If a URL is provided, it must use the `file:` protocol.
  374. * @param newPath A path to a file. If a URL is provided, it must use the `file:` protocol.
  375. */
  376. function link(existingPath: PathLike, newPath: PathLike, callback: (err: NodeJS.ErrnoException | null) => void): void;
  377. // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
  378. namespace link {
  379. /**
  380. * Asynchronous link(2) - Create a new link (also known as a hard link) to an existing file.
  381. * @param existingPath A path to a file. If a URL is provided, it must use the `file:` protocol.
  382. * @param newPath A path to a file. If a URL is provided, it must use the `file:` protocol.
  383. */
  384. function link(existingPath: PathLike, newPath: PathLike): Promise<void>;
  385. }
  386. /**
  387. * Synchronous link(2) - Create a new link (also known as a hard link) to an existing file.
  388. * @param existingPath A path to a file. If a URL is provided, it must use the `file:` protocol.
  389. * @param newPath A path to a file. If a URL is provided, it must use the `file:` protocol.
  390. */
  391. function linkSync(existingPath: PathLike, newPath: PathLike): void;
  392. /**
  393. * Asynchronous symlink(2) - Create a new symbolic link to an existing file.
  394. * @param target A path to an existing file. If a URL is provided, it must use the `file:` protocol.
  395. * @param path A path to the new symlink. If a URL is provided, it must use the `file:` protocol.
  396. * @param type May be set to `'dir'`, `'file'`, or `'junction'` (default is `'file'`) and is only available on Windows (ignored on other platforms).
  397. * When using `'junction'`, the `target` argument will automatically be normalized to an absolute path.
  398. */
  399. function symlink(target: PathLike, path: PathLike, type: symlink.Type | undefined | null, callback: (err: NodeJS.ErrnoException | null) => void): void;
  400. /**
  401. * Asynchronous symlink(2) - Create a new symbolic link to an existing file.
  402. * @param target A path to an existing file. If a URL is provided, it must use the `file:` protocol.
  403. * @param path A path to the new symlink. If a URL is provided, it must use the `file:` protocol.
  404. */
  405. function symlink(target: PathLike, path: PathLike, callback: (err: NodeJS.ErrnoException | null) => void): void;
  406. // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
  407. namespace symlink {
  408. /**
  409. * Asynchronous symlink(2) - Create a new symbolic link to an existing file.
  410. * @param target A path to an existing file. If a URL is provided, it must use the `file:` protocol.
  411. * @param path A path to the new symlink. If a URL is provided, it must use the `file:` protocol.
  412. * @param type May be set to `'dir'`, `'file'`, or `'junction'` (default is `'file'`) and is only available on Windows (ignored on other platforms).
  413. * When using `'junction'`, the `target` argument will automatically be normalized to an absolute path.
  414. */
  415. function __promisify__(target: PathLike, path: PathLike, type?: string | null): Promise<void>;
  416. type Type = "dir" | "file" | "junction";
  417. }
  418. /**
  419. * Synchronous symlink(2) - Create a new symbolic link to an existing file.
  420. * @param target A path to an existing file. If a URL is provided, it must use the `file:` protocol.
  421. * @param path A path to the new symlink. If a URL is provided, it must use the `file:` protocol.
  422. * @param type May be set to `'dir'`, `'file'`, or `'junction'` (default is `'file'`) and is only available on Windows (ignored on other platforms).
  423. * When using `'junction'`, the `target` argument will automatically be normalized to an absolute path.
  424. */
  425. function symlinkSync(target: PathLike, path: PathLike, type?: symlink.Type | null): void;
  426. /**
  427. * Asynchronous readlink(2) - read value of a symbolic link.
  428. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  429. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  430. */
  431. function readlink(
  432. path: PathLike,
  433. options: { encoding?: BufferEncoding | null } | BufferEncoding | undefined | null,
  434. callback: (err: NodeJS.ErrnoException | null, linkString: string) => void
  435. ): void;
  436. /**
  437. * Asynchronous readlink(2) - read value of a symbolic link.
  438. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  439. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  440. */
  441. function readlink(path: PathLike, options: { encoding: "buffer" } | "buffer", callback: (err: NodeJS.ErrnoException | null, linkString: Buffer) => void): void;
  442. /**
  443. * Asynchronous readlink(2) - read value of a symbolic link.
  444. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  445. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  446. */
  447. function readlink(path: PathLike, options: { encoding?: string | null } | string | undefined | null, callback: (err: NodeJS.ErrnoException | null, linkString: string | Buffer) => void): void;
  448. /**
  449. * Asynchronous readlink(2) - read value of a symbolic link.
  450. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  451. */
  452. function readlink(path: PathLike, callback: (err: NodeJS.ErrnoException | null, linkString: string) => void): void;
  453. // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
  454. namespace readlink {
  455. /**
  456. * Asynchronous readlink(2) - read value of a symbolic link.
  457. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  458. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  459. */
  460. function __promisify__(path: PathLike, options?: { encoding?: BufferEncoding | null } | BufferEncoding | null): Promise<string>;
  461. /**
  462. * Asynchronous readlink(2) - read value of a symbolic link.
  463. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  464. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  465. */
  466. function __promisify__(path: PathLike, options: { encoding: "buffer" } | "buffer"): Promise<Buffer>;
  467. /**
  468. * Asynchronous readlink(2) - read value of a symbolic link.
  469. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  470. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  471. */
  472. function __promisify__(path: PathLike, options?: { encoding?: string | null } | string | null): Promise<string | Buffer>;
  473. }
  474. /**
  475. * Synchronous readlink(2) - read value of a symbolic link.
  476. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  477. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  478. */
  479. function readlinkSync(path: PathLike, options?: { encoding?: BufferEncoding | null } | BufferEncoding | null): string;
  480. /**
  481. * Synchronous readlink(2) - read value of a symbolic link.
  482. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  483. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  484. */
  485. function readlinkSync(path: PathLike, options: { encoding: "buffer" } | "buffer"): Buffer;
  486. /**
  487. * Synchronous readlink(2) - read value of a symbolic link.
  488. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  489. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  490. */
  491. function readlinkSync(path: PathLike, options?: { encoding?: string | null } | string | null): string | Buffer;
  492. /**
  493. * Asynchronous realpath(3) - return the canonicalized absolute pathname.
  494. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  495. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  496. */
  497. function realpath(
  498. path: PathLike,
  499. options: { encoding?: BufferEncoding | null } | BufferEncoding | undefined | null,
  500. callback: (err: NodeJS.ErrnoException | null, resolvedPath: string) => void
  501. ): void;
  502. /**
  503. * Asynchronous realpath(3) - return the canonicalized absolute pathname.
  504. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  505. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  506. */
  507. function realpath(path: PathLike, options: { encoding: "buffer" } | "buffer", callback: (err: NodeJS.ErrnoException | null, resolvedPath: Buffer) => void): void;
  508. /**
  509. * Asynchronous realpath(3) - return the canonicalized absolute pathname.
  510. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  511. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  512. */
  513. function realpath(path: PathLike, options: { encoding?: string | null } | string | undefined | null, callback: (err: NodeJS.ErrnoException | null, resolvedPath: string | Buffer) => void): void;
  514. /**
  515. * Asynchronous realpath(3) - return the canonicalized absolute pathname.
  516. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  517. */
  518. function realpath(path: PathLike, callback: (err: NodeJS.ErrnoException | null, resolvedPath: string) => void): void;
  519. // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
  520. namespace realpath {
  521. /**
  522. * Asynchronous realpath(3) - return the canonicalized absolute pathname.
  523. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  524. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  525. */
  526. function __promisify__(path: PathLike, options?: { encoding?: BufferEncoding | null } | BufferEncoding | null): Promise<string>;
  527. /**
  528. * Asynchronous realpath(3) - return the canonicalized absolute pathname.
  529. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  530. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  531. */
  532. function __promisify__(path: PathLike, options: { encoding: "buffer" } | "buffer"): Promise<Buffer>;
  533. /**
  534. * Asynchronous realpath(3) - return the canonicalized absolute pathname.
  535. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  536. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  537. */
  538. function __promisify__(path: PathLike, options?: { encoding?: string | null } | string | null): Promise<string | Buffer>;
  539. function native(
  540. path: PathLike,
  541. options: { encoding?: BufferEncoding | null } | BufferEncoding | undefined | null,
  542. callback: (err: NodeJS.ErrnoException | null, resolvedPath: string) => void
  543. ): void;
  544. function native(path: PathLike, options: { encoding: "buffer" } | "buffer", callback: (err: NodeJS.ErrnoException | null, resolvedPath: Buffer) => void): void;
  545. function native(path: PathLike, options: { encoding?: string | null } | string | undefined | null, callback: (err: NodeJS.ErrnoException | null, resolvedPath: string | Buffer) => void): void;
  546. function native(path: PathLike, callback: (err: NodeJS.ErrnoException | null, resolvedPath: string) => void): void;
  547. }
  548. /**
  549. * Synchronous realpath(3) - return the canonicalized absolute pathname.
  550. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  551. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  552. */
  553. function realpathSync(path: PathLike, options?: { encoding?: BufferEncoding | null } | BufferEncoding | null): string;
  554. /**
  555. * Synchronous realpath(3) - return the canonicalized absolute pathname.
  556. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  557. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  558. */
  559. function realpathSync(path: PathLike, options: { encoding: "buffer" } | "buffer"): Buffer;
  560. /**
  561. * Synchronous realpath(3) - return the canonicalized absolute pathname.
  562. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  563. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  564. */
  565. function realpathSync(path: PathLike, options?: { encoding?: string | null } | string | null): string | Buffer;
  566. namespace realpathSync {
  567. function native(path: PathLike, options?: { encoding?: BufferEncoding | null } | BufferEncoding | null): string;
  568. function native(path: PathLike, options: { encoding: "buffer" } | "buffer"): Buffer;
  569. function native(path: PathLike, options?: { encoding?: string | null } | string | null): string | Buffer;
  570. }
  571. /**
  572. * Asynchronous unlink(2) - delete a name and possibly the file it refers to.
  573. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  574. */
  575. function unlink(path: PathLike, callback: (err: NodeJS.ErrnoException | null) => void): void;
  576. // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
  577. namespace unlink {
  578. /**
  579. * Asynchronous unlink(2) - delete a name and possibly the file it refers to.
  580. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  581. */
  582. function __promisify__(path: PathLike): Promise<void>;
  583. }
  584. /**
  585. * Synchronous unlink(2) - delete a name and possibly the file it refers to.
  586. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  587. */
  588. function unlinkSync(path: PathLike): void;
  589. /**
  590. * Asynchronous rmdir(2) - delete a directory.
  591. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  592. */
  593. function rmdir(path: PathLike, callback: (err: NodeJS.ErrnoException | null) => void): void;
  594. // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
  595. namespace rmdir {
  596. /**
  597. * Asynchronous rmdir(2) - delete a directory.
  598. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  599. */
  600. function __promisify__(path: PathLike): Promise<void>;
  601. }
  602. /**
  603. * Synchronous rmdir(2) - delete a directory.
  604. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  605. */
  606. function rmdirSync(path: PathLike): void;
  607. export interface MakeDirectoryOptions {
  608. /**
  609. * Indicates whether parent folders should be created.
  610. * @default false
  611. */
  612. recursive?: boolean;
  613. /**
  614. * A file mode. If a string is passed, it is parsed as an octal integer. If not specified
  615. * @default 0o777.
  616. */
  617. mode?: number;
  618. }
  619. /**
  620. * Asynchronous mkdir(2) - create a directory.
  621. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  622. * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
  623. * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
  624. */
  625. function mkdir(path: PathLike, options: number | string | MakeDirectoryOptions | undefined | null, callback: (err: NodeJS.ErrnoException | null) => void): void;
  626. /**
  627. * Asynchronous mkdir(2) - create a directory with a mode of `0o777`.
  628. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  629. */
  630. function mkdir(path: PathLike, callback: (err: NodeJS.ErrnoException | null) => void): void;
  631. // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
  632. namespace mkdir {
  633. /**
  634. * Asynchronous mkdir(2) - create a directory.
  635. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  636. * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
  637. * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
  638. */
  639. function __promisify__(path: PathLike, options?: number | string | MakeDirectoryOptions | null): Promise<void>;
  640. }
  641. /**
  642. * Synchronous mkdir(2) - create a directory.
  643. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  644. * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
  645. * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
  646. */
  647. function mkdirSync(path: PathLike, options?: number | string | MakeDirectoryOptions | null): void;
  648. /**
  649. * Asynchronously creates a unique temporary directory.
  650. * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
  651. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  652. */
  653. function mkdtemp(prefix: string, options: { encoding?: BufferEncoding | null } | BufferEncoding | undefined | null, callback: (err: NodeJS.ErrnoException | null, folder: string) => void): void;
  654. /**
  655. * Asynchronously creates a unique temporary directory.
  656. * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
  657. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  658. */
  659. function mkdtemp(prefix: string, options: "buffer" | { encoding: "buffer" }, callback: (err: NodeJS.ErrnoException | null, folder: Buffer) => void): void;
  660. /**
  661. * Asynchronously creates a unique temporary directory.
  662. * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
  663. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  664. */
  665. function mkdtemp(prefix: string, options: { encoding?: string | null } | string | undefined | null, callback: (err: NodeJS.ErrnoException | null, folder: string | Buffer) => void): void;
  666. /**
  667. * Asynchronously creates a unique temporary directory.
  668. * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
  669. */
  670. function mkdtemp(prefix: string, callback: (err: NodeJS.ErrnoException | null, folder: string) => void): void;
  671. // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
  672. namespace mkdtemp {
  673. /**
  674. * Asynchronously creates a unique temporary directory.
  675. * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
  676. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  677. */
  678. function __promisify__(prefix: string, options?: { encoding?: BufferEncoding | null } | BufferEncoding | null): Promise<string>;
  679. /**
  680. * Asynchronously creates a unique temporary directory.
  681. * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
  682. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  683. */
  684. function __promisify__(prefix: string, options: { encoding: "buffer" } | "buffer"): Promise<Buffer>;
  685. /**
  686. * Asynchronously creates a unique temporary directory.
  687. * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
  688. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  689. */
  690. function __promisify__(prefix: string, options?: { encoding?: string | null } | string | null): Promise<string | Buffer>;
  691. }
  692. /**
  693. * Synchronously creates a unique temporary directory.
  694. * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
  695. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  696. */
  697. function mkdtempSync(prefix: string, options?: { encoding?: BufferEncoding | null } | BufferEncoding | null): string;
  698. /**
  699. * Synchronously creates a unique temporary directory.
  700. * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
  701. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  702. */
  703. function mkdtempSync(prefix: string, options: { encoding: "buffer" } | "buffer"): Buffer;
  704. /**
  705. * Synchronously creates a unique temporary directory.
  706. * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
  707. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  708. */
  709. function mkdtempSync(prefix: string, options?: { encoding?: string | null } | string | null): string | Buffer;
  710. /**
  711. * Asynchronous readdir(3) - read a directory.
  712. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  713. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  714. */
  715. function readdir(
  716. path: PathLike,
  717. options: { encoding: BufferEncoding | null; withFileTypes?: false } | BufferEncoding | undefined | null,
  718. callback: (err: NodeJS.ErrnoException | null, files: string[]) => void,
  719. ): void;
  720. /**
  721. * Asynchronous readdir(3) - read a directory.
  722. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  723. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  724. */
  725. function readdir(path: PathLike, options: { encoding: "buffer"; withFileTypes?: false } | "buffer", callback: (err: NodeJS.ErrnoException | null, files: Buffer[]) => void): void;
  726. /**
  727. * Asynchronous readdir(3) - read a directory.
  728. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  729. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  730. */
  731. function readdir(
  732. path: PathLike,
  733. options: { encoding?: string | null; withFileTypes?: false } | string | undefined | null,
  734. callback: (err: NodeJS.ErrnoException | null, files: string[] | Buffer[]) => void,
  735. ): void;
  736. /**
  737. * Asynchronous readdir(3) - read a directory.
  738. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  739. */
  740. function readdir(path: PathLike, callback: (err: NodeJS.ErrnoException | null, files: string[]) => void): void;
  741. /**
  742. * Asynchronous readdir(3) - read a directory.
  743. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  744. * @param options If called with `withFileTypes: true` the result data will be an array of Dirent.
  745. */
  746. function readdir(path: PathLike, options: { encoding?: string | null; withFileTypes: true }, callback: (err: NodeJS.ErrnoException | null, files: Dirent[]) => void): void;
  747. // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
  748. namespace readdir {
  749. /**
  750. * Asynchronous readdir(3) - read a directory.
  751. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  752. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  753. */
  754. function __promisify__(path: PathLike, options?: { encoding: BufferEncoding | null; withFileTypes?: false } | BufferEncoding | null): Promise<string[]>;
  755. /**
  756. * Asynchronous readdir(3) - read a directory.
  757. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  758. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  759. */
  760. function __promisify__(path: PathLike, options: "buffer" | { encoding: "buffer"; withFileTypes?: false }): Promise<Buffer[]>;
  761. /**
  762. * Asynchronous readdir(3) - read a directory.
  763. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  764. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  765. */
  766. function __promisify__(path: PathLike, options?: { encoding?: string | null; withFileTypes?: false } | string | null): Promise<string[] | Buffer[]>;
  767. /**
  768. * Asynchronous readdir(3) - read a directory.
  769. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  770. * @param options If called with `withFileTypes: true` the result data will be an array of Dirent
  771. */
  772. function __promisify__(path: PathLike, options: { encoding?: string | null; withFileTypes: true }): Promise<Dirent[]>;
  773. }
  774. /**
  775. * Synchronous readdir(3) - read a directory.
  776. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  777. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  778. */
  779. function readdirSync(path: PathLike, options?: { encoding: BufferEncoding | null; withFileTypes?: false } | BufferEncoding | null): string[];
  780. /**
  781. * Synchronous readdir(3) - read a directory.
  782. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  783. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  784. */
  785. function readdirSync(path: PathLike, options: { encoding: "buffer"; withFileTypes?: false } | "buffer"): Buffer[];
  786. /**
  787. * Synchronous readdir(3) - read a directory.
  788. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  789. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  790. */
  791. function readdirSync(path: PathLike, options?: { encoding?: string | null; withFileTypes?: false } | string | null): string[] | Buffer[];
  792. /**
  793. * Synchronous readdir(3) - read a directory.
  794. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  795. * @param options If called with `withFileTypes: true` the result data will be an array of Dirent.
  796. */
  797. function readdirSync(path: PathLike, options: { encoding?: string | null; withFileTypes: true }): Dirent[];
  798. /**
  799. * Asynchronous close(2) - close a file descriptor.
  800. * @param fd A file descriptor.
  801. */
  802. function close(fd: number, callback: (err: NodeJS.ErrnoException | null) => void): void;
  803. // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
  804. namespace close {
  805. /**
  806. * Asynchronous close(2) - close a file descriptor.
  807. * @param fd A file descriptor.
  808. */
  809. function __promisify__(fd: number): Promise<void>;
  810. }
  811. /**
  812. * Synchronous close(2) - close a file descriptor.
  813. * @param fd A file descriptor.
  814. */
  815. function closeSync(fd: number): void;
  816. /**
  817. * Asynchronous open(2) - open and possibly create a file.
  818. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  819. * @param mode A file mode. If a string is passed, it is parsed as an octal integer. If not supplied, defaults to `0o666`.
  820. */
  821. function open(path: PathLike, flags: string | number, mode: string | number | undefined | null, callback: (err: NodeJS.ErrnoException | null, fd: number) => void): void;
  822. /**
  823. * Asynchronous open(2) - open and possibly create a file. If the file is created, its mode will be `0o666`.
  824. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  825. */
  826. function open(path: PathLike, flags: string | number, callback: (err: NodeJS.ErrnoException | null, fd: number) => void): void;
  827. // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
  828. namespace open {
  829. /**
  830. * Asynchronous open(2) - open and possibly create a file.
  831. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  832. * @param mode A file mode. If a string is passed, it is parsed as an octal integer. If not supplied, defaults to `0o666`.
  833. */
  834. function __promisify__(path: PathLike, flags: string | number, mode?: string | number | null): Promise<number>;
  835. }
  836. /**
  837. * Synchronous open(2) - open and possibly create a file, returning a file descriptor..
  838. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  839. * @param mode A file mode. If a string is passed, it is parsed as an octal integer. If not supplied, defaults to `0o666`.
  840. */
  841. function openSync(path: PathLike, flags: string | number, mode?: string | number | null): number;
  842. /**
  843. * Asynchronously change file timestamps of the file referenced by the supplied path.
  844. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  845. * @param atime The last access time. If a string is provided, it will be coerced to number.
  846. * @param mtime The last modified time. If a string is provided, it will be coerced to number.
  847. */
  848. function utimes(path: PathLike, atime: string | number | Date, mtime: string | number | Date, callback: (err: NodeJS.ErrnoException | null) => void): void;
  849. // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
  850. namespace utimes {
  851. /**
  852. * Asynchronously change file timestamps of the file referenced by the supplied path.
  853. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  854. * @param atime The last access time. If a string is provided, it will be coerced to number.
  855. * @param mtime The last modified time. If a string is provided, it will be coerced to number.
  856. */
  857. function __promisify__(path: PathLike, atime: string | number | Date, mtime: string | number | Date): Promise<void>;
  858. }
  859. /**
  860. * Synchronously change file timestamps of the file referenced by the supplied path.
  861. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  862. * @param atime The last access time. If a string is provided, it will be coerced to number.
  863. * @param mtime The last modified time. If a string is provided, it will be coerced to number.
  864. */
  865. function utimesSync(path: PathLike, atime: string | number | Date, mtime: string | number | Date): void;
  866. /**
  867. * Asynchronously change file timestamps of the file referenced by the supplied file descriptor.
  868. * @param fd A file descriptor.
  869. * @param atime The last access time. If a string is provided, it will be coerced to number.
  870. * @param mtime The last modified time. If a string is provided, it will be coerced to number.
  871. */
  872. function futimes(fd: number, atime: string | number | Date, mtime: string | number | Date, callback: (err: NodeJS.ErrnoException | null) => void): void;
  873. // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
  874. namespace futimes {
  875. /**
  876. * Asynchronously change file timestamps of the file referenced by the supplied file descriptor.
  877. * @param fd A file descriptor.
  878. * @param atime The last access time. If a string is provided, it will be coerced to number.
  879. * @param mtime The last modified time. If a string is provided, it will be coerced to number.
  880. */
  881. function __promisify__(fd: number, atime: string | number | Date, mtime: string | number | Date): Promise<void>;
  882. }
  883. /**
  884. * Synchronously change file timestamps of the file referenced by the supplied file descriptor.
  885. * @param fd A file descriptor.
  886. * @param atime The last access time. If a string is provided, it will be coerced to number.
  887. * @param mtime The last modified time. If a string is provided, it will be coerced to number.
  888. */
  889. function futimesSync(fd: number, atime: string | number | Date, mtime: string | number | Date): void;
  890. /**
  891. * Asynchronous fsync(2) - synchronize a file's in-core state with the underlying storage device.
  892. * @param fd A file descriptor.
  893. */
  894. function fsync(fd: number, callback: (err: NodeJS.ErrnoException | null) => void): void;
  895. // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
  896. namespace fsync {
  897. /**
  898. * Asynchronous fsync(2) - synchronize a file's in-core state with the underlying storage device.
  899. * @param fd A file descriptor.
  900. */
  901. function __promisify__(fd: number): Promise<void>;
  902. }
  903. /**
  904. * Synchronous fsync(2) - synchronize a file's in-core state with the underlying storage device.
  905. * @param fd A file descriptor.
  906. */
  907. function fsyncSync(fd: number): void;
  908. /**
  909. * Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
  910. * @param fd A file descriptor.
  911. * @param offset The part of the buffer to be written. If not supplied, defaults to `0`.
  912. * @param length The number of bytes to write. If not supplied, defaults to `buffer.length - offset`.
  913. * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
  914. */
  915. function write<TBuffer extends BinaryData>(
  916. fd: number,
  917. buffer: TBuffer,
  918. offset: number | undefined | null,
  919. length: number | undefined | null,
  920. position: number | undefined | null,
  921. callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void,
  922. ): void;
  923. /**
  924. * Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
  925. * @param fd A file descriptor.
  926. * @param offset The part of the buffer to be written. If not supplied, defaults to `0`.
  927. * @param length The number of bytes to write. If not supplied, defaults to `buffer.length - offset`.
  928. */
  929. function write<TBuffer extends BinaryData>(
  930. fd: number,
  931. buffer: TBuffer,
  932. offset: number | undefined | null,
  933. length: number | undefined | null,
  934. callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void,
  935. ): void;
  936. /**
  937. * Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
  938. * @param fd A file descriptor.
  939. * @param offset The part of the buffer to be written. If not supplied, defaults to `0`.
  940. */
  941. function write<TBuffer extends BinaryData>(
  942. fd: number,
  943. buffer: TBuffer,
  944. offset: number | undefined | null,
  945. callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void
  946. ): void;
  947. /**
  948. * Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
  949. * @param fd A file descriptor.
  950. */
  951. function write<TBuffer extends BinaryData>(fd: number, buffer: TBuffer, callback: (err: NodeJS.ErrnoException | null, written: number, buffer: TBuffer) => void): void;
  952. /**
  953. * Asynchronously writes `string` to the file referenced by the supplied file descriptor.
  954. * @param fd A file descriptor.
  955. * @param string A string to write. If something other than a string is supplied it will be coerced to a string.
  956. * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
  957. * @param encoding The expected string encoding.
  958. */
  959. function write(
  960. fd: number,
  961. string: any,
  962. position: number | undefined | null,
  963. encoding: string | undefined | null,
  964. callback: (err: NodeJS.ErrnoException | null, written: number, str: string) => void,
  965. ): void;
  966. /**
  967. * Asynchronously writes `string` to the file referenced by the supplied file descriptor.
  968. * @param fd A file descriptor.
  969. * @param string A string to write. If something other than a string is supplied it will be coerced to a string.
  970. * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
  971. */
  972. function write(fd: number, string: any, position: number | undefined | null, callback: (err: NodeJS.ErrnoException | null, written: number, str: string) => void): void;
  973. /**
  974. * Asynchronously writes `string` to the file referenced by the supplied file descriptor.
  975. * @param fd A file descriptor.
  976. * @param string A string to write. If something other than a string is supplied it will be coerced to a string.
  977. */
  978. function write(fd: number, string: any, callback: (err: NodeJS.ErrnoException | null, written: number, str: string) => void): void;
  979. // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
  980. namespace write {
  981. /**
  982. * Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
  983. * @param fd A file descriptor.
  984. * @param offset The part of the buffer to be written. If not supplied, defaults to `0`.
  985. * @param length The number of bytes to write. If not supplied, defaults to `buffer.length - offset`.
  986. * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
  987. */
  988. function __promisify__<TBuffer extends BinaryData>(
  989. fd: number,
  990. buffer?: TBuffer,
  991. offset?: number,
  992. length?: number,
  993. position?: number | null,
  994. ): Promise<{ bytesWritten: number, buffer: TBuffer }>;
  995. /**
  996. * Asynchronously writes `string` to the file referenced by the supplied file descriptor.
  997. * @param fd A file descriptor.
  998. * @param string A string to write. If something other than a string is supplied it will be coerced to a string.
  999. * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
  1000. * @param encoding The expected string encoding.
  1001. */
  1002. function __promisify__(fd: number, string: any, position?: number | null, encoding?: string | null): Promise<{ bytesWritten: number, buffer: string }>;
  1003. }
  1004. /**
  1005. * Synchronously writes `buffer` to the file referenced by the supplied file descriptor, returning the number of bytes written.
  1006. * @param fd A file descriptor.
  1007. * @param offset The part of the buffer to be written. If not supplied, defaults to `0`.
  1008. * @param length The number of bytes to write. If not supplied, defaults to `buffer.length - offset`.
  1009. * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
  1010. */
  1011. function writeSync(fd: number, buffer: BinaryData, offset?: number | null, length?: number | null, position?: number | null): number;
  1012. /**
  1013. * Synchronously writes `string` to the file referenced by the supplied file descriptor, returning the number of bytes written.
  1014. * @param fd A file descriptor.
  1015. * @param string A string to write. If something other than a string is supplied it will be coerced to a string.
  1016. * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
  1017. * @param encoding The expected string encoding.
  1018. */
  1019. function writeSync(fd: number, string: any, position?: number | null, encoding?: string | null): number;
  1020. /**
  1021. * Asynchronously reads data from the file referenced by the supplied file descriptor.
  1022. * @param fd A file descriptor.
  1023. * @param buffer The buffer that the data will be written to.
  1024. * @param offset The offset in the buffer at which to start writing.
  1025. * @param length The number of bytes to read.
  1026. * @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.
  1027. */
  1028. function read<TBuffer extends BinaryData>(
  1029. fd: number,
  1030. buffer: TBuffer,
  1031. offset: number,
  1032. length: number,
  1033. position: number | null,
  1034. callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: TBuffer) => void,
  1035. ): void;
  1036. // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
  1037. namespace read {
  1038. /**
  1039. * @param fd A file descriptor.
  1040. * @param buffer The buffer that the data will be written to.
  1041. * @param offset The offset in the buffer at which to start writing.
  1042. * @param length The number of bytes to read.
  1043. * @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.
  1044. */
  1045. function __promisify__<TBuffer extends BinaryData>(fd: number, buffer: TBuffer, offset: number, length: number, position: number | null): Promise<{ bytesRead: number, buffer: TBuffer }>;
  1046. }
  1047. /**
  1048. * Synchronously reads data from the file referenced by the supplied file descriptor, returning the number of bytes read.
  1049. * @param fd A file descriptor.
  1050. * @param buffer The buffer that the data will be written to.
  1051. * @param offset The offset in the buffer at which to start writing.
  1052. * @param length The number of bytes to read.
  1053. * @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.
  1054. */
  1055. function readSync(fd: number, buffer: BinaryData, offset: number, length: number, position: number | null): number;
  1056. /**
  1057. * Asynchronously reads the entire contents of a file.
  1058. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  1059. * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
  1060. * @param options An object that may contain an optional flag.
  1061. * If a flag is not provided, it defaults to `'r'`.
  1062. */
  1063. function readFile(path: PathLike | number, options: { encoding?: null; flag?: string; } | undefined | null, callback: (err: NodeJS.ErrnoException | null, data: Buffer) => void): void;
  1064. /**
  1065. * Asynchronously reads the entire contents of a file.
  1066. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  1067. * URL support is _experimental_.
  1068. * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
  1069. * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
  1070. * If a flag is not provided, it defaults to `'r'`.
  1071. */
  1072. function readFile(path: PathLike | number, options: { encoding: string; flag?: string; } | string, callback: (err: NodeJS.ErrnoException | null, data: string) => void): void;
  1073. /**
  1074. * Asynchronously reads the entire contents of a file.
  1075. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  1076. * URL support is _experimental_.
  1077. * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
  1078. * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
  1079. * If a flag is not provided, it defaults to `'r'`.
  1080. */
  1081. function readFile(
  1082. path: PathLike | number,
  1083. options: { encoding?: string | null; flag?: string; } | string | undefined | null,
  1084. callback: (err: NodeJS.ErrnoException | null, data: string | Buffer) => void,
  1085. ): void;
  1086. /**
  1087. * Asynchronously reads the entire contents of a file.
  1088. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  1089. * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
  1090. */
  1091. function readFile(path: PathLike | number, callback: (err: NodeJS.ErrnoException | null, data: Buffer) => void): void;
  1092. // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
  1093. namespace readFile {
  1094. /**
  1095. * Asynchronously reads the entire contents of a file.
  1096. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  1097. * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
  1098. * @param options An object that may contain an optional flag.
  1099. * If a flag is not provided, it defaults to `'r'`.
  1100. */
  1101. function __promisify__(path: PathLike | number, options?: { encoding?: null; flag?: string; } | null): Promise<Buffer>;
  1102. /**
  1103. * Asynchronously reads the entire contents of a file.
  1104. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  1105. * URL support is _experimental_.
  1106. * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
  1107. * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
  1108. * If a flag is not provided, it defaults to `'r'`.
  1109. */
  1110. function __promisify__(path: PathLike | number, options: { encoding: string; flag?: string; } | string): Promise<string>;
  1111. /**
  1112. * Asynchronously reads the entire contents of a file.
  1113. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  1114. * URL support is _experimental_.
  1115. * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
  1116. * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
  1117. * If a flag is not provided, it defaults to `'r'`.
  1118. */
  1119. function __promisify__(path: PathLike | number, options?: { encoding?: string | null; flag?: string; } | string | null): Promise<string | Buffer>;
  1120. }
  1121. /**
  1122. * Synchronously reads the entire contents of a file.
  1123. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  1124. * URL support is _experimental_.
  1125. * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
  1126. * @param options An object that may contain an optional flag. If a flag is not provided, it defaults to `'r'`.
  1127. */
  1128. function readFileSync(path: PathLike | number, options?: { encoding?: null; flag?: string; } | null): Buffer;
  1129. /**
  1130. * Synchronously reads the entire contents of a file.
  1131. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  1132. * URL support is _experimental_.
  1133. * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
  1134. * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
  1135. * If a flag is not provided, it defaults to `'r'`.
  1136. */
  1137. function readFileSync(path: PathLike | number, options: { encoding: string; flag?: string; } | string): string;
  1138. /**
  1139. * Synchronously reads the entire contents of a file.
  1140. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  1141. * URL support is _experimental_.
  1142. * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
  1143. * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
  1144. * If a flag is not provided, it defaults to `'r'`.
  1145. */
  1146. function readFileSync(path: PathLike | number, options?: { encoding?: string | null; flag?: string; } | string | null): string | Buffer;
  1147. type WriteFileOptions = { encoding?: string | null; mode?: number | string; flag?: string; } | string | null;
  1148. /**
  1149. * Asynchronously writes data to a file, replacing the file if it already exists.
  1150. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  1151. * URL support is _experimental_.
  1152. * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
  1153. * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
  1154. * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
  1155. * If `encoding` is not supplied, the default of `'utf8'` is used.
  1156. * If `mode` is not supplied, the default of `0o666` is used.
  1157. * If `mode` is a string, it is parsed as an octal integer.
  1158. * If `flag` is not supplied, the default of `'w'` is used.
  1159. */
  1160. function writeFile(path: PathLike | number, data: any, options: WriteFileOptions, callback: (err: NodeJS.ErrnoException | null) => void): void;
  1161. /**
  1162. * Asynchronously writes data to a file, replacing the file if it already exists.
  1163. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  1164. * URL support is _experimental_.
  1165. * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
  1166. * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
  1167. */
  1168. function writeFile(path: PathLike | number, data: any, callback: (err: NodeJS.ErrnoException | null) => void): void;
  1169. // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
  1170. namespace writeFile {
  1171. /**
  1172. * Asynchronously writes data to a file, replacing the file if it already exists.
  1173. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  1174. * URL support is _experimental_.
  1175. * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
  1176. * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
  1177. * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
  1178. * If `encoding` is not supplied, the default of `'utf8'` is used.
  1179. * If `mode` is not supplied, the default of `0o666` is used.
  1180. * If `mode` is a string, it is parsed as an octal integer.
  1181. * If `flag` is not supplied, the default of `'w'` is used.
  1182. */
  1183. function __promisify__(path: PathLike | number, data: any, options?: WriteFileOptions): Promise<void>;
  1184. }
  1185. /**
  1186. * Synchronously writes data to a file, replacing the file if it already exists.
  1187. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  1188. * URL support is _experimental_.
  1189. * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
  1190. * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
  1191. * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
  1192. * If `encoding` is not supplied, the default of `'utf8'` is used.
  1193. * If `mode` is not supplied, the default of `0o666` is used.
  1194. * If `mode` is a string, it is parsed as an octal integer.
  1195. * If `flag` is not supplied, the default of `'w'` is used.
  1196. */
  1197. function writeFileSync(path: PathLike | number, data: any, options?: WriteFileOptions): void;
  1198. /**
  1199. * Asynchronously append data to a file, creating the file if it does not exist.
  1200. * @param file A path to a file. If a URL is provided, it must use the `file:` protocol.
  1201. * URL support is _experimental_.
  1202. * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
  1203. * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
  1204. * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
  1205. * If `encoding` is not supplied, the default of `'utf8'` is used.
  1206. * If `mode` is not supplied, the default of `0o666` is used.
  1207. * If `mode` is a string, it is parsed as an octal integer.
  1208. * If `flag` is not supplied, the default of `'a'` is used.
  1209. */
  1210. function appendFile(file: PathLike | number, data: any, options: WriteFileOptions, callback: (err: NodeJS.ErrnoException | null) => void): void;
  1211. /**
  1212. * Asynchronously append data to a file, creating the file if it does not exist.
  1213. * @param file A path to a file. If a URL is provided, it must use the `file:` protocol.
  1214. * URL support is _experimental_.
  1215. * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
  1216. * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
  1217. */
  1218. function appendFile(file: PathLike | number, data: any, callback: (err: NodeJS.ErrnoException | null) => void): void;
  1219. // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
  1220. namespace appendFile {
  1221. /**
  1222. * Asynchronously append data to a file, creating the file if it does not exist.
  1223. * @param file A path to a file. If a URL is provided, it must use the `file:` protocol.
  1224. * URL support is _experimental_.
  1225. * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
  1226. * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
  1227. * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
  1228. * If `encoding` is not supplied, the default of `'utf8'` is used.
  1229. * If `mode` is not supplied, the default of `0o666` is used.
  1230. * If `mode` is a string, it is parsed as an octal integer.
  1231. * If `flag` is not supplied, the default of `'a'` is used.
  1232. */
  1233. function __promisify__(file: PathLike | number, data: any, options?: WriteFileOptions): Promise<void>;
  1234. }
  1235. /**
  1236. * Synchronously append data to a file, creating the file if it does not exist.
  1237. * @param file A path to a file. If a URL is provided, it must use the `file:` protocol.
  1238. * URL support is _experimental_.
  1239. * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
  1240. * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
  1241. * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
  1242. * If `encoding` is not supplied, the default of `'utf8'` is used.
  1243. * If `mode` is not supplied, the default of `0o666` is used.
  1244. * If `mode` is a string, it is parsed as an octal integer.
  1245. * If `flag` is not supplied, the default of `'a'` is used.
  1246. */
  1247. function appendFileSync(file: PathLike | number, data: any, options?: WriteFileOptions): void;
  1248. /**
  1249. * Watch for changes on `filename`. The callback `listener` will be called each time the file is accessed.
  1250. */
  1251. function watchFile(filename: PathLike, options: { persistent?: boolean; interval?: number; } | undefined, listener: (curr: Stats, prev: Stats) => void): void;
  1252. /**
  1253. * Watch for changes on `filename`. The callback `listener` will be called each time the file is accessed.
  1254. * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
  1255. * URL support is _experimental_.
  1256. */
  1257. function watchFile(filename: PathLike, listener: (curr: Stats, prev: Stats) => void): void;
  1258. /**
  1259. * Stop watching for changes on `filename`.
  1260. * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
  1261. * URL support is _experimental_.
  1262. */
  1263. function unwatchFile(filename: PathLike, listener?: (curr: Stats, prev: Stats) => void): void;
  1264. /**
  1265. * Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
  1266. * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
  1267. * URL support is _experimental_.
  1268. * @param options Either the encoding for the filename provided to the listener, or an object optionally specifying encoding, persistent, and recursive options.
  1269. * If `encoding` is not supplied, the default of `'utf8'` is used.
  1270. * If `persistent` is not supplied, the default of `true` is used.
  1271. * If `recursive` is not supplied, the default of `false` is used.
  1272. */
  1273. function watch(
  1274. filename: PathLike,
  1275. options: { encoding?: BufferEncoding | null, persistent?: boolean, recursive?: boolean } | BufferEncoding | undefined | null,
  1276. listener?: (event: string, filename: string) => void,
  1277. ): FSWatcher;
  1278. /**
  1279. * Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
  1280. * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
  1281. * URL support is _experimental_.
  1282. * @param options Either the encoding for the filename provided to the listener, or an object optionally specifying encoding, persistent, and recursive options.
  1283. * If `encoding` is not supplied, the default of `'utf8'` is used.
  1284. * If `persistent` is not supplied, the default of `true` is used.
  1285. * If `recursive` is not supplied, the default of `false` is used.
  1286. */
  1287. function watch(filename: PathLike, options: { encoding: "buffer", persistent?: boolean, recursive?: boolean } | "buffer", listener?: (event: string, filename: Buffer) => void): FSWatcher;
  1288. /**
  1289. * Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
  1290. * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
  1291. * URL support is _experimental_.
  1292. * @param options Either the encoding for the filename provided to the listener, or an object optionally specifying encoding, persistent, and recursive options.
  1293. * If `encoding` is not supplied, the default of `'utf8'` is used.
  1294. * If `persistent` is not supplied, the default of `true` is used.
  1295. * If `recursive` is not supplied, the default of `false` is used.
  1296. */
  1297. function watch(
  1298. filename: PathLike,
  1299. options: { encoding?: string | null, persistent?: boolean, recursive?: boolean } | string | null,
  1300. listener?: (event: string, filename: string | Buffer) => void,
  1301. ): FSWatcher;
  1302. /**
  1303. * Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
  1304. * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
  1305. * URL support is _experimental_.
  1306. */
  1307. function watch(filename: PathLike, listener?: (event: string, filename: string) => any): FSWatcher;
  1308. /**
  1309. * Asynchronously tests whether or not the given path exists by checking with the file system.
  1310. * @deprecated
  1311. * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
  1312. * URL support is _experimental_.
  1313. */
  1314. function exists(path: PathLike, callback: (exists: boolean) => void): void;
  1315. // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
  1316. namespace exists {
  1317. /**
  1318. * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
  1319. * URL support is _experimental_.
  1320. */
  1321. function __promisify__(path: PathLike): Promise<boolean>;
  1322. }
  1323. /**
  1324. * Synchronously tests whether or not the given path exists by checking with the file system.
  1325. * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
  1326. * URL support is _experimental_.
  1327. */
  1328. function existsSync(path: PathLike): boolean;
  1329. namespace constants {
  1330. // File Access Constants
  1331. /** Constant for fs.access(). File is visible to the calling process. */
  1332. const F_OK: number;
  1333. /** Constant for fs.access(). File can be read by the calling process. */
  1334. const R_OK: number;
  1335. /** Constant for fs.access(). File can be written by the calling process. */
  1336. const W_OK: number;
  1337. /** Constant for fs.access(). File can be executed by the calling process. */
  1338. const X_OK: number;
  1339. // File Copy Constants
  1340. /** Constant for fs.copyFile. Flag indicating the destination file should not be overwritten if it already exists. */
  1341. const COPYFILE_EXCL: number;
  1342. /**
  1343. * Constant for fs.copyFile. copy operation will attempt to create a copy-on-write reflink.
  1344. * If the underlying platform does not support copy-on-write, then a fallback copy mechanism is used.
  1345. */
  1346. const COPYFILE_FICLONE: number;
  1347. /**
  1348. * Constant for fs.copyFile. Copy operation will attempt to create a copy-on-write reflink.
  1349. * If the underlying platform does not support copy-on-write, then the operation will fail with an error.
  1350. */
  1351. const COPYFILE_FICLONE_FORCE: number;
  1352. // File Open Constants
  1353. /** Constant for fs.open(). Flag indicating to open a file for read-only access. */
  1354. const O_RDONLY: number;
  1355. /** Constant for fs.open(). Flag indicating to open a file for write-only access. */
  1356. const O_WRONLY: number;
  1357. /** Constant for fs.open(). Flag indicating to open a file for read-write access. */
  1358. const O_RDWR: number;
  1359. /** Constant for fs.open(). Flag indicating to create the file if it does not already exist. */
  1360. const O_CREAT: number;
  1361. /** Constant for fs.open(). Flag indicating that opening a file should fail if the O_CREAT flag is set and the file already exists. */
  1362. const O_EXCL: number;
  1363. /**
  1364. * Constant for fs.open(). Flag indicating that if path identifies a terminal device,
  1365. * opening the path shall not cause that terminal to become the controlling terminal for the process
  1366. * (if the process does not already have one).
  1367. */
  1368. const O_NOCTTY: number;
  1369. /** 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. */
  1370. const O_TRUNC: number;
  1371. /** Constant for fs.open(). Flag indicating that data will be appended to the end of the file. */
  1372. const O_APPEND: number;
  1373. /** Constant for fs.open(). Flag indicating that the open should fail if the path is not a directory. */
  1374. const O_DIRECTORY: number;
  1375. /**
  1376. * constant for fs.open().
  1377. * Flag indicating reading accesses to the file system will no longer result in
  1378. * an update to the atime information associated with the file.
  1379. * This flag is available on Linux operating systems only.
  1380. */
  1381. const O_NOATIME: number;
  1382. /** Constant for fs.open(). Flag indicating that the open should fail if the path is a symbolic link. */
  1383. const O_NOFOLLOW: number;
  1384. /** Constant for fs.open(). Flag indicating that the file is opened for synchronous I/O. */
  1385. const O_SYNC: number;
  1386. /** Constant for fs.open(). Flag indicating that the file is opened for synchronous I/O with write operations waiting for data integrity. */
  1387. const O_DSYNC: number;
  1388. /** Constant for fs.open(). Flag indicating to open the symbolic link itself rather than the resource it is pointing to. */
  1389. const O_SYMLINK: number;
  1390. /** Constant for fs.open(). When set, an attempt will be made to minimize caching effects of file I/O. */
  1391. const O_DIRECT: number;
  1392. /** Constant for fs.open(). Flag indicating to open the file in nonblocking mode when possible. */
  1393. const O_NONBLOCK: number;
  1394. // File Type Constants
  1395. /** Constant for fs.Stats mode property for determining a file's type. Bit mask used to extract the file type code. */
  1396. const S_IFMT: number;
  1397. /** Constant for fs.Stats mode property for determining a file's type. File type constant for a regular file. */
  1398. const S_IFREG: number;
  1399. /** Constant for fs.Stats mode property for determining a file's type. File type constant for a directory. */
  1400. const S_IFDIR: number;
  1401. /** Constant for fs.Stats mode property for determining a file's type. File type constant for a character-oriented device file. */
  1402. const S_IFCHR: number;
  1403. /** Constant for fs.Stats mode property for determining a file's type. File type constant for a block-oriented device file. */
  1404. const S_IFBLK: number;
  1405. /** Constant for fs.Stats mode property for determining a file's type. File type constant for a FIFO/pipe. */
  1406. const S_IFIFO: number;
  1407. /** Constant for fs.Stats mode property for determining a file's type. File type constant for a symbolic link. */
  1408. const S_IFLNK: number;
  1409. /** Constant for fs.Stats mode property for determining a file's type. File type constant for a socket. */
  1410. const S_IFSOCK: number;
  1411. // File Mode Constants
  1412. /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable, writable and executable by owner. */
  1413. const S_IRWXU: number;
  1414. /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable by owner. */
  1415. const S_IRUSR: number;
  1416. /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating writable by owner. */
  1417. const S_IWUSR: number;
  1418. /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating executable by owner. */
  1419. const S_IXUSR: number;
  1420. /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable, writable and executable by group. */
  1421. const S_IRWXG: number;
  1422. /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable by group. */
  1423. const S_IRGRP: number;
  1424. /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating writable by group. */
  1425. const S_IWGRP: number;
  1426. /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating executable by group. */
  1427. const S_IXGRP: number;
  1428. /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable, writable and executable by others. */
  1429. const S_IRWXO: number;
  1430. /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable by others. */
  1431. const S_IROTH: number;
  1432. /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating writable by others. */
  1433. const S_IWOTH: number;
  1434. /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating executable by others. */
  1435. const S_IXOTH: number;
  1436. }
  1437. /**
  1438. * Asynchronously tests a user's permissions for the file specified by path.
  1439. * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
  1440. * URL support is _experimental_.
  1441. */
  1442. function access(path: PathLike, mode: number | undefined, callback: (err: NodeJS.ErrnoException | null) => void): void;
  1443. /**
  1444. * Asynchronously tests a user's permissions for the file specified by path.
  1445. * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
  1446. * URL support is _experimental_.
  1447. */
  1448. function access(path: PathLike, callback: (err: NodeJS.ErrnoException | null) => void): void;
  1449. // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
  1450. namespace access {
  1451. /**
  1452. * Asynchronously tests a user's permissions for the file specified by path.
  1453. * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
  1454. * URL support is _experimental_.
  1455. */
  1456. function __promisify__(path: PathLike, mode?: number): Promise<void>;
  1457. }
  1458. /**
  1459. * Synchronously tests a user's permissions for the file specified by path.
  1460. * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
  1461. * URL support is _experimental_.
  1462. */
  1463. function accessSync(path: PathLike, mode?: number): void;
  1464. /**
  1465. * Returns a new `ReadStream` object.
  1466. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  1467. * URL support is _experimental_.
  1468. */
  1469. function createReadStream(path: PathLike, options?: string | {
  1470. flags?: string;
  1471. encoding?: string;
  1472. fd?: number;
  1473. mode?: number;
  1474. autoClose?: boolean;
  1475. start?: number;
  1476. end?: number;
  1477. highWaterMark?: number;
  1478. }): ReadStream;
  1479. /**
  1480. * Returns a new `WriteStream` object.
  1481. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  1482. * URL support is _experimental_.
  1483. */
  1484. function createWriteStream(path: PathLike, options?: string | {
  1485. flags?: string;
  1486. encoding?: string;
  1487. fd?: number;
  1488. mode?: number;
  1489. autoClose?: boolean;
  1490. start?: number;
  1491. highWaterMark?: number;
  1492. }): WriteStream;
  1493. /**
  1494. * Asynchronous fdatasync(2) - synchronize a file's in-core state with storage device.
  1495. * @param fd A file descriptor.
  1496. */
  1497. function fdatasync(fd: number, callback: (err: NodeJS.ErrnoException | null) => void): void;
  1498. // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
  1499. namespace fdatasync {
  1500. /**
  1501. * Asynchronous fdatasync(2) - synchronize a file's in-core state with storage device.
  1502. * @param fd A file descriptor.
  1503. */
  1504. function __promisify__(fd: number): Promise<void>;
  1505. }
  1506. /**
  1507. * Synchronous fdatasync(2) - synchronize a file's in-core state with storage device.
  1508. * @param fd A file descriptor.
  1509. */
  1510. function fdatasyncSync(fd: number): void;
  1511. /**
  1512. * Asynchronously copies src to dest. By default, dest is overwritten if it already exists.
  1513. * No arguments other than a possible exception are given to the callback function.
  1514. * Node.js makes no guarantees about the atomicity of the copy operation.
  1515. * If an error occurs after the destination file has been opened for writing, Node.js will attempt
  1516. * to remove the destination.
  1517. * @param src A path to the source file.
  1518. * @param dest A path to the destination file.
  1519. */
  1520. function copyFile(src: PathLike, dest: PathLike, callback: (err: NodeJS.ErrnoException | null) => void): void;
  1521. /**
  1522. * Asynchronously copies src to dest. By default, dest is overwritten if it already exists.
  1523. * No arguments other than a possible exception are given to the callback function.
  1524. * Node.js makes no guarantees about the atomicity of the copy operation.
  1525. * If an error occurs after the destination file has been opened for writing, Node.js will attempt
  1526. * to remove the destination.
  1527. * @param src A path to the source file.
  1528. * @param dest A path to the destination file.
  1529. * @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.
  1530. */
  1531. function copyFile(src: PathLike, dest: PathLike, flags: number, callback: (err: NodeJS.ErrnoException | null) => void): void;
  1532. // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
  1533. namespace copyFile {
  1534. /**
  1535. * Asynchronously copies src to dest. By default, dest is overwritten if it already exists.
  1536. * No arguments other than a possible exception are given to the callback function.
  1537. * Node.js makes no guarantees about the atomicity of the copy operation.
  1538. * If an error occurs after the destination file has been opened for writing, Node.js will attempt
  1539. * to remove the destination.
  1540. * @param src A path to the source file.
  1541. * @param dest A path to the destination file.
  1542. * @param flags An optional integer that specifies the behavior of the copy operation.
  1543. * The only supported flag is fs.constants.COPYFILE_EXCL,
  1544. * which causes the copy operation to fail if dest already exists.
  1545. */
  1546. function __promisify__(src: PathLike, dst: PathLike, flags?: number): Promise<void>;
  1547. }
  1548. /**
  1549. * Synchronously copies src to dest. By default, dest is overwritten if it already exists.
  1550. * Node.js makes no guarantees about the atomicity of the copy operation.
  1551. * If an error occurs after the destination file has been opened for writing, Node.js will attempt
  1552. * to remove the destination.
  1553. * @param src A path to the source file.
  1554. * @param dest A path to the destination file.
  1555. * @param flags An optional integer that specifies the behavior of the copy operation.
  1556. * The only supported flag is fs.constants.COPYFILE_EXCL, which causes the copy operation to fail if dest already exists.
  1557. */
  1558. function copyFileSync(src: PathLike, dest: PathLike, flags?: number): void;
  1559. namespace promises {
  1560. interface FileHandle {
  1561. /**
  1562. * Gets the file descriptor for this file handle.
  1563. */
  1564. readonly fd: number;
  1565. /**
  1566. * Asynchronously append data to a file, creating the file if it does not exist. The underlying file will _not_ be closed automatically.
  1567. * The `FileHandle` must have been opened for appending.
  1568. * @param data The data to write. If something other than a `Buffer` or `Uint8Array` is provided, the value is coerced to a string.
  1569. * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
  1570. * If `encoding` is not supplied, the default of `'utf8'` is used.
  1571. * If `mode` is not supplied, the default of `0o666` is used.
  1572. * If `mode` is a string, it is parsed as an octal integer.
  1573. * If `flag` is not supplied, the default of `'a'` is used.
  1574. */
  1575. appendFile(data: any, options?: { encoding?: string | null, mode?: string | number, flag?: string | number } | string | null): Promise<void>;
  1576. /**
  1577. * Asynchronous fchown(2) - Change ownership of a file.
  1578. */
  1579. chown(uid: number, gid: number): Promise<void>;
  1580. /**
  1581. * Asynchronous fchmod(2) - Change permissions of a file.
  1582. * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
  1583. */
  1584. chmod(mode: string | number): Promise<void>;
  1585. /**
  1586. * Asynchronous fdatasync(2) - synchronize a file's in-core state with storage device.
  1587. */
  1588. datasync(): Promise<void>;
  1589. /**
  1590. * Asynchronous fsync(2) - synchronize a file's in-core state with the underlying storage device.
  1591. */
  1592. sync(): Promise<void>;
  1593. /**
  1594. * Asynchronously reads data from the file.
  1595. * The `FileHandle` must have been opened for reading.
  1596. * @param buffer The buffer that the data will be written to.
  1597. * @param offset The offset in the buffer at which to start writing.
  1598. * @param length The number of bytes to read.
  1599. * @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.
  1600. */
  1601. read<TBuffer extends Buffer | Uint8Array>(buffer: TBuffer, offset?: number | null, length?: number | null, position?: number | null): Promise<{ bytesRead: number, buffer: TBuffer }>;
  1602. /**
  1603. * Asynchronously reads the entire contents of a file. The underlying file will _not_ be closed automatically.
  1604. * The `FileHandle` must have been opened for reading.
  1605. * @param options An object that may contain an optional flag.
  1606. * If a flag is not provided, it defaults to `'r'`.
  1607. */
  1608. readFile(options?: { encoding?: null, flag?: string | number } | null): Promise<Buffer>;
  1609. /**
  1610. * Asynchronously reads the entire contents of a file. The underlying file will _not_ be closed automatically.
  1611. * The `FileHandle` must have been opened for reading.
  1612. * @param options An object that may contain an optional flag.
  1613. * If a flag is not provided, it defaults to `'r'`.
  1614. */
  1615. readFile(options: { encoding: BufferEncoding, flag?: string | number } | BufferEncoding): Promise<string>;
  1616. /**
  1617. * Asynchronously reads the entire contents of a file. The underlying file will _not_ be closed automatically.
  1618. * The `FileHandle` must have been opened for reading.
  1619. * @param options An object that may contain an optional flag.
  1620. * If a flag is not provided, it defaults to `'r'`.
  1621. */
  1622. readFile(options?: { encoding?: string | null, flag?: string | number } | string | null): Promise<string | Buffer>;
  1623. /**
  1624. * Asynchronous fstat(2) - Get file status.
  1625. */
  1626. stat(): Promise<Stats>;
  1627. /**
  1628. * Asynchronous ftruncate(2) - Truncate a file to a specified length.
  1629. * @param len If not specified, defaults to `0`.
  1630. */
  1631. truncate(len?: number): Promise<void>;
  1632. /**
  1633. * Asynchronously change file timestamps of the file.
  1634. * @param atime The last access time. If a string is provided, it will be coerced to number.
  1635. * @param mtime The last modified time. If a string is provided, it will be coerced to number.
  1636. */
  1637. utimes(atime: string | number | Date, mtime: string | number | Date): Promise<void>;
  1638. /**
  1639. * Asynchronously writes `buffer` to the file.
  1640. * The `FileHandle` must have been opened for writing.
  1641. * @param buffer The buffer that the data will be written to.
  1642. * @param offset The part of the buffer to be written. If not supplied, defaults to `0`.
  1643. * @param length The number of bytes to write. If not supplied, defaults to `buffer.length - offset`.
  1644. * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
  1645. */
  1646. write<TBuffer extends Buffer | Uint8Array>(buffer: TBuffer, offset?: number | null, length?: number | null, position?: number | null): Promise<{ bytesWritten: number, buffer: TBuffer }>;
  1647. /**
  1648. * Asynchronously writes `string` to the file.
  1649. * The `FileHandle` must have been opened for writing.
  1650. * It is unsafe to call `write()` multiple times on the same file without waiting for the `Promise`
  1651. * to be resolved (or rejected). For this scenario, `fs.createWriteStream` is strongly recommended.
  1652. * @param string A string to write. If something other than a string is supplied it will be coerced to a string.
  1653. * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
  1654. * @param encoding The expected string encoding.
  1655. */
  1656. write(data: any, position?: number | null, encoding?: string | null): Promise<{ bytesWritten: number, buffer: string }>;
  1657. /**
  1658. * Asynchronously writes data to a file, replacing the file if it already exists. The underlying file will _not_ be closed automatically.
  1659. * The `FileHandle` must have been opened for writing.
  1660. * It is unsafe to call `writeFile()` multiple times on the same file without waiting for the `Promise` to be resolved (or rejected).
  1661. * @param data The data to write. If something other than a `Buffer` or `Uint8Array` is provided, the value is coerced to a string.
  1662. * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
  1663. * If `encoding` is not supplied, the default of `'utf8'` is used.
  1664. * If `mode` is not supplied, the default of `0o666` is used.
  1665. * If `mode` is a string, it is parsed as an octal integer.
  1666. * If `flag` is not supplied, the default of `'w'` is used.
  1667. */
  1668. writeFile(data: any, options?: { encoding?: string | null, mode?: string | number, flag?: string | number } | string | null): Promise<void>;
  1669. /**
  1670. * Asynchronous close(2) - close a `FileHandle`.
  1671. */
  1672. close(): Promise<void>;
  1673. }
  1674. /**
  1675. * Asynchronously tests a user's permissions for the file specified by path.
  1676. * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
  1677. * URL support is _experimental_.
  1678. */
  1679. function access(path: PathLike, mode?: number): Promise<void>;
  1680. /**
  1681. * Asynchronously copies `src` to `dest`. By default, `dest` is overwritten if it already exists.
  1682. * Node.js makes no guarantees about the atomicity of the copy operation.
  1683. * If an error occurs after the destination file has been opened for writing, Node.js will attempt
  1684. * to remove the destination.
  1685. * @param src A path to the source file.
  1686. * @param dest A path to the destination file.
  1687. * @param flags An optional integer that specifies the behavior of the copy operation. The only
  1688. * supported flag is `fs.constants.COPYFILE_EXCL`, which causes the copy operation to fail if
  1689. * `dest` already exists.
  1690. */
  1691. function copyFile(src: PathLike, dest: PathLike, flags?: number): Promise<void>;
  1692. /**
  1693. * Asynchronous open(2) - open and possibly create a file.
  1694. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  1695. * @param mode A file mode. If a string is passed, it is parsed as an octal integer. If not
  1696. * supplied, defaults to `0o666`.
  1697. */
  1698. function open(path: PathLike, flags: string | number, mode?: string | number): Promise<FileHandle>;
  1699. /**
  1700. * Asynchronously reads data from the file referenced by the supplied `FileHandle`.
  1701. * @param handle A `FileHandle`.
  1702. * @param buffer The buffer that the data will be written to.
  1703. * @param offset The offset in the buffer at which to start writing.
  1704. * @param length The number of bytes to read.
  1705. * @param position The offset from the beginning of the file from which data should be read. If
  1706. * `null`, data will be read from the current position.
  1707. */
  1708. function read<TBuffer extends Buffer | Uint8Array>(
  1709. handle: FileHandle,
  1710. buffer: TBuffer,
  1711. offset?: number | null,
  1712. length?: number | null,
  1713. position?: number | null,
  1714. ): Promise<{ bytesRead: number, buffer: TBuffer }>;
  1715. /**
  1716. * Asynchronously writes `buffer` to the file referenced by the supplied `FileHandle`.
  1717. * It is unsafe to call `fsPromises.write()` multiple times on the same file without waiting for the `Promise`
  1718. * to be resolved (or rejected). For this scenario, `fs.createWriteStream` is strongly recommended.
  1719. * @param handle A `FileHandle`.
  1720. * @param buffer The buffer that the data will be written to.
  1721. * @param offset The part of the buffer to be written. If not supplied, defaults to `0`.
  1722. * @param length The number of bytes to write. If not supplied, defaults to `buffer.length - offset`.
  1723. * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
  1724. */
  1725. function write<TBuffer extends Buffer | Uint8Array>(
  1726. handle: FileHandle,
  1727. buffer: TBuffer,
  1728. offset?: number | null,
  1729. length?: number | null, position?: number | null): Promise<{ bytesWritten: number, buffer: TBuffer }>;
  1730. /**
  1731. * Asynchronously writes `string` to the file referenced by the supplied `FileHandle`.
  1732. * It is unsafe to call `fsPromises.write()` multiple times on the same file without waiting for the `Promise`
  1733. * to be resolved (or rejected). For this scenario, `fs.createWriteStream` is strongly recommended.
  1734. * @param handle A `FileHandle`.
  1735. * @param string A string to write. If something other than a string is supplied it will be coerced to a string.
  1736. * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
  1737. * @param encoding The expected string encoding.
  1738. */
  1739. function write(handle: FileHandle, string: any, position?: number | null, encoding?: string | null): Promise<{ bytesWritten: number, buffer: string }>;
  1740. /**
  1741. * Asynchronous rename(2) - Change the name or location of a file or directory.
  1742. * @param oldPath A path to a file. If a URL is provided, it must use the `file:` protocol.
  1743. * URL support is _experimental_.
  1744. * @param newPath A path to a file. If a URL is provided, it must use the `file:` protocol.
  1745. * URL support is _experimental_.
  1746. */
  1747. function rename(oldPath: PathLike, newPath: PathLike): Promise<void>;
  1748. /**
  1749. * Asynchronous truncate(2) - Truncate a file to a specified length.
  1750. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  1751. * @param len If not specified, defaults to `0`.
  1752. */
  1753. function truncate(path: PathLike, len?: number): Promise<void>;
  1754. /**
  1755. * Asynchronous ftruncate(2) - Truncate a file to a specified length.
  1756. * @param handle A `FileHandle`.
  1757. * @param len If not specified, defaults to `0`.
  1758. */
  1759. function ftruncate(handle: FileHandle, len?: number): Promise<void>;
  1760. /**
  1761. * Asynchronous rmdir(2) - delete a directory.
  1762. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  1763. */
  1764. function rmdir(path: PathLike): Promise<void>;
  1765. /**
  1766. * Asynchronous fdatasync(2) - synchronize a file's in-core state with storage device.
  1767. * @param handle A `FileHandle`.
  1768. */
  1769. function fdatasync(handle: FileHandle): Promise<void>;
  1770. /**
  1771. * Asynchronous fsync(2) - synchronize a file's in-core state with the underlying storage device.
  1772. * @param handle A `FileHandle`.
  1773. */
  1774. function fsync(handle: FileHandle): Promise<void>;
  1775. /**
  1776. * Asynchronous mkdir(2) - create a directory.
  1777. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  1778. * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
  1779. * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
  1780. */
  1781. function mkdir(path: PathLike, options?: number | string | MakeDirectoryOptions | null): Promise<void>;
  1782. /**
  1783. * Asynchronous readdir(3) - read a directory.
  1784. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  1785. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  1786. */
  1787. function readdir(path: PathLike, options?: { encoding?: BufferEncoding | null; withFileTypes?: false } | BufferEncoding | null): Promise<string[]>;
  1788. /**
  1789. * Asynchronous readdir(3) - read a directory.
  1790. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  1791. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  1792. */
  1793. function readdir(path: PathLike, options: { encoding: "buffer"; withFileTypes?: false } | "buffer"): Promise<Buffer[]>;
  1794. /**
  1795. * Asynchronous readdir(3) - read a directory.
  1796. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  1797. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  1798. */
  1799. function readdir(path: PathLike, options?: { encoding?: string | null; withFileTypes?: false } | string | null): Promise<string[] | Buffer[]>;
  1800. /**
  1801. * Asynchronous readdir(3) - read a directory.
  1802. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  1803. * @param options If called with `withFileTypes: true` the result data will be an array of Dirent.
  1804. */
  1805. function readdir(path: PathLike, options: { encoding?: string | null; withFileTypes: true }): Promise<Dirent[]>;
  1806. /**
  1807. * Asynchronous readlink(2) - read value of a symbolic link.
  1808. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  1809. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  1810. */
  1811. function readlink(path: PathLike, options?: { encoding?: BufferEncoding | null } | BufferEncoding | null): Promise<string>;
  1812. /**
  1813. * Asynchronous readlink(2) - read value of a symbolic link.
  1814. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  1815. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  1816. */
  1817. function readlink(path: PathLike, options: { encoding: "buffer" } | "buffer"): Promise<Buffer>;
  1818. /**
  1819. * Asynchronous readlink(2) - read value of a symbolic link.
  1820. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  1821. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  1822. */
  1823. function readlink(path: PathLike, options?: { encoding?: string | null } | string | null): Promise<string | Buffer>;
  1824. /**
  1825. * Asynchronous symlink(2) - Create a new symbolic link to an existing file.
  1826. * @param target A path to an existing file. If a URL is provided, it must use the `file:` protocol.
  1827. * @param path A path to the new symlink. If a URL is provided, it must use the `file:` protocol.
  1828. * @param type May be set to `'dir'`, `'file'`, or `'junction'` (default is `'file'`) and is only available on Windows (ignored on other platforms).
  1829. * When using `'junction'`, the `target` argument will automatically be normalized to an absolute path.
  1830. */
  1831. function symlink(target: PathLike, path: PathLike, type?: string | null): Promise<void>;
  1832. /**
  1833. * Asynchronous fstat(2) - Get file status.
  1834. * @param handle A `FileHandle`.
  1835. */
  1836. function fstat(handle: FileHandle): Promise<Stats>;
  1837. /**
  1838. * Asynchronous lstat(2) - Get file status. Does not dereference symbolic links.
  1839. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  1840. */
  1841. function lstat(path: PathLike): Promise<Stats>;
  1842. /**
  1843. * Asynchronous stat(2) - Get file status.
  1844. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  1845. */
  1846. function stat(path: PathLike): Promise<Stats>;
  1847. /**
  1848. * Asynchronous link(2) - Create a new link (also known as a hard link) to an existing file.
  1849. * @param existingPath A path to a file. If a URL is provided, it must use the `file:` protocol.
  1850. * @param newPath A path to a file. If a URL is provided, it must use the `file:` protocol.
  1851. */
  1852. function link(existingPath: PathLike, newPath: PathLike): Promise<void>;
  1853. /**
  1854. * Asynchronous unlink(2) - delete a name and possibly the file it refers to.
  1855. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  1856. */
  1857. function unlink(path: PathLike): Promise<void>;
  1858. /**
  1859. * Asynchronous fchmod(2) - Change permissions of a file.
  1860. * @param handle A `FileHandle`.
  1861. * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
  1862. */
  1863. function fchmod(handle: FileHandle, mode: string | number): Promise<void>;
  1864. /**
  1865. * Asynchronous chmod(2) - Change permissions of a file.
  1866. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  1867. * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
  1868. */
  1869. function chmod(path: PathLike, mode: string | number): Promise<void>;
  1870. /**
  1871. * Asynchronous lchmod(2) - Change permissions of a file. Does not dereference symbolic links.
  1872. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  1873. * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
  1874. */
  1875. function lchmod(path: PathLike, mode: string | number): Promise<void>;
  1876. /**
  1877. * Asynchronous lchown(2) - Change ownership of a file. Does not dereference symbolic links.
  1878. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  1879. */
  1880. function lchown(path: PathLike, uid: number, gid: number): Promise<void>;
  1881. /**
  1882. * Asynchronous fchown(2) - Change ownership of a file.
  1883. * @param handle A `FileHandle`.
  1884. */
  1885. function fchown(handle: FileHandle, uid: number, gid: number): Promise<void>;
  1886. /**
  1887. * Asynchronous chown(2) - Change ownership of a file.
  1888. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  1889. */
  1890. function chown(path: PathLike, uid: number, gid: number): Promise<void>;
  1891. /**
  1892. * Asynchronously change file timestamps of the file referenced by the supplied path.
  1893. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  1894. * @param atime The last access time. If a string is provided, it will be coerced to number.
  1895. * @param mtime The last modified time. If a string is provided, it will be coerced to number.
  1896. */
  1897. function utimes(path: PathLike, atime: string | number | Date, mtime: string | number | Date): Promise<void>;
  1898. /**
  1899. * Asynchronously change file timestamps of the file referenced by the supplied `FileHandle`.
  1900. * @param handle A `FileHandle`.
  1901. * @param atime The last access time. If a string is provided, it will be coerced to number.
  1902. * @param mtime The last modified time. If a string is provided, it will be coerced to number.
  1903. */
  1904. function futimes(handle: FileHandle, atime: string | number | Date, mtime: string | number | Date): Promise<void>;
  1905. /**
  1906. * Asynchronous realpath(3) - return the canonicalized absolute pathname.
  1907. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  1908. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  1909. */
  1910. function realpath(path: PathLike, options?: { encoding?: BufferEncoding | null } | BufferEncoding | null): Promise<string>;
  1911. /**
  1912. * Asynchronous realpath(3) - return the canonicalized absolute pathname.
  1913. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  1914. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  1915. */
  1916. function realpath(path: PathLike, options: { encoding: "buffer" } | "buffer"): Promise<Buffer>;
  1917. /**
  1918. * Asynchronous realpath(3) - return the canonicalized absolute pathname.
  1919. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  1920. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  1921. */
  1922. function realpath(path: PathLike, options?: { encoding?: string | null } | string | null): Promise<string | Buffer>;
  1923. /**
  1924. * Asynchronously creates a unique temporary directory.
  1925. * Generates six random characters to be appended behind a required `prefix` to create a unique temporary directory.
  1926. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  1927. */
  1928. function mkdtemp(prefix: string, options?: { encoding?: BufferEncoding | null } | BufferEncoding | null): Promise<string>;
  1929. /**
  1930. * Asynchronously creates a unique temporary directory.
  1931. * Generates six random characters to be appended behind a required `prefix` to create a unique temporary directory.
  1932. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  1933. */
  1934. function mkdtemp(prefix: string, options: { encoding: "buffer" } | "buffer"): Promise<Buffer>;
  1935. /**
  1936. * Asynchronously creates a unique temporary directory.
  1937. * Generates six random characters to be appended behind a required `prefix` to create a unique temporary directory.
  1938. * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
  1939. */
  1940. function mkdtemp(prefix: string, options?: { encoding?: string | null } | string | null): Promise<string | Buffer>;
  1941. /**
  1942. * Asynchronously writes data to a file, replacing the file if it already exists.
  1943. * It is unsafe to call `fsPromises.writeFile()` multiple times on the same file without waiting for the `Promise` to be resolved (or rejected).
  1944. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  1945. * URL support is _experimental_.
  1946. * If a `FileHandle` is provided, the underlying file will _not_ be closed automatically.
  1947. * @param data The data to write. If something other than a `Buffer` or `Uint8Array` is provided, the value is coerced to a string.
  1948. * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
  1949. * If `encoding` is not supplied, the default of `'utf8'` is used.
  1950. * If `mode` is not supplied, the default of `0o666` is used.
  1951. * If `mode` is a string, it is parsed as an octal integer.
  1952. * If `flag` is not supplied, the default of `'w'` is used.
  1953. */
  1954. function writeFile(path: PathLike | FileHandle, data: any, options?: { encoding?: string | null, mode?: string | number, flag?: string | number } | string | null): Promise<void>;
  1955. /**
  1956. * Asynchronously append data to a file, creating the file if it does not exist.
  1957. * @param file A path to a file. If a URL is provided, it must use the `file:` protocol.
  1958. * URL support is _experimental_.
  1959. * If a `FileHandle` is provided, the underlying file will _not_ be closed automatically.
  1960. * @param data The data to write. If something other than a `Buffer` or `Uint8Array` is provided, the value is coerced to a string.
  1961. * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
  1962. * If `encoding` is not supplied, the default of `'utf8'` is used.
  1963. * If `mode` is not supplied, the default of `0o666` is used.
  1964. * If `mode` is a string, it is parsed as an octal integer.
  1965. * If `flag` is not supplied, the default of `'a'` is used.
  1966. */
  1967. function appendFile(path: PathLike | FileHandle, data: any, options?: { encoding?: string | null, mode?: string | number, flag?: string | number } | string | null): Promise<void>;
  1968. /**
  1969. * Asynchronously reads the entire contents of a file.
  1970. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  1971. * If a `FileHandle` is provided, the underlying file will _not_ be closed automatically.
  1972. * @param options An object that may contain an optional flag.
  1973. * If a flag is not provided, it defaults to `'r'`.
  1974. */
  1975. function readFile(path: PathLike | FileHandle, options?: { encoding?: null, flag?: string | number } | null): Promise<Buffer>;
  1976. /**
  1977. * Asynchronously reads the entire contents of a file.
  1978. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  1979. * If a `FileHandle` is provided, the underlying file will _not_ be closed automatically.
  1980. * @param options An object that may contain an optional flag.
  1981. * If a flag is not provided, it defaults to `'r'`.
  1982. */
  1983. function readFile(path: PathLike | FileHandle, options: { encoding: BufferEncoding, flag?: string | number } | BufferEncoding): Promise<string>;
  1984. /**
  1985. * Asynchronously reads the entire contents of a file.
  1986. * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
  1987. * If a `FileHandle` is provided, the underlying file will _not_ be closed automatically.
  1988. * @param options An object that may contain an optional flag.
  1989. * If a flag is not provided, it defaults to `'r'`.
  1990. */
  1991. function readFile(path: PathLike | FileHandle, options?: { encoding?: string | null, flag?: string | number } | string | null): Promise<string | Buffer>;
  1992. }
  1993. }