Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fs.d.ts 117KB

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