-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathFs.re
519 lines (454 loc) · 16.9 KB
/
Fs.re
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
module Dirent = {
type t;
[@bs.send] external isBlockDevice: t => bool = "isBlockDevice";
[@bs.send] external isCharacterDevice: t => bool = "isCharacterDevice";
[@bs.send] external isDirectory: t => bool = "isDirectory";
[@bs.send] external isFIFO: t => bool = "isFIFO";
[@bs.send] external isFile: t => bool = "isFile";
[@bs.send] external isSocket: t => bool = "isSocket";
[@bs.send] external isSymbolicLink: t => bool = "isSymbolicLink";
[@bs.get] external name: t => string = "name";
};
module Dir = {
type t;
[@bs.send] external close: t => Js.Promise.t(unit) = "close";
[@bs.send]
external closeWithCallback: (t, Js.nullable(Js.Exn.t) => unit) => unit =
"close";
[@bs.send] external closeSync: t => unit = "closeSync";
[@bs.get] external path: t => string = "path";
[@bs.send]
external read: t => Js.Promise.t(Js.nullable(Dirent.t)) = "read";
[@bs.send]
external readWithCallback:
(t, (Js.Exn.t, Js.nullable(Dirent.t)) => unit) => unit =
"read";
[@bs.send] external readSync: t => Js.nullable(Dirent.t) = "readSync";
};
module Stats = {
type t = {
dev: int,
ino: int,
mode: int,
nlink: int,
uid: int,
gid: int,
rdev: int,
size: int,
blksize: int,
blocks: int,
atimeMs: float,
mtimeMs: float,
ctimeMs: float,
birthtimeMs: float,
atime: string,
mtime: string,
ctime: string,
birthtime: string,
};
/** `isFile(stats)` Returns true if the `stats` object describes a file. */
[@bs.send]
external isFile: t => bool = "isFile";
/** `isDirectory(stats)` Returns true if the `stats` object describes a directory. */
[@bs.send]
external isDirectory: t => bool = "isDirectory";
/** `isBlockDevice(stats)` Returns true if the `stats` object describes a block device. */
[@bs.send]
external isBlockDevice: t => bool = "isBlockDevice";
/** `isBlockDevice(stats)` Returns true if the `stats` object describes a character device. */
[@bs.send]
external isCharacterDevice: t => bool = "isCharacterDevice";
/** `isBlockDevice(stats)` Returns true if the `stats` object describes a symbolic link. */
[@bs.send]
external isSymbolicLink: t => bool = "isSymbolicLink";
/** `isBlockDevice(stats)` Returns true if the `stats` object describes a first-in-first-out (FIFO) pipe. */
[@bs.send]
external isFIFO: t => bool = "isFIFO";
/** `isBlockDevice(stats)` Returns true if the `stats` object describes a socket. */
[@bs.send]
external isSocket: t => bool = "isSocket";
};
module Constants = {
type t = pri int;
/** Bitwise 'or' i.e. JavaScript [x | y] */
external (lor): (t, t) => t = "%orint";
[@text "{1 File Access Constants}"];
[@bs.module "fs"] [@bs.scope "constants"] external f_ok: t = "F_OK";
[@bs.module "fs"] [@bs.scope "constants"] external w_ok: t = "W_OK";
[@bs.module "fs"] [@bs.scope "constants"] external r_ok: t = "R_OK";
[@bs.module "fs"] [@bs.scope "constants"] external x_ok: t = "X_OK";
[@text "{1 File Copy Constants}"];
[@bs.module "fs"] [@bs.scope "constants"] external copyfile_excl: t = "COPYFILE_EXCL";
[@bs.module "fs"] [@bs.scope "constants"] external copyfile_ficlone: t = "COPYFILE_FICLONE";
[@bs.module "fs"] [@bs.scope "constants"] external copyfile_ficlone_force: t = "COPYFILE_FICLONE_FORCE";
[@text "{1 File Open Constants}"];
[@bs.module "fs"] [@bs.scope "constants"] external o_rdonly: t = "O_RDONLY";
[@bs.module "fs"] [@bs.scope "constants"] external o_wronly: t = "O_WRONLY";
[@bs.module "fs"] [@bs.scope "constants"] external o_rdwr: t = "O_RDWR";
[@bs.module "fs"] [@bs.scope "constants"] external o_creat: t = "O_CREAT";
[@bs.module "fs"] [@bs.scope "constants"] external o_excl: t = "O_EXCL";
[@bs.module "fs"] [@bs.scope "constants"] external o_noctty: t = "O_NOCTTY";
[@bs.module "fs"] [@bs.scope "constants"] external o_trunc: t = "O_TRUNC";
[@bs.module "fs"] [@bs.scope "constants"] external o_append: t = "O_APPEND";
[@bs.module "fs"] [@bs.scope "constants"] external o_directory: t = "O_DIRECTORY";
[@bs.module "fs"] [@bs.scope "constants"] external o_noatime: t = "O_NOATIME";
[@bs.module "fs"] [@bs.scope "constants"] external o_nofollow: t = "O_NOFOLLOW";
[@bs.module "fs"] [@bs.scope "constants"] external o_sync: t = "O_SYNC";
[@bs.module "fs"] [@bs.scope "constants"] external o_dsync: t = "O_DSYNC";
[@bs.module "fs"] [@bs.scope "constants"] external o_symlink: t = "O_SYMLINK";
[@bs.module "fs"] [@bs.scope "constants"] external o_direct: t = "O_DIRECT";
[@bs.module "fs"] [@bs.scope "constants"] external o_nonblock: t = "O_NONBLOCK";
[@text "{1 File Type Constants}"];
[@bs.module "fs"] [@bs.scope "constants"] external s_ifmt: t = "S_IFMT";
[@bs.module "fs"] [@bs.scope "constants"] external s_ifreg: t = "S_IFREG";
[@bs.module "fs"] [@bs.scope "constants"] external s_ifdir: t = "S_IFDIR";
[@bs.module "fs"] [@bs.scope "constants"] external s_ifchr: t = "S_IFCHR";
[@bs.module "fs"] [@bs.scope "constants"] external s_ifblk: t = "S_IFBLK";
[@bs.module "fs"] [@bs.scope "constants"] external s_ififo: t = "S_IFIFO";
[@bs.module "fs"] [@bs.scope "constants"] external s_iflnk: t = "S_IFLNK";
[@bs.module "fs"] [@bs.scope "constants"] external s_ifsock: t = "S_IFSOCK";
[@text "{1 File Mode Constants}"];
[@bs.module "fs"] [@bs.scope "constants"] external s_irwxu: t = "S_IRWXU";
[@bs.module "fs"] [@bs.scope "constants"] external s_irusr: t = "S_IRUSR";
[@bs.module "fs"] [@bs.scope "constants"] external s_iwusr: t = "S_IWUSR";
[@bs.module "fs"] [@bs.scope "constants"] external s_ixusr: t = "S_IXUSR";
[@bs.module "fs"] [@bs.scope "constants"] external s_irwxg: t = "S_IRWXG";
[@bs.module "fs"] [@bs.scope "constants"] external s_irgrp: t = "S_IRGRP";
[@bs.module "fs"] [@bs.scope "constants"] external s_iwgrp: t = "S_IWGRP";
[@bs.module "fs"] [@bs.scope "constants"] external s_ixgrp: t = "S_IXGRP";
[@bs.module "fs"] [@bs.scope "constants"] external s_irwxo: t = "S_IRWXO";
[@bs.module "fs"] [@bs.scope "constants"] external s_iroth: t = "S_IROTH";
[@bs.module "fs"] [@bs.scope "constants"] external s_iwoth: t = "S_IWOTH";
[@bs.module "fs"] [@bs.scope "constants"] external s_ixoth: t = "S_IXOTH";
};
module Flag: {
type t = pri string;
[@bs.inline "r"]
let read: t;
[@bs.inline "r+"]
let readWrite: t;
[@bs.inline "rs+"]
let readWriteSync: t;
[@bs.inline "w"]
let write: t;
[@bs.inline "wx"]
let writeFailIfExists: t;
[@bs.inline "w+"]
let writeRead: t;
[@bs.inline "wx+"]
let writeReadFailIfExists: t;
[@bs.inline "a"]
let append: t;
[@bs.inline "ax"]
let appendFailIfExists: t;
[@bs.inline "a+"]
let appendRead: t;
[@bs.inline "ax+"]
let appendReadFailIfExists: t;
} = {
type t = string;
[@bs.inline "r"]
let read = "r";
[@bs.inline "r+"]
let readWrite = "r+";
[@bs.inline "rs+"]
let readWriteSync = "rs+";
[@bs.inline "w"]
let write = "w";
[@bs.inline "wx"]
let writeFailIfExists = "wx";
[@bs.inline "w+"]
let writeRead = "w+";
[@bs.inline "wx+"]
let writeReadFailIfExists = "wx+";
[@bs.inline "a"]
let append = "a";
[@bs.inline "ax"]
let appendFailIfExists = "ax";
[@bs.inline "a+"]
let appendRead = "a+";
[@bs.inline "ax+"]
let appendReadFailIfExists = "ax+";
};
type fd = pri int;
type writeFileOptions;
[@bs.obj]
external writeFileOptions:
(~mode: int=?, ~flag: string=?, unit) => writeFileOptions;
type appendFileOptions;
[@bs.obj]
external appendFileOptions:
(~mode: int=?, ~flag: Flag.t=?, unit) => appendFileOptions;
type readFileOptions;
[@bs.obj] external readFileOptions: (~flag: Flag.t=?, unit) => readFileOptions;
/**
* `readdirSync(path)`
* Reads the contents of a directory, returning an array of strings representing
* the paths of files and sub-directories. **Execution is synchronous and blocking**.
*/
[@bs.module "fs"]
external readdirSync: string => array(string) = "readdirSync";
/**
* `renameSync(~oldPath, ~newPath)
* Renames/moves the file located at `~oldPath` to `~newPath`. **Execution is
* synchronous and blocking**.
*/
[@bs.module "fs"]
external renameSync: (~from: string, ~to_: string) => unit = "renameSync";
[@bs.module "fs"] external ftruncateSync: (fd, int) => unit = "ftruncateSync";
[@bs.module "fs"]
external truncateSync: (string, int) => unit = "truncateSync";
[@bs.module "fs"]
external chownSync: (string, ~uid: int, ~gid: int) => unit = "chownSync";
[@bs.module "fs"]
external fchownSync: (fd, ~uid: int, ~gid: int) => unit = "fchownSync";
[@bs.module "fs"] external readlinkSync: string => string = "readlinkSync";
[@bs.module "fs"] external unlinkSync: string => unit = "unlinkSync";
/**
* `rmdirSync(dirPath)
* **Note: (recursive removal is experimental).**
* Removes the directory at `dirPath`. **Execution is synchronous and blocking**.
*/
[@bs.module "fs"]
external rmdirSync: string => unit = "rmdirSync";
[@bs.module "fs"] external openSync: string => fd = "openSync";
[@bs.module "fs"]
external openSyncWith: (string, ~flag: Flag.t=?, ~mode: int=?) => fd =
"openSync";
[@bs.module "fs"]
external readFileSync: (string, ~options: readFileOptions=?, unit) => Buffer.t =
"readFileSync";
[@bs.module "fs"] external existsSync: string => bool = "existsSync";
type writeFileSyncOptions;
[@bs.obj]
external writeFileSyncOptions:
(~mode: int=?, ~flag: Flag.t=?, unit) => writeFileSyncOptions;
[@bs.val] [@bs.module "fs"]
external writeFileSync: (string, Buffer.t) => unit = "writeFileSync";
[@bs.val] [@bs.module "fs"]
external writeFileSyncWith: (string, Buffer.t, writeFileSyncOptions) => unit =
"writeFileSync";
module FileHandle = {
type t;
[@bs.send]
external appendFile: (t, Buffer.t, appendFileOptions) => Js.Promise.t(unit) =
"appendFile";
[@bs.send]
external appendFileWith: (t, Buffer.t) => Js.Promise.t(unit) = "appendFile";
[@bs.send] external chmod: (t, int) => Js.Promise.t(unit) = "chmod";
[@bs.send] external chown: (t, int, int) => Js.Promise.t(unit) = "chown";
[@bs.send] external close: t => Js.Promise.t(unit) = "close";
[@bs.send] external datasync: t => Js.Promise.t(unit) = "datasync";
[@bs.get] external fd: t => fd = "fd";
type readInfo = {
bytesRead: int,
buffer: Buffer.t,
};
[@bs.send]
external read:
(t, Buffer.t, ~offset: int, ~length: int, ~position: int) =>
Js.Promise.t(readInfo) =
"read";
[@bs.send] external readFile: t => Js.Promise.t(Buffer.t) = "readFile";
[@bs.send]
external readFileWith: (t, ~encoding: string) => Js.Promise.t(string) =
"readFile";
[@bs.send] external stat: t => Js.Promise.t(Stats.t) = "stat";
[@bs.send] external sync: t => Js.Promise.t(unit) = "sync";
[@bs.send]
external truncate: (t, ~length: int=?, unit) => Js.Promise.t(unit) =
"truncate";
type writeInfo = {bytesWritten: int};
[@bs.send]
external write: (t, Buffer.t) => Js.Promise.t(writeInfo) = "write";
[@bs.send]
external writeOffset: (t, Buffer.t, ~offset: int) => Js.Promise.t(writeInfo) =
"write";
[@bs.send]
external writeRange:
(t, Buffer.t, ~offset: int, ~length: int, ~position: int) =>
Js.Promise.t(writeInfo) =
"write";
type writeFileOptions;
[@bs.obj]
external writeFileOptions:
(~mode: int=?, ~flag: Flag.t=?, unit) => writeFileOptions;
[@bs.send]
external writeFile: (t, Buffer.t) => Js.Promise.t(unit) = "writeFile";
[@bs.send]
external writeFileWith:
(t, Buffer.t, writeFileOptions) => Js.Promise.t(unit) =
"writeFile";
};
[@bs.module "fs"] [@bs.scope "promises"]
external access: string => Js.Promise.t(unit) = "access";
[@bs.module "fs"] [@bs.scope "promises"]
external accessWithMode: (string, ~mode: int) => Js.Promise.t(unit) =
"access";
[@bs.module "fs"] [@bs.scope "promises"]
external appendFile: (string, string, appendFileOptions) => Js.Promise.t(unit) =
"appendFile";
[@bs.module "fs"] [@bs.scope "promises"]
external appendFileWith:
(string, string, appendFileOptions) => Js.Promise.t(unit) =
"appendFile";
type appendFileBufferOptions;
[@bs.obj]
external appendFileBufferOptions:
(~mode: int=?, ~flag: Flag.t=?, unit) => appendFileBufferOptions;
[@bs.module "fs"] [@bs.scope "promises"]
external appendFileBuffer: (string, Buffer.t) => Js.Promise.t(unit) =
"appendFile";
[@bs.module "fs"] [@bs.scope "promises"]
external appendFileBufferWith:
(string, Buffer.t, appendFileBufferOptions) => Js.Promise.t(unit) =
"appendFile";
[@bs.module "fs"] [@bs.scope "promises"]
external chmod: (string, ~mode: int) => Js.Promise.t(unit) = "chmod";
[@bs.module "fs"] [@bs.scope "promises"]
external chown: (string, ~uid: int, ~gid: int) => Js.Promise.t(unit) =
"chown";
[@bs.module "fs"] [@bs.scope "promises"]
external copyFile: (string, ~dest: string) => Js.Promise.t(unit) = "copyFile";
[@bs.module "fs"] [@bs.scope "promises"]
external copyFileFlag:
(string, ~dest: string, ~flags: Constants.t) => Js.Promise.t(unit) =
"copyFile";
[@bs.module "fs"] [@bs.scope "promises"]
external lchmod: (string, ~mode: int) => Js.Promise.t(unit) = "lchmod";
[@bs.module "fs"] [@bs.scope "promises"]
external link: (~existingPath: string, ~newPath: string) => Js.Promise.t(unit) =
"link";
[@bs.module "fs"] [@bs.scope "promises"]
external lstat: string => Js.Promise.t(Stats.t) = "lstat";
[@bs.module "fs"] [@bs.scope "promises"]
external lstatBigInt: (string, bool) => Js.Promise.t(Stats.t) = "lstat";
type mkdirOptions;
[@bs.obj]
external mkdirOptions:
(~recursive: bool=?, ~mode: int=?, unit) => mkdirOptions;
[@bs.module "fs"] [@bs.scope "promises"]
external mkdir: (string, mkdirOptions) => Js.Promise.t(unit) = "mkdir";
[@bs.module "fs"] [@bs.scope "promises"]
external mkdirWith: (string, mkdirOptions) => Js.Promise.t(unit) = "mkdir";
type mkdtempOptions;
[@bs.obj] external mdktempOptions: unit => mkdtempOptions;
[@bs.module "fs"] [@bs.scope "promises"]
external mkdtemp: (string, mkdtempOptions) => Js.Promise.t(string) =
"mkddtemp";
[@bs.module "fs"] [@bs.scope "promises"]
external mkdtempWith: (string, mkdtempOptions) => Js.Promise.t(string) =
"mkddtemp";
[@bs.module "fs"] [@bs.scope "promises"]
external open_: (string, Flag.t) => Js.Promise.t(FileHandle.t) = "open";
[@bs.module "fs"] [@bs.scope "promises"]
external openWithMode:
(string, Flag.t, ~mode: int) => Js.Promise.t(FileHandle.t) =
"open";
module WriteStream = {
type kind('w) = [ Stream.writable('w) | `FileSystem];
type subtype('w, 'ty) = Stream.subtype([> kind('w)] as 'ty);
type supertype('w, 'ty) = Stream.subtype([< kind('w)] as 'ty);
type t = subtype(Buffer.t, [ kind(Buffer.t)]);
module Impl = {
include Stream.Writable.Impl;
[@bs.send]
external bytesWritten: subtype('w, [> kind('w)]) => int = "bytesWritten";
[@bs.send] external path: subtype('w, [> kind('w)]) => string = "path";
[@bs.send]
external pending: subtype('w, [> kind('w)]) => bool = "pending";
[@bs.send]
external onOpen:
(
subtype('w, [> kind('w)]) as 'stream',
[@bs.as "open"] _,
[@bs.uncurry] (fd => unit)
) =>
'stream =
"on";
[@bs.send]
external onReady:
(
subtype('w, [> kind('w)]) as 'stream,
[@bs.as "ready"] _,
[@bs.uncurry] (unit => unit)
) =>
'stream =
"on";
};
include Impl;
};
module ReadStream = {
type kind('r) = [ Stream.readable('r) | `FileSystem];
type subtype('r, 'ty) = Stream.subtype([> kind('r)] as 'ty);
type supertype('r, 'ty) = Stream.subtype([< kind('r)] as 'ty);
type t = subtype(Buffer.t, [ kind(Buffer.t)]);
module Impl = {
include Stream.Readable.Impl;
[@bs.send]
external bytesRead: subtype('r, [> kind('r)]) => int = "bytesWritten";
[@bs.send] external path: subtype('r, [> kind('r)]) => string = "path";
[@bs.send]
external pending: subtype('r, [> kind('r)]) => bool = "pending";
[@bs.send]
external onOpen:
(
subtype('r, [> kind('r)]) as 'stream,
[@bs.as "open"] _,
[@bs.uncurry] (fd => unit)
) =>
'stream =
"on";
[@bs.send]
external onReady:
(
subtype('r, [> kind('r)]) as 'stream,
[@bs.as "ready"] _,
[@bs.uncurry] (unit => unit)
) =>
'stream =
"on";
};
include Impl;
};
type createReadStreamOptions;
[@bs.obj]
external createReadStreamOptions:
(
~flags: string=?,
~fd: fd=?,
~mode: int=?,
~autoClose: bool=?,
~emitClose: bool=?,
~start: int=?,
~_end: int=?,
~highWaterMark: int=?,
unit
) =>
createReadStreamOptions;
[@bs.module "fs"]
external createReadStream: string => ReadStream.t = "createReadStream";
[@bs.module "fs"]
external createReadStreamWith:
(string, createReadStreamOptions) => ReadStream.t =
"createReadStream";
type createWriteStreamOptions;
[@bs.obj]
external createWriteStreamOptions:
(
~flags: string=?,
~fd: fd=?,
~mode: int=?,
~autoClose: bool=?,
~emitClose: bool=?,
~start: int=?,
~fs: Js.t({..})=?,
unit
) =>
createReadStreamOptions;
[@bs.module "fs"]
external createWriteStream: string => WriteStream.t = "createWriteStream";
[@bs.module "fs"]
external createWriteStreamWith:
(string, createWriteStreamOptions) => WriteStream.t =
"createWriteStream";