-
Notifications
You must be signed in to change notification settings - Fork 2
/
stdmods.js
1868 lines (1713 loc) · 57.5 KB
/
stdmods.js
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
/** @file: duktape.hh */
/**
* Reference to the global object, mainly useful
* for accessing in strict mode ('use strict';).
* @var {object}
*/
var global = {};
/** @file: mod.stdlib.hh */
/**
* Exits the script interpreter with a specified exit code.
*
* @param {number} status_code
*/
exit = function(status_code) {};
/**
* Includes a JS file and returns the result of
* the last statement.
* Note that `include()` is NOT recursion protected.
*
* @param {string} path
* @return {any}
*/
include = function(path) {};
/**
* Contains the environment variables of the application
* as key-value (string->string) plain object. If env is
* not explicitly enabled in the binary application, the
* object is undefined.
*
* @var {object} sys.env
*/
sys.env = {};
/** @file: mod.stdio.hh */
/**
* print(a,b,c, ...). Writes data stringifyed to STDOUT.
*
* @param {...*} args
*/
print = function(args) {};
/**
* alert(a,b,c, ...). Writes data stringifyed to STDERR.
*
* @param {...*} args
*/
alert = function(args) {};
/**
* Returns a first character entered as string. First function argument
* is a text that is printed before reading the input stream (without newline,
* "?" or ":"). The input is read from STDIN.
*
* @param {string} text
* @return {string}
*/
confirm = function(text) {};
/**
* Returns a line entered via the input stream STDIN.
*
* @return {string}
*/
prompt = function() {};
/**
* C style formatted output to STDOUT. Note that not
* all formats can be used like in C/C++ because ECMA
* is has no strong type system. E.g. %u, %ul etc does
* not make sense because numbers are intrinsically
* floating point, and the (data type) size of the number
* matters when using %u. If unsupported arguments are
* passed the method will throw an exception.
*
* Supported formatters are:
*
* - %d, %ld, %lld: The ECMA number is coerced
* into an integer and printed. Digits and sign
* are supported (%4d, %+06l).
*
* - %f, %lf, %g: Floating point format, also with additional
* format specs like %.8f, %+10.5f etc.
*
* - %x: Hexadecimal representation of numbers (also %08x
* or %4X etc supported).
*
* - %o: Octal representation of numbers (also %08o)
*
* - %s: String coercing with optional minimum width (e.g. %10s)
*
* - %c: When number given, the ASCII code of the lowest byte
* (e.g. 65=='A'). When string given the first character
* of the string.
*
* Not supported:
*
* - Parameter argument (like "%2$d", the "2$" would apply the
* same format to two arguments passed to the function).
*
* - Dynamic width (like "%*f", the "*" would be used to pass
* the output width of the floating point number as argument).
*
* - Unsigned %u, %n
*
* @param {string} format
* @param {...*} args
*/
printf = function(format, args) {};
/**
* C style formatted output into a string. For
* formatting details please @see printf.
*
* @param {string} format
* @param {...*} args
* @return {string}
*/
sprintf = function(format, args) {};
/**
* Console object known from various JS implementations.
*
* @var {object}
*/
var console = {};
/**
* Writes a line to the log stream (automatically appends a newline).
* The default log stream is STDERR.
*
* @param {...*} args
*/
console.log = function(args) {};
/**
* Read from STDIN (default until EOF). Using the argument `arg`
* it is possible to use further functionality:
*
* - By default (if `arg` is undefined or not given) the function
* returns a string when all data are read.
*
* - If `arg` is boolean and `true`, then the input is read into
* a buffer variable, not a string. The function returns when
* all data are read.
*
* - If `arg` is a function, then a string is read line by line,
* and each line passed to this callback function. If the function
* returns `true`, then the line is added to the output. The
* function may also preprocess line and return a String. In this
* case the returned string is added to the output.
* Otherwise, if `arg` is not `true` and no string, the line is
* skipped.
*
* - If `arg` is a number, then reading from a pipe or tty/console
* is nonblocking if supported by the device, returning maximum
* `arg` characters. Returns `undefined` on EOF or read error
* (e.g. broken-pipe). Console interfaces are temporarily set to
* non-canonical mode for this purpose (settings restored after
* reading).
*
* @param {function|boolean} arg
* @return {string|buffer}
*/
console.read = function(arg) {};
/**
* Write to STDOUT without any conversion, whitespaces between the given arguments,
* and without newline at the end.
*
* @param {...*} args
*/
console.write = function(args) {};
/**
* Blocking string line input.
* @return {string}
*/
console.readline = function(args) {};
/**
* Enable/disable VT100 processing (default: enabled).
* Only relevant on Windows operating systems.
*
* @param {boolean} enable
*/
console.vt100 = function(enable) {};
/** @file: mod.fs.hh */
/**
* Global file system object.
* @var {object}
*/
var fs = {};
/**
* Reads a file, returns the contents or undefined on error.
*
* - Normally the file is read as text file, no matter if the data in the file
* really correspond to a readable text.
*
* - If `conf` is a string containing the word "binary", the data are read
* binary and returned as `buffer`.
*
* - If `conf` is a callable function, the data are read as text line by line,
* and for each line the callback is invoked, where the line text is passed
* as argument. The callback ("filter function") can:
*
* - return `true` to keep the passed line in the file read output.
* - return `false` or `undefined` to exclude the line from the output.
* - return a `string` to put the returned string into the output instead
* of the original passed text (inline editing).
*
* - Binary reading and using the filter callback function excludes another.
*
* - Not returning anything/undefined has a purpose of storing the line data
* somewhere else, e.g. when parsing:
*
* var config = {};
* fs.readfile("whatever.conf", function(s) {
* // parse, parse ... get some key and value pair ...
* config[key] = value;
* // no return return statement, output of fs.filter()
* // is not relevant.
* });
*
* @param {string} path
* @param {string|function} [conf]
* @return {string|buffer}
*/
fs.read = function(path, conf) {};
/**
* Writes data into a file.
*
* @param {string} path
* @param {string|buffer|number|boolean|object} data
* @return {boolean}
*/
fs.write = function(path, data) {};
/**
* Appends data at the end of a file.
*
* @see fs.append
* @param {string} path
* @param {string|buffer|number|boolean|object} data
* @return {boolean}
*/
fs.append = function(path, data) {};
/**
* Returns the current working directory or `undefined` on error.
* Does strictly not accept arguments.
*
* @return {string|undefined}
*/
fs.cwd = function() {};
/**
* Returns the temporary directory or `undefined` on error.
* Does strictly not accept arguments.
*
* @return {string|undefined}
*/
fs.tmpdir = function() {};
/**
* Returns the home directory of the current used or `undefined` on error.
* Does strictly not accept arguments.
*
* @return {string|undefined}
*/
fs.home = function() {};
/**
* Returns the real, full path (with resolved symbolic links) or `undefined`
* on error or if the file does not exist.
* Does strictly require one String argument (the path).
*
* @param {string} path
* @return {string|undefined}
*/
fs.realpath = function(path) {};
/**
* Returns the path of the executing interpreter binary,
* `undefined` if the function is not supported on the
* current operating system.
*
* @return {string|undefined}
*/
fs.application = function() {};
/**
* Returns directory part of the given path (without tailing slash/backslash)
* or `undefined` on error.
* Does strictly require one String argument (the path).
*
* @param {string} path
* @return {string|undefined}
*/
fs.dirname = function(path) {};
/**
* Returns file base part of the given path (name and extension, without parent directory)
* or `undefined` on error.
* Does strictly require one String argument (the path).
*
* @param {string} path
* @return {string|undefined}
*/
fs.basename = function(path) {};
/**
* Returns a plain object containing information about a given file,
* directory or `undefined` on error.
* Does strictly require one String argument (the path).
*
* The returned object has the properties:
*
* {
* path: String, // given path (function argument)
* size: Number, // size in bytes
* mtime: Date, // Last modification time
* ctime: Date, // Creation time
* atime: Date, // Last accessed time
* owner: String, // User name of the file owner
* group: String, // Group name of the file group
* uid: Number, // User ID of the owner
* gid: Number, // Group ID of the group
* inode: Number, // Inode of the file
* device: Number, // Device identifier/no of the file
* mode: String, // Octal mode representation like "644" or "755"
* modeval: Number // Numeric file mode bitmask, use `fs.mod2str(mode)` to convert to a string like 'drwxr-xr-x'.
* }
*
* @param {string} path
* @return {object|undefined}
*/
fs.stat = function(path) {};
/**
* Returns a plain object containing information about a given file,
* where links are not resolved. Return value is the same as in
* `fs.stat()`.
*
* @see fs.stat()
* @param {string} path
* @return {object|undefined}
*/
fs.lstat = function(path) {};
/**
* Returns last modified time a given file path, or undefined on error.
* Does strictly require one String argument (the input path).
*
* @param {string} path
* @return {Date|undefined}
*/
fs.mtime = function(path) {};
/**
* Returns creation time a given file path, or undefined on error.
* Does strictly require one String argument (the input path).
*
* @param {string} path
* @return {Date|undefined}
*/
fs.ctime = function(path) {};
/**
* Returns last access time a given file path, or undefined on error.
* Does strictly require one String argument (the input path).
*
* @param {string} path
* @return {Date|undefined}
*/
fs.atime = function(path) {};
/**
* Returns the name of the file owner of a given file path, or undefined on error.
* Does strictly require one String argument (the input path).
*
* @param {string} path
* @return {string|undefined}
*/
fs.owner = function(path) {};
/**
* Returns the group name of a given file path, or undefined on error.
* Does strictly require one String argument (the input path).
*
* @param {string} path
* @return {string|undefined}
*/
fs.group = function(path) {};
/**
* Returns the file size in bytes of a given file path, or undefined on error.
* Does strictly require one String argument (the input path).
*
* @param {string} path
* @return {number|undefined}
*/
fs.size = function(path) {};
/**
* Returns a string representation of a file mode bit mask, e.g.
* for a (octal) mode `0755` directory the output will be '755' or 'rwxrwxrwx' (see flags below).
* Does strictly require one (integral) Number argument (the input mode) at first.
*
* If flags are given they modify the output as follows:
*
* flags == 'o' (octal) : returns a string with the octal representation (like 755 or 644)
* flags == 'l' (long) : returns a string like 'rwxrwxrwx', like `ls -l` but without preceeding file type character.
* flags == 'e' (extended) : output like `ls -l` ('d'=directory, 'c'=character device, 'p'=pipe, ...)
*
* @param {number} mode
* @param {string} [flags]
* @return {string|undefined}
*/
fs.mod2str = function(mode, flags) {};
/**
* Returns a numeric representation of a file mode bit mask given as string, e.g.
* "755", "rwx------", etc.
* Does strictly require one argument (the input mode). Note that numeric arguments
* will be reinterpreted as string, so that 755 is NOT the bit mask 0x02f3, but seen
* as 0755 octal.
*
* @param {string} mode
* @return {number|undefined}
*/
fs.str2mod = function(mode) {};
/**
* Returns true if a given path points to an existing "node" in the file system (file, dir, pipe, link ...),
* false otherwise or undefined on error.
* Does strictly require one String argument (the input path).
*
* @param {string} path
* @return {boolean}
*/
fs.exists = function(path) {};
/**
* Returns true if the current user has write permission to a given path,
* false otherwise or undefined on error.
* Does strictly require one String argument (the input path).
*
* @param {string} path
* @return {boolean}
*/
fs.iswritable = function(path) {};
/**
* Returns true if the current user has read permission to a given path,
* false otherwise or undefined on error.
* Does strictly require one String argument (the input path).
*
* @param {string} path
* @return {boolean}
*/
fs.isreadable = function(path) {};
/**
* Returns true if the current user has execution permission to a given path,
* false otherwise or undefined on error.
* Does strictly require one String argument (the input path).
*
* @param {string} path
* @return {boolean}
*/
fs.isexecutable = function(path) {};
/**
* Returns true if a given path points to a directory, false otherwise or undefined on error.
* Does strictly require one String argument (the input path).
*
* @param {string} path
* @return {boolean}
*/
fs.isdir = function(path) {};
/**
* Returns true if a given path points to a regular file, false otherwise or undefined on error.
* Does strictly require one String argument (the input path).
*
* @param {string} path
* @return {boolean}
*/
fs.isfile = function(path) {};
/**
* Returns true if a given path points to a link, false otherwise or undefined on error.
* Does strictly require one String argument (the input path).
*
* @param {string} path
* @return {boolean}
*/
fs.islink = function(path) {};
/**
* Returns true if a given path points to a fifo (named pipe), false otherwise or undefined on error.
* Does strictly require one String argument (the input path).
*
* @param {string} path
* @return {boolean}
*/
fs.isfifo = function(path) {};
/**
* Switches the current working directory to the specified path. Returns true on success, false on error.
* Does strictly require one String argument (the input path).
*
* @param {string} path
* @return {boolean}
*/
fs.chdir = function(path) {};
/**
* Creates a new empty directory for the specified path. Returns true on success, false on error.
* Require one String argument (the input path), and one optional option argument.
* If the options is "p" or "parents" (similar to unix `mkdir -p`), parent directories will be
* created recursively. If the directory already exists, the function returns success, if the
* creation of the directory or a parent directory fails, the function returns false.
* Note that it is possible that the path might be only partially created in this case.
*
* @param {string} path
* @param {string} [options]
* @return {boolean}
*/
fs.mkdir = function(path, options) {};
/**
* Removes an empty directory specified by a given path. Returns true on success, false on error.
* Does strictly require one String argument (the input path).
* Note that the function also fails if the directory is not empty (no recursion),
*
* @param {string} path
* @return {boolean}
*/
fs.rmdir = function(path) {};
/**
* Removes a file or link form the file system. Returns true on success, false on error.
* Does strictly require one String argument (the input path).
* Note that the function also fails if the given path is a directory. Use `fs.rmdir()` in this case.
*
* @param {string} path
* @return {boolean}
*/
fs.unlink = function(path) {};
/**
* Changes the name of a file or directory. Returns true on success, false on error.
* Does strictly require two String arguments: The input path and the new name path.
* Note that this is a basic filesystem i/o function that fails if the parent directory,
* or the new file does already exist.
*
* @param {string} path
* @param {string} new_path
* @return {boolean}
*/
fs.rename = function(path, new_path) {};
/**
* Lists the contents of a directory (basenames only), undefined if the function failed to open the directory
* for reading. Results are unsorted.
*
* @param {string} path
* @return {array|undefined}
*/
fs.readdir = function(path) {};
/**
* File pattern (fnmatch) based listing of files.
*
* @param {string} pattern
* @return {array|undefined}
*/
fs.glob = function(pattern) {};
/**
* Creates a symbolic link, returns true on success, false on error.
*
* @param {string} path
* @param {string} link_path
* @return {boolean}
*/
fs.symlink = function(path, link_path) {};
/**
* Changes the modification and access time of a file or directory. Returns true on success, false on error.
* Does strictly require three argument: The input path (String), the last-modified time (Date) and the last
* access time (Date).
*
* @param {string} path
* @param {Date} [mtime]
* @param {Date} [atime]
* @return {boolean}
*/
fs.utime = function(path, mtime, atime) {};
/**
* Creates a (hard) link, returns true on success, false on error.
*
* @param {string} path
* @param {string} link_path
* @return {boolean}
*/
fs.hardlink = function(path, link_path) {};
/**
* Returns the target path of a symbolic link, returns a String or `undefined` on error.
* Does strictly require one String argument (the path).
* Note: Windows: returns undefined, not implemented.
*
* @param {string} path
* @return {string|undefined}
*/
fs.readlink = function(path) {};
/**
* Creates a (hard) link, returns true on success, false on error.
*
* @param {string} path
* @param {string|number} [mode]
* @return {boolean}
*/
fs.chmod = function(path, mode) {};
/**
* Contains the (execution path) PATH separator,
* e.g. ":" for Linux/Unix or ";" for win32.
*
* @var {string}
*/
fs.pathseparator = "";
/**
* Contains the directory separator, e.g. "/"
* for Linux/Unix or "\" for win32.
*
* @var {string}
*/
fs.directoryseparator = "";
/** @file: mod.fs.ext.hh */
/**
* Recursive directory walking. The argument `path` specifies the root directory
* of the file search - that is not a pattern with wildcards, but a absolute or
* relative path. The second argument `options` can be
*
* - a string: then it is the pattern to filter by the file name.
*
* - a plain object with one or more of the properties:
*
* - name: {string} Filter by file name match pattern (fnmatch based, means with '*','?', etc).
*
* - type: {string} Filter by file type, where
*
* - "d": Directory
* - "f": Regular file
* - "l": Symbolic link
* - "p": Fifo (pipe)
* - "s": Socket
* - "c": Character device (like /dev/tty)
* - "b": Block device (like /dev/sda)
* - "h": Include hidden files (dot-files like ".fileordir", and win32 'hidden' flag).
* If `type` is empty/not specified, hidden files are implicitly included.
*
* - depth: {number} Maximum directory recursion depth. `0` lists the contents of the root directory, etc.
*
* - icase: {boolean} File name matching is not case sensitive (Linux/Unix: default false, Win32: default true)
*
* - filter: [Function A callback invoked for each file that was not yet filtered out with the
* criteria listed above. The callback gets the file path as first argument. With that
* you can:
*
* - Add it to the output by returning `true`.
*
* - Not add it to the output list by returning `false`, `null`, or `undefined`. That is
* useful e.g. if you don't want to list any files, but process them instead, or update
* global/local accessible variables depending on the file paths you get.
*
* - Add a modified path or other string by returning a String. That is really useful
* e.g. if you want to directly return the contents of files, or checksums etc etc etc.
* You get a path, and specify the output yourself.
*
* @throws {Error}
* @param {string} path
* @param {string|Object} [options]
* @param {function} [filter]
* @return {array|undefined}
*/
fs.find = function(path, options, filter) {};
/**
* Copies a file from one location `source_path` to another (`target_path`),
* similar to the `cp` shell command. The argument `options` can encompass
* the key-value pairs
*
* {
* "recursive": {boolean}=false
* }
*
* Optionally, it is possible to specify the string 'r' or '-r' instead of
* `{recursive:true}` as third argument.
*
* @throws {Error}
* @param {string} source_path
* @param {string} target_path
* @param {object} [options]
* @return {boolean}
*/
fs.copy = function(source_path, target_path, options) {};
/**
* Moves a file or directory from one location `source_path` to another (`target_path`),
* similar to the `mv` shell command. File are NOT moved accross disks (method will fail).
*
* @throws {Error}
* @param {string} source_path
* @param {string} target_path
* @return {boolean}
*/
fs.move = function(source_path, target_path) {};
/**
* Deletes a file or directory (`target_path`), similar to the `rm` shell
* command. The argument `options` can encompass the key-value pairs
*
* {
* "recursive": {boolean}=false
* }
*
* Optionally, it is possible to specify the string 'r' or '-r' instead of
* `{recursive:true}` as third argument.
*
* Removing is implicitly forced (like "rm -f").
*
* @throws {Error}
* @param {string} target_path
* @param {string|object} [options]
* @return {boolean}
*/
fs.remove = function(target_path, options) {};
/** @file: mod.fs.file.hh */
/**
* File object constructor, creates a fs.file object when
* invoked with the `new` keyword. Optionally, path and openmode
* can be specified to directly open the file. See `File.open()`
* for details.
*
* @constructor
* @throws {Error}
* @param {string} [path]
* @param {string} [openmode]
* @return {fs.file}
*/
fs.file = function(path, openmode) {};
/**
* Opens a file given the path and corresponding "open mode". The
* mode is a string defining flags from adding or omitting characters,
* where the characters are (with exception of mode "a+") compliant
* to the ANSI C `fopen()` options. Additional characters enable
* further file operations and functionality. The options are:
*
* - "r": Open for `r`eading. The file must exist. Set the position
* to the beginning of the file (ANSI C).
*
* - "w": Open for `w`riting. Create if the file is not existing yet,
* truncate the file (discard contents). Start position is the
* beginning of the file. (ANSI C).
*
* - "a": Open for `a`ppending. Create if the file is not existing yet,
* set the write position to the end of the file. (ANSI C).
*
* - "r+": Open for `r`eading and writing, the file must exist. The
* read/write position is set to the beginning of the file
* (ANSI C).
*
* - "w+": Open for `w`riting and reading. Create if the file is not
* existing yet, truncate the file (discard contents). Start
* position is the beginning of the file. (ANSI C).
*
* - "a+": Open for `a`ppending and reading. Create if the file is not
* existing yet. Start position is the beginning of the file.
* Warning: The write position is guaranteed to be the end of
* the file, but ANSI C specifies that the read position is
* separately handled from the write position, and the write
* position is implicitly always the end of the file. This is
* NOT guaranteed in this implementation. When reading you must
* `seek()` to the read position yourself.
*
* - "b": Optional flag: Open to read/write `b`inary. Reading will return
* a `Buffer` in this case. Writing a `Buffer` will write binary
* data.
*
* - "t": Optional flag: Open to read/write `t`ext (in contrast to binary,
* this is already the default and only accepted because it is
* known on some platforms).
*
* - "x": Optional flag: E`x`clusive creation. This causes opening for write
* to fail with an exception if the file already exists. You can
* use this to prevent accidentally overwriting existing files.
*
* - "e": Optional flag: Open `e`xisting files only. This is similar to "r+"
* and can be used for higher verbosity or ensuring that no file will
* be created. The open() call fails with an exception if the file
* does not exist.
*
* - "c": Optional flag: `C`reate file if not existing. This is the explicit
* specification of the default open for write/append behaviour. This
* flag implicitly resets the `e` flag.
*
* - "p": Optional flag: `P`reserve file contents. This is an explicit order
* that opening for write does not discard the current file contents.
*
* - "s": Optional flag: `S`ync. Means that file operations are implicitly
* forced to be read from / written to the disk or device. Ignored if
* the platform does not support it.
*
* - "n": Optional flag: `N`onblocking. Means that read/write operations that
* would cause the function to "sleep" until data are available return
* directly with empty return value. Ignored if the platform does not
* support it (or not implemented for the platform).
*
* The flags (characters) are not case sensitive, so `file.open(path, "R")` and
* `file.open(path, "r")` are identical.
*
* Although the ANSI open flags are supported it is at a second glance more explicit
* to use the optional flags in combination with "r" and "w" or "a", e.g.
*
* - `file.open(path, "rwcx")` --> open for read/write, create if not yet existing,
* and only if not yet existing.
*
* - `file.open(path, "wep")` --> open for write, only existing, preserve contents.
*
* - `file.open("/dev/cdev", "rwens")` --> open a character device for read/write, must exist,
* nonblocking, sync.
*
* The function returns the reference to `this`.
*
* @throws {Error}
* @param {string} [path]
* @param {string} [openmode]
* @return {fs.file}
*/
fs.file.prototype.open = function(path, openmode) {};
/**
* Closes a file. Returns `this` reference.
*
* @return {fs.file}
*/
fs.file.prototype.close = function() {};
/**
* Returns true if a file is closed.
*
* @return {boolean}
*/
fs.file.prototype.closed = function() {};
/**
* Returns true if a file is opened.
*
* @return {boolean}
*/
fs.file.prototype.opened = function() {};
/**
* Returns true if the end of the file is reached. This
* is practically interpreted as:
*
* - when the file or pipe signals EOF,
* - when the file is not opened,
* - when a pipe is not connected or broken
*
* @return {boolean}
*/
fs.file.prototype.eof = function() {};
/**
* Reads data from a file, where the maximum number of bytes
* to read can be specified. If `max_size` is not specified,
* then as many bytes as possible are read (until EOF, until
* error or until the operation would block).
*
* Note: If the end of the file is reached, the `eof()`
* method will return true and the `read()` method
* will return `undefined` as indication.
*
* @throws {Error}
* @param {number} [max_bytes]
* @return {string|buffer}
*/
fs.file.prototype.read = function(max_size) {};
/**
* Read string data from the opened file and return when
* detecting a newline character. The newline character
* defaults to the operating system newline and can be
* changed for the file by setting the `newline` property
* of the file (e.g. `myfile.newline = "\r\n"`).
*
* Note: This function cannot be used in combination
* with the nonblocking I/O option.
*
* Note: If the end of the file is reached, the `eof()`
* method will return true and the `read()` method
* will return `undefined` to indicate that no
* empty line was read but nothing at all.
*
* Note: This function is slower than `fs.file.read()` or
* `fs.readfile()` because it has to read unbuffered
* char-by-char. If you intend to read an entire file
* and filter the lines prefer `fs.readfile()` with
* line processing callback.
*
* @throws {Error}
* @return {string}
*/
fs.file.prototype.readln = function() {};
/**
* Write data to a file, returns the number of bytes written.
* Normally all bytes are written, except if nonblocking i/o
* was specified when opening the file.
*
* @throws {Error}
* @param {string|buffer} data
* @return {number}
*/
fs.file.prototype.write = function(data) {};
/**
* Write string data to a file and implicitly append
* a newline character. The newline character defaults
* to the operating system newline (Windows CRLF, else
* LF, no old Mac CR). This character can be changed
* for the file by setting the `newline` property of
* the file (e.g. myfile.newline = "\r\n").
* Note: This function cannot be used in combination
* with the nonblocking I/O option. The method throws
* an exception if not all data could be written.
*
* @throws {Error}
* @param {string} data
*/
fs.file.prototype.writeln = function(data) {};
/**
* C style formatted output to the opened file.
* The method is used identically to `printf()`.
* Note: This function cannot be used in combination
* with the nonblocking I/O option. The method
* throws an exception if not all data could be
* written.
*
* @throws {Error}
* @param {string} format
* @param {...*} args
*/
fs.file.prototype.printf = function(format, args) {};
/**
* Flushes the file write buffer. Ignored on platforms where this
* is not required. Returns reference to `this`.
*
* @throws {Error}
* @return {fs.file}
*/
fs.file.prototype.flush = function() {};
/**
* Returns the current file position.
*
* @throws {Error}
* @return {number}
*/
fs.file.prototype.tell = function() {};
/**
* Sets the new file position (read and write). Returns the
* actual position (from the beginning of the file) after the
* position was set. The parameter whence specifies from where
* the position shall be set: