fs.d.ts 116 KB

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