This repository has been archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
fs.d.ts
3606 lines (3598 loc) · 130 KB
/
fs.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* The `fs` module enables interacting with the file system in a
* way modeled on standard POSIX functions.
*
* To use the promise-based APIs:
*
* ```js
* import * as fs from 'fs/promises';
* ```
*
* To use the callback and sync APIs:
*
* ```js
* import * as fs from 'fs';
* ```
*
* All file system operations have synchronous and callback
* forms, and are accessible using both CommonJS syntax and ES6 Modules (ESM).
*/
declare module "fs" {
import type { SystemError } from "bun";
interface ObjectEncodingOptions {
encoding?: BufferEncoding | null | undefined;
}
type EncodingOption =
| ObjectEncodingOptions
| BufferEncoding
| undefined
| null;
type OpenMode = number | string;
type Mode = number | string;
type SimlinkType = "symlink" | "junction" | undefined | null;
interface StatsBase<T> {
isFile(): boolean;
isDirectory(): boolean;
isBlockDevice(): boolean;
isCharacterDevice(): boolean;
isSymbolicLink(): boolean;
isFIFO(): boolean;
isSocket(): boolean;
dev: T;
ino: T;
mode: T;
nlink: T;
uid: T;
gid: T;
rdev: T;
size: T;
blksize: T;
blocks: T;
atimeMs: T;
mtimeMs: T;
ctimeMs: T;
birthtimeMs: T;
atime: Date;
mtime: Date;
ctime: Date;
birthtime: Date;
}
interface Stats extends StatsBase<number> {}
/**
* A `fs.Stats` object provides information about a file.
*
* Objects returned from {@link stat}, {@link lstat} and {@link fstat} and
* their synchronous counterparts are of this type.
* If `bigint` in the `options` passed to those methods is true, the numeric values
* will be `bigint` instead of `number`, and the object will contain additional
* nanosecond-precision properties suffixed with `Ns`.
*
* ```console
* Stats {
* dev: 2114,
* ino: 48064969,
* mode: 33188,
* nlink: 1,
* uid: 85,
* gid: 100,
* rdev: 0,
* size: 527,
* blksize: 4096,
* blocks: 8,
* atimeMs: 1318289051000.1,
* mtimeMs: 1318289051000.1,
* ctimeMs: 1318289051000.1,
* birthtimeMs: 1318289051000.1,
* atime: Mon, 10 Oct 2011 23:24:11 GMT,
* mtime: Mon, 10 Oct 2011 23:24:11 GMT,
* ctime: Mon, 10 Oct 2011 23:24:11 GMT,
* birthtime: Mon, 10 Oct 2011 23:24:11 GMT }
* ```
*
* `bigint` version:
*
* ```console
* BigIntStats {
* dev: 2114n,
* ino: 48064969n,
* mode: 33188n,
* nlink: 1n,
* uid: 85n,
* gid: 100n,
* rdev: 0n,
* size: 527n,
* blksize: 4096n,
* blocks: 8n,
* atimeMs: 1318289051000n,
* mtimeMs: 1318289051000n,
* ctimeMs: 1318289051000n,
* birthtimeMs: 1318289051000n,
* atimeNs: 1318289051000000000n,
* mtimeNs: 1318289051000000000n,
* ctimeNs: 1318289051000000000n,
* birthtimeNs: 1318289051000000000n,
* atime: Mon, 10 Oct 2011 23:24:11 GMT,
* mtime: Mon, 10 Oct 2011 23:24:11 GMT,
* ctime: Mon, 10 Oct 2011 23:24:11 GMT,
* birthtime: Mon, 10 Oct 2011 23:24:11 GMT }
* ```
* @since v0.0.67
*/
class Stats {}
/**
* A representation of a directory entry, which can be a file or a subdirectory
* within the directory, as returned by reading from an `fs.Dir`. The
* directory entry is a combination of the file name and file type pairs.
*
* Additionally, when {@link readdir} or {@link readdirSync} is called with
* the `withFileTypes` option set to `true`, the resulting array is filled with `fs.Dirent` objects, rather than strings or `Buffer` s.
* @since v0.0.67
*/
class Dirent {
/**
* Returns `true` if the `fs.Dirent` object describes a regular file.
* @since v0.0.67
*/
isFile(): boolean;
/**
* Returns `true` if the `fs.Dirent` object describes a file system
* directory.
* @since v0.0.67
*/
isDirectory(): boolean;
/**
* Returns `true` if the `fs.Dirent` object describes a block device.
* @since v0.0.67
*/
isBlockDevice(): boolean;
/**
* Returns `true` if the `fs.Dirent` object describes a character device.
* @since v0.0.67
*/
isCharacterDevice(): boolean;
/**
* Returns `true` if the `fs.Dirent` object describes a symbolic link.
* @since v0.0.67
*/
isSymbolicLink(): boolean;
/**
* Returns `true` if the `fs.Dirent` object describes a first-in-first-out
* (FIFO) pipe.
* @since v0.0.67
*/
isFIFO(): boolean;
/**
* Returns `true` if the `fs.Dirent` object describes a socket.
* @since v0.0.67
*/
isSocket(): boolean;
/**
* The file name that this `fs.Dirent` object refers to. The type of this
* value is determined by the `options.encoding` passed to {@link readdir} or {@link readdirSync}.
* @since v0.0.67
*/
name: string;
}
/**
* Asynchronously rename file at `oldPath` to the pathname provided
* as `newPath`. In the case that `newPath` already exists, it will
* be overwritten. If there is a directory at `newPath`, an error will
* be raised instead. No arguments other than a possible exception are
* given to the completion callback.
*
* See also: [`rename(2)`](http://man7.org/linux/man-pages/man2/rename.2.html).
*
* ```js
* import { rename } from 'fs';
*
* rename('oldFile.txt', 'newFile.txt', (err) => {
* if (err) throw err;
* console.log('Rename complete!');
* });
* ```
* @since v0.0.67
*/
function rename(
oldPath: PathLike,
newPath: PathLike,
callback: NoParamCallback
): void;
// namespace rename {
// /**
// * Asynchronous rename(2) - Change the name or location of a file or directory.
// * @param oldPath A path to a file. If a URL is provided, it must use the `file:` protocol.
// * URL support is _experimental_.
// * @param newPath A path to a file. If a URL is provided, it must use the `file:` protocol.
// * URL support is _experimental_.
// */
// function __promisify__(oldPath: PathLike, newPath: PathLike): Promise<void>;
// }
/**
* Renames the file from `oldPath` to `newPath`. Returns `undefined`.
*
* See the POSIX [`rename(2)`](http://man7.org/linux/man-pages/man2/rename.2.html) documentation for more details.
* @since v0.0.67
*/
function renameSync(oldPath: PathLike, newPath: PathLike): void;
/**
* Truncates the file. No arguments other than a possible exception are
* given to the completion callback. A file descriptor can also be passed as the
* first argument. In this case, `fs.ftruncate()` is called.
*
* ```js
* import { truncate } from 'fs';
* // Assuming that 'path/file.txt' is a regular file.
* truncate('path/file.txt', (err) => {
* if (err) throw err;
* console.log('path/file.txt was truncated');
* });
* ```
*
* Passing a file descriptor is deprecated and may result in an error being thrown
* in the future.
*
* See the POSIX [`truncate(2)`](http://man7.org/linux/man-pages/man2/truncate.2.html) documentation for more details.
* @since v0.0.67
* @param [len=0]
*/
function truncate(
path: PathLike,
len: number | undefined | null,
callback: NoParamCallback
): void;
/**
* Asynchronous truncate(2) - Truncate a file to a specified length.
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
*/
function truncate(path: PathLike, callback: NoParamCallback): void;
// namespace truncate {
// /**
// * Asynchronous truncate(2) - Truncate a file to a specified length.
// * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
// * @param len If not specified, defaults to `0`.
// */
// function __promisify__(path: PathLike, len?: number | null): Promise<void>;
// }
/**
* Truncates the file. Returns `undefined`. A file descriptor can also be
* passed as the first argument. In this case, `fs.ftruncateSync()` is called.
*
* Passing a file descriptor is deprecated and may result in an error being thrown
* in the future.
* @since v0.0.67
* @param [len=0]
*/
function truncateSync(path: PathLike, len?: number | null): void;
/**
* Truncates the file descriptor. No arguments other than a possible exception are
* given to the completion callback.
*
* See the POSIX [`ftruncate(2)`](http://man7.org/linux/man-pages/man2/ftruncate.2.html) documentation for more detail.
*
* If the file referred to by the file descriptor was larger than `len` bytes, only
* the first `len` bytes will be retained in the file.
*
* For example, the following program retains only the first four bytes of the
* file:
*
* ```js
* import { open, close, ftruncate } from 'fs';
*
* function closeFd(fd) {
* close(fd, (err) => {
* if (err) throw err;
* });
* }
*
* open('temp.txt', 'r+', (err, fd) => {
* if (err) throw err;
*
* try {
* ftruncate(fd, 4, (err) => {
* closeFd(fd);
* if (err) throw err;
* });
* } catch (err) {
* closeFd(fd);
* if (err) throw err;
* }
* });
* ```
*
* If the file previously was shorter than `len` bytes, it is extended, and the
* extended part is filled with null bytes (`'\0'`):
*
* If `len` is negative then `0` will be used.
* @since v0.0.67
* @param [len=0]
*/
function ftruncate(
fd: number,
len: number | undefined | null,
callback: NoParamCallback
): void;
/**
* Asynchronous ftruncate(2) - Truncate a file to a specified length.
* @param fd A file descriptor.
*/
function ftruncate(fd: number, callback: NoParamCallback): void;
// namespace ftruncate {
// /**
// * Asynchronous ftruncate(2) - Truncate a file to a specified length.
// * @param fd A file descriptor.
// * @param len If not specified, defaults to `0`.
// */
// function __promisify__(fd: number, len?: number | null): Promise<void>;
// }
/**
* Truncates the file descriptor. Returns `undefined`.
*
* For detailed information, see the documentation of the asynchronous version of
* this API: {@link ftruncate}.
* @since v0.0.67
* @param [len=0]
*/
function ftruncateSync(fd: number, len?: number | null): void;
/**
* Asynchronously changes owner and group of a file. No arguments other than a
* possible exception are given to the completion callback.
*
* See the POSIX [`chown(2)`](http://man7.org/linux/man-pages/man2/chown.2.html) documentation for more detail.
* @since v0.0.67
*/
function chown(
path: PathLike,
uid: number,
gid: number,
callback: NoParamCallback
): void;
// namespace chown {
// /**
// * Asynchronous chown(2) - Change ownership of a file.
// * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
// */
// function __promisify__(
// path: PathLike,
// uid: number,
// gid: number
// ): Promise<void>;
// }
/**
* Synchronously changes owner and group of a file. Returns `undefined`.
* This is the synchronous version of {@link chown}.
*
* See the POSIX [`chown(2)`](http://man7.org/linux/man-pages/man2/chown.2.html) documentation for more detail.
* @since v0.0.67
*/
function chownSync(path: PathLike, uid: number, gid: number): void;
/**
* Sets the owner of the file. No arguments other than a possible exception are
* given to the completion callback.
*
* See the POSIX [`fchown(2)`](http://man7.org/linux/man-pages/man2/fchown.2.html) documentation for more detail.
* @since v0.0.67
*/
function fchown(
fd: number,
uid: number,
gid: number,
callback: NoParamCallback
): void;
// namespace fchown {
// /**
// * Asynchronous fchown(2) - Change ownership of a file.
// * @param fd A file descriptor.
// */
// function __promisify__(fd: number, uid: number, gid: number): Promise<void>;
// }
/**
* Sets the owner of the file. Returns `undefined`.
*
* See the POSIX [`fchown(2)`](http://man7.org/linux/man-pages/man2/fchown.2.html) documentation for more detail.
* @since v0.0.67
* @param uid The file's new owner's user id.
* @param gid The file's new group's group id.
*/
function fchownSync(fd: number, uid: number, gid: number): void;
/**
* Set the owner of the symbolic link. No arguments other than a possible
* exception are given to the completion callback.
*
* See the POSIX [`lchown(2)`](http://man7.org/linux/man-pages/man2/lchown.2.html) documentation for more detail.
*/
function lchown(
path: PathLike,
uid: number,
gid: number,
callback: NoParamCallback
): void;
// namespace lchown {
// /**
// * Asynchronous lchown(2) - Change ownership of a file. Does not dereference symbolic links.
// * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
// */
// function __promisify__(
// path: PathLike,
// uid: number,
// gid: number
// ): Promise<void>;
// }
/**
* Set the owner for the path. Returns `undefined`.
*
* See the POSIX [`lchown(2)`](http://man7.org/linux/man-pages/man2/lchown.2.html) documentation for more details.
* @param uid The file's new owner's user id.
* @param gid The file's new group's group id.
*/
function lchownSync(path: PathLike, uid: number, gid: number): void;
/**
* Changes the access and modification times of a file in the same way as {@link utimes}, with the difference that if the path refers to a symbolic
* link, then the link is not dereferenced: instead, the timestamps of the
* symbolic link itself are changed.
*
* No arguments other than a possible exception are given to the completion
* callback.
* @since v0.0.67
*/
function lutimes(
path: PathLike,
atime: TimeLike,
mtime: TimeLike,
callback: NoParamCallback
): void;
// namespace lutimes {
// /**
// * Changes the access and modification times of a file in the same way as `fsPromises.utimes()`,
// * with the difference that if the path refers to a symbolic link, then the link is not
// * dereferenced: instead, the timestamps of the symbolic link itself are changed.
// * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
// * @param atime The last access time. If a string is provided, it will be coerced to number.
// * @param mtime The last modified time. If a string is provided, it will be coerced to number.
// */
// function __promisify__(
// path: PathLike,
// atime: TimeLike,
// mtime: TimeLike
// ): Promise<void>;
// }
/**
* Change the file system timestamps of the symbolic link referenced by `path`.
* Returns `undefined`, or throws an exception when parameters are incorrect or
* the operation fails. This is the synchronous version of {@link lutimes}.
* @since v0.0.67
*/
function lutimesSync(path: PathLike, atime: TimeLike, mtime: TimeLike): void;
/**
* Asynchronously changes the permissions of a file. No arguments other than a
* possible exception are given to the completion callback.
*
* See the POSIX [`chmod(2)`](http://man7.org/linux/man-pages/man2/chmod.2.html) documentation for more detail.
*
* ```js
* import { chmod } from 'fs';
*
* chmod('my_file.txt', 0o775, (err) => {
* if (err) throw err;
* console.log('The permissions for file "my_file.txt" have been changed!');
* });
* ```
* @since v0.0.67
*/
function chmod(path: PathLike, mode: Mode, callback: NoParamCallback): void;
// namespace chmod {
// /**
// * Asynchronous chmod(2) - Change permissions of a file.
// * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
// * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
// */
// function __promisify__(path: PathLike, mode: Mode): Promise<void>;
// }
/**
* For detailed information, see the documentation of the asynchronous version of
* this API: {@link chmod}.
*
* See the POSIX [`chmod(2)`](http://man7.org/linux/man-pages/man2/chmod.2.html) documentation for more detail.
* @since v0.0.67
*/
function chmodSync(path: PathLike, mode: Mode): void;
/**
* Sets the permissions on the file. No arguments other than a possible exception
* are given to the completion callback.
*
* See the POSIX [`fchmod(2)`](http://man7.org/linux/man-pages/man2/fchmod.2.html) documentation for more detail.
* @since v0.0.67
*/
function fchmod(fd: number, mode: Mode, callback: NoParamCallback): void;
// namespace fchmod {
// /**
// * Asynchronous fchmod(2) - Change permissions of a file.
// * @param fd A file descriptor.
// * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
// */
// function __promisify__(fd: number, mode: Mode): Promise<void>;
// }
/**
* Sets the permissions on the file. Returns `undefined`.
*
* See the POSIX [`fchmod(2)`](http://man7.org/linux/man-pages/man2/fchmod.2.html) documentation for more detail.
* @since v0.0.67
*/
function fchmodSync(fd: number, mode: Mode): void;
/**
* Changes the permissions on a symbolic link. No arguments other than a possible
* exception are given to the completion callback.
*
* This method is only implemented on macOS.
*
* See the POSIX [`lchmod(2)`](https://www.freebsd.org/cgi/man.cgi?query=lchmod&sektion=2) documentation for more detail.
* @deprecated Since v0.4.7
*/
function lchmod(path: PathLike, mode: Mode, callback: NoParamCallback): void;
// /** @deprecated */
// namespace lchmod {
// /**
// * Asynchronous lchmod(2) - Change permissions of a file. Does not dereference symbolic links.
// * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
// * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
// */
// function __promisify__(path: PathLike, mode: Mode): Promise<void>;
// }
/**
* Changes the permissions on a symbolic link. Returns `undefined`.
*
* This method is only implemented on macOS.
*
* See the POSIX [`lchmod(2)`](https://www.freebsd.org/cgi/man.cgi?query=lchmod&sektion=2) documentation for more detail.
* @deprecated Since v0.4.7
*/
function lchmodSync(path: PathLike, mode: Mode): void;
/**
* Asynchronous [`stat(2)`](http://man7.org/linux/man-pages/man2/stat.2.html). The callback gets two arguments `(err, stats)` where`stats` is an `fs.Stats` object.
*
* In case of an error, the `err.code` will be one of `Common System Errors`.
*
* Using `fs.stat()` to check for the existence of a file before calling`fs.open()`, `fs.readFile()` or `fs.writeFile()` is not recommended.
* Instead, user code should open/read/write the file directly and handle the
* error raised if the file is not available.
*
* To check if a file exists without manipulating it afterwards, {@link access} is recommended.
*
* For example, given the following directory structure:
*
* ```text
* - txtDir
* -- file.txt
* - app.js
* ```
*
* The next program will check for the stats of the given paths:
*
* ```js
* import { stat } from 'fs';
*
* const pathsToCheck = ['./txtDir', './txtDir/file.txt'];
*
* for (let i = 0; i < pathsToCheck.length; i++) {
* stat(pathsToCheck[i], (err, stats) => {
* console.log(stats.isDirectory());
* console.log(stats);
* });
* }
* ```
*
* The resulting output will resemble:
*
* ```console
* true
* Stats {
* dev: 16777220,
* mode: 16877,
* nlink: 3,
* uid: 501,
* gid: 20,
* rdev: 0,
* blksize: 4096,
* ino: 14214262,
* size: 96,
* blocks: 0,
* atimeMs: 1561174653071.963,
* mtimeMs: 1561174614583.3518,
* ctimeMs: 1561174626623.5366,
* birthtimeMs: 1561174126937.2893,
* atime: 2019-06-22T03:37:33.072Z,
* mtime: 2019-06-22T03:36:54.583Z,
* ctime: 2019-06-22T03:37:06.624Z,
* birthtime: 2019-06-22T03:28:46.937Z
* }
* false
* Stats {
* dev: 16777220,
* mode: 33188,
* nlink: 1,
* uid: 501,
* gid: 20,
* rdev: 0,
* blksize: 4096,
* ino: 14214074,
* size: 8,
* blocks: 8,
* atimeMs: 1561174616618.8555,
* mtimeMs: 1561174614584,
* ctimeMs: 1561174614583.8145,
* birthtimeMs: 1561174007710.7478,
* atime: 2019-06-22T03:36:56.619Z,
* mtime: 2019-06-22T03:36:54.584Z,
* ctime: 2019-06-22T03:36:54.584Z,
* birthtime: 2019-06-22T03:26:47.711Z
* }
* ```
* @since v0.0.67
*/
function stat(
path: PathLike,
callback: (err: SystemError | null, stats: Stats) => void
): void;
function stat(
path: PathLike,
options:
| (StatOptions & {
bigint?: false | undefined;
})
| undefined,
callback: (err: SystemError | null, stats: Stats) => void
): void;
function stat(
path: PathLike,
options: StatOptions & {
bigint: true;
},
callback: (err: SystemError | null, stats: BigIntStats) => void
): void;
function stat(
path: PathLike,
options: StatOptions | undefined,
callback: (err: SystemError | null, stats: Stats | BigIntStats) => void
): void;
// namespace stat {
// /**
// * Asynchronous stat(2) - Get file status.
// * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
// */
// function __promisify__(
// path: PathLike,
// options?: StatOptions & {
// bigint?: false | undefined;
// }
// ): Promise<Stats>;
// function __promisify__(
// path: PathLike,
// options: StatOptions & {
// bigint: true;
// }
// ): Promise<BigIntStats>;
// function __promisify__(
// path: PathLike,
// options?: StatOptions
// ): Promise<Stats | BigIntStats>;
// }
// tslint:disable-next-line:unified-signatures
interface StatSyncFn extends Function {
// tslint:disable-next-line:unified-signatures
(path: PathLike, options?: undefined): Stats;
(
path: PathLike,
options?: StatSyncOptions & {
bigint?: false | undefined;
throwIfNoEntry: false;
}
): Stats | undefined;
(
path: PathLike,
options: StatSyncOptions & {
bigint: true;
throwIfNoEntry: false;
}
): BigIntStats | undefined;
// tslint:disable-next-line:unified-signatures
(
path: PathLike,
// tslint:disable-next-line:unified-signatures
options?: StatSyncOptions & {
bigint?: false | undefined;
}
): Stats;
(
path: PathLike,
options: StatSyncOptions & {
bigint: true;
}
): BigIntStats;
(
path: PathLike,
options: StatSyncOptions & {
bigint: boolean;
throwIfNoEntry?: false | undefined;
}
): Stats | BigIntStats;
(path: PathLike, options?: StatSyncOptions):
| Stats
| BigIntStats
| undefined;
}
/**
* Synchronous stat(2) - Get file status.
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
*/
var statSync: StatSyncFn;
/**
* Invokes the callback with the `fs.Stats` for the file descriptor.
*
* See the POSIX [`fstat(2)`](http://man7.org/linux/man-pages/man2/fstat.2.html) documentation for more detail.
* @since v0.0.67
*/
function fstat(
fd: number,
callback: (err: SystemError | null, stats: Stats) => void
): void;
function fstat(
fd: number,
options:
| (StatOptions & {
bigint?: false | undefined;
})
| undefined,
callback: (err: SystemError | null, stats: Stats) => void
): void;
function fstat(
fd: number,
options: StatOptions & {
bigint: true;
},
callback: (err: SystemError | null, stats: BigIntStats) => void
): void;
function fstat(
fd: number,
options: StatOptions | undefined,
callback: (err: SystemError | null, stats: Stats | BigIntStats) => void
): void;
// namespace fstat {
// /**
// * Asynchronous fstat(2) - Get file status.
// * @param fd A file descriptor.
// */
// function __promisify__(
// fd: number,
// options?: StatOptions & {
// bigint?: false | undefined;
// }
// ): Promise<Stats>;
// function __promisify__(
// fd: number,
// options: StatOptions & {
// bigint: true;
// }
// ): Promise<BigIntStats>;
// function __promisify__(
// fd: number,
// options?: StatOptions
// ): Promise<Stats | BigIntStats>;
// }
/**
* Retrieves the `fs.Stats` for the file descriptor.
*
* See the POSIX [`fstat(2)`](http://man7.org/linux/man-pages/man2/fstat.2.html) documentation for more detail.
* @since v0.0.67
*/
function fstatSync(
fd: number,
options?: StatOptions & {
bigint?: false | undefined;
}
): Stats;
function fstatSync(
fd: number,
options: StatOptions & {
bigint: true;
}
): BigIntStats;
function fstatSync(fd: number, options?: StatOptions): Stats | BigIntStats;
/**
* Retrieves the `fs.Stats` for the symbolic link referred to by the path.
* The callback gets two arguments `(err, stats)` where `stats` is a `fs.Stats` object. `lstat()` is identical to `stat()`, except that if `path` is a symbolic
* link, then the link itself is stat-ed, not the file that it refers to.
*
* See the POSIX [`lstat(2)`](http://man7.org/linux/man-pages/man2/lstat.2.html) documentation for more details.
* @since v0.0.67
*/
function lstat(
path: PathLike,
callback: (err: SystemError | null, stats: Stats) => void
): void;
function lstat(
path: PathLike,
options:
| (StatOptions & {
bigint?: false | undefined;
})
| undefined,
callback: (err: SystemError | null, stats: Stats) => void
): void;
function lstat(
path: PathLike,
options: StatOptions & {
bigint: true;
},
callback: (err: SystemError | null, stats: BigIntStats) => void
): void;
function lstat(
path: PathLike,
options: StatOptions | undefined,
callback: (err: SystemError | null, stats: Stats | BigIntStats) => void
): void;
// namespace lstat {
// /**
// * Asynchronous lstat(2) - Get file status. Does not dereference symbolic links.
// * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
// */
// function __promisify__(
// path: PathLike,
// options?: StatOptions & {
// bigint?: false | undefined;
// }
// ): Promise<Stats>;
// function __promisify__(
// path: PathLike,
// options: StatOptions & {
// bigint: true;
// }
// ): Promise<BigIntStats>;
// function __promisify__(
// path: PathLike,
// options?: StatOptions
// ): Promise<Stats | BigIntStats>;
// }
/**
* Synchronous lstat(2) - Get file status. Does not dereference symbolic links.
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
*/
var lstatSync: StatSyncFn;
/**
* Creates a new link from the `existingPath` to the `newPath`. See the POSIX [`link(2)`](http://man7.org/linux/man-pages/man2/link.2.html) documentation for more detail. No arguments other than
* a possible
* exception are given to the completion callback.
* @since v0.0.67
*/
function link(
existingPath: PathLike,
newPath: PathLike,
callback: NoParamCallback
): void;
// namespace link {
// /**
// * Asynchronous link(2) - Create a new link (also known as a hard link) to an existing file.
// * @param existingPath A path to a file. If a URL is provided, it must use the `file:` protocol.
// * @param newPath A path to a file. If a URL is provided, it must use the `file:` protocol.
// */
// function __promisify__(
// existingPath: PathLike,
// newPath: PathLike
// ): Promise<void>;
// }
/**
* Creates a new link from the `existingPath` to the `newPath`. See the POSIX [`link(2)`](http://man7.org/linux/man-pages/man2/link.2.html) documentation for more detail. Returns `undefined`.
* @since v0.0.67
*/
function linkSync(existingPath: PathLike, newPath: PathLike): void;
/**
* Creates the link called `path` pointing to `target`. No arguments other than a
* possible exception are given to the completion callback.
*
* See the POSIX [`symlink(2)`](http://man7.org/linux/man-pages/man2/symlink.2.html) documentation for more details.
*
* The `type` argument is only available on Windows and ignored on other platforms.
* It can be set to `'dir'`, `'file'`, or `'junction'`. If the `type` argument is
* not set, Node.js will autodetect `target` type and use `'file'` or `'dir'`. If
* the `target` does not exist, `'file'` will be used. Windows junction points
* require the destination path to be absolute. When using `'junction'`, the`target` argument will automatically be normalized to absolute path.
*
* Relative targets are relative to the link’s parent directory.
*
* ```js
* import { symlink } from 'fs';
*
* symlink('./mew', './example/mewtwo', callback);
* ```
*
* The above example creates a symbolic link `mewtwo` in the `example` which points
* to `mew` in the same directory:
*
* ```bash
* $ tree example/
* example/
* ├── mew
* └── mewtwo -> ./mew
* ```
* @since v0.0.67
*/
function symlink(
target: PathLike,
path: PathLike,
type: SimlinkType,
callback: NoParamCallback
): void;
/**
* Asynchronous symlink(2) - Create a new symbolic link to an existing file.
* @param target A path to an existing file. If a URL is provided, it must use the `file:` protocol.
* @param path A path to the new symlink. If a URL is provided, it must use the `file:` protocol.
*/
function symlink(
target: PathLike,
path: PathLike,
callback: NoParamCallback
): void;
// namespace symlink {
// /**
// * Asynchronous symlink(2) - Create a new symbolic link to an existing file.
// * @param target A path to an existing file. If a URL is provided, it must use the `file:` protocol.
// * @param path A path to the new symlink. If a URL is provided, it must use the `file:` protocol.
// * @param type May be set to `'dir'`, `'file'`, or `'junction'` (default is `'file'`) and is only available on Windows (ignored on other platforms).
// * When using `'junction'`, the `target` argument will automatically be normalized to an absolute path.
// */
// function __promisify__(
// target: PathLike,
// path: PathLike,
// type?: string | null
// ): Promise<void>;
// type Type = "dir" | "file" | "junction";
// }
/**
* Returns `undefined`.
*
* For detailed information, see the documentation of the asynchronous version of
* this API: {@link symlink}.
* @since v0.0.67
*/
function symlinkSync(
target: PathLike,
path: PathLike,
type?: SimlinkType
): void;
/**
* Reads the contents of the symbolic link referred to by `path`. The callback gets
* two arguments `(err, linkString)`.
*
* See the POSIX [`readlink(2)`](http://man7.org/linux/man-pages/man2/readlink.2.html) documentation for more details.
*
* The optional `options` argument can be a string specifying an encoding, or an
* object with an `encoding` property specifying the character encoding to use for
* the link path passed to the callback. If the `encoding` is set to `'buffer'`,
* the link path returned will be passed as a `Buffer` object.
* @since v0.0.67
*/
function readlink(
path: PathLike,
options: EncodingOption,
callback: (err: SystemError | null, linkString: string) => void
): void;
/**
* Asynchronous readlink(2) - read value of a symbolic link.
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
*/
// tslint:disable-next-line:unified-signatures
function readlink(
path: PathLike,
options: BufferEncodingOption,
callback: (err: SystemError | null, linkString: Buffer) => void
): void;
/**
* Asynchronous readlink(2) - read value of a symbolic link.
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
*/
// tslint:disable-next-line:unified-signatures
function readlink(
path: PathLike,
options: EncodingOption,
// tslint:disable-next-line:unified-signatures
callback: (err: SystemError | null, linkString: string | Buffer) => void