ktfile 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,667 @@
1
+ import { IFile } from "../IFile";
2
+ import { FileAsync } from "../async/FileAsync";
3
+ import { ISyncFS } from "./ISyncFS";
4
+ export declare function pass(x: () => unknown): boolean;
5
+ export declare function ret<T>(x: () => T): T | null;
6
+ export declare class FileSync extends IFile<ISyncFS> {
7
+ static fs: ISyncFS;
8
+ static createTempFile(directory: FileSync, prefix?: string, suffix?: string): FileSync;
9
+ get fs(): ISyncFS;
10
+ /**
11
+ * @description Checks if the file is executable.
12
+ * A file is considered executable if it has the execute permission set.
13
+ * This method checks if the file can be executed by the current user.
14
+ * @example
15
+ * const file = new FileSync("path/to/file.txt");
16
+ * if (file.canExecute) {
17
+ * console.log("This file is executable.");
18
+ * } else {
19
+ * console.log("This file is not executable.");
20
+ * }
21
+ * @returns {boolean} True if the file is executable, false otherwise.
22
+ * If the file does not exist or cannot be accessed, it will throw an error.
23
+ */
24
+ get canExecute(): boolean;
25
+ /**
26
+ * @description Sets the executable permission for the file.
27
+ * If `value` is true, it sets the permission to allow execution.
28
+ * If `value` is false, it sets the permission to disallow execution.
29
+ * @example
30
+ * const file = new FileSync("path/to/file.txt");
31
+ * file.canExecute = true; // Sets the file to be executable
32
+ * file.canExecute = false; // Sets the file to be non-executable
33
+ * @param {boolean} value - Whether to allow execution (true) or disallow execution (false).
34
+ */
35
+ set canExecute(value: boolean);
36
+ /**
37
+ * @description Checks if the file can be read.
38
+ * A file is considered readable if it has the read permission set.
39
+ * This method checks if the file can be accessed for reading by the current user.
40
+ * @example
41
+ * const file = new FileSync("path/to/file.txt");
42
+ * if (file.canRead) {
43
+ * console.log("This file can be read.");
44
+ * } else {
45
+ * console.log("This file cannot be read.");
46
+ * }
47
+ * @returns {boolean} True if the file can be read, false otherwise.
48
+ * If the file does not exist or cannot be accessed, it will throw an error.
49
+ */
50
+ get canRead(): boolean;
51
+ /**
52
+ * @description Sets the read permission for the file.
53
+ * If `value` is true, it sets the permission to allow reading.
54
+ * If `value` is false, it sets the permission to disallow reading.
55
+ * @example
56
+ * const file = new FileSync("path/to/file.txt");
57
+ * file.canRead = true; // Sets the file to be readable
58
+ * file.canRead = false; // Sets the file to be non-readable
59
+ * @param {boolean} value - Whether to allow reading (true) or disallow reading (false).
60
+ */
61
+ set canRead(value: boolean);
62
+ /**
63
+ * @description Checks if the file can be written to.
64
+ * A file is considered writable if it has the write permission set.
65
+ * This method checks if the file can be accessed for writing by the current user.
66
+ * @example
67
+ * const file = new FileSync("path/to/file.txt");
68
+ * if (file.canWrite) {
69
+ * console.log("This file can be written to.");
70
+ * } else {
71
+ * console.log("This file cannot be written to.");
72
+ * }
73
+ * @returns {boolean} True if the file can be written to, false otherwise.
74
+ * If the file does not exist or cannot be accessed, it will throw an error.
75
+ */
76
+ get canWrite(): boolean;
77
+ /**
78
+ * @description Sets the write permission for the file.
79
+ * If `value` is true, it sets the permission to allow writing.
80
+ * If `value` is false, it sets the permission to disallow writing.
81
+ * @example
82
+ * const file = new FileSync("path/to/file.txt");
83
+ * file.canWrite = true; // Sets the file to be writable
84
+ * file.canWrite = false; // Sets the file to be non-writable
85
+ * @param {boolean} value - Whether to allow writing (true) or disallow writing (false).
86
+ */
87
+ set canWrite(value: boolean);
88
+ /**
89
+ * @description Gets the creation time of the file.
90
+ * The creation time is the time when the file was created in the file system.
91
+ * If the file does not exist, it returns null.
92
+ * @example
93
+ * const file = new FileSync("path/to/file.txt");
94
+ * console.log("Creation time:", file.creationTime);
95
+ * // Output: Creation time: 2023-10-01T12:00:00.000Z
96
+ * @returns {Date | null} The creation time of the file as a Date object, or null if the file does not exist.
97
+ */
98
+ get creationTime(): Date | null;
99
+ /**
100
+ * @description Sets the creation time of the file.
101
+ * This method allows you to change the creation time of the file to a specified Date.
102
+ * If the file does not exist, it will throw an error.
103
+ * @example
104
+ * const file = new FileSync("path/to/file.txt");
105
+ * file.creationTime = new Date("2023-10-01T12:00:00.000Z");
106
+ * // Sets the creation time of the file to the specified date.
107
+ * @param {Date} value - The new creation time to set for the file.
108
+ */
109
+ set creationTime(value: Date);
110
+ /**
111
+ * @description Gets the last modified time of the file.
112
+ * The last modified time is the time when the file was last modified in the file system.
113
+ * If the file does not exist, it returns null.
114
+ * @example
115
+ * const file = new FileSync("path/to/file.txt");
116
+ * console.log("Last modified time:", file.lastModified);
117
+ * // Output: Last modified time: 2023-10-01T12:00:00.000Z
118
+ * @returns {Date | null} The last modified time of the file as a Date object, or null if the file does not exist.
119
+ */
120
+ get lastModified(): Date | null;
121
+ /**
122
+ * @description Sets the last modified time of the file.
123
+ * This method allows you to change the last modified time of the file to a specified Date.
124
+ * If the file does not exist, it will throw an error.
125
+ * @example
126
+ * const file = new FileSync("path/to/file.txt");
127
+ * file.lastModified = new Date("2023-10-01T12:00:00.000Z");
128
+ * // Sets the last modified time of the file to the specified date.
129
+ * @param {Date} value - The new last modified time to set for the file.
130
+ */
131
+ set lastModified(value: Date);
132
+ /**
133
+ * @description Gets the last access time of the file.
134
+ * The last access time is the time when the file was last accessed in the file system.
135
+ * If the file does not exist, it returns null.
136
+ * @example
137
+ * const file = new FileSync("path/to/file.txt");
138
+ * console.log("Last access time:", file.lastAccess);
139
+ * // Output: Last access time: 2023-10-01T12:00:00.000Z
140
+ * @returns {Date | null} The last access time of the file as a Date object, or null if the file does not exist.
141
+ */
142
+ get exists(): boolean | null;
143
+ /**
144
+ * @description Gets the last access time of the file.
145
+ * The last access time is the time when the file was last accessed in the file system.
146
+ * If the file does not exist, it returns null.
147
+ * @example
148
+ * const file = new FileSync("path/to/file.txt");
149
+ * console.log("Last access time:", file.lastAccess);
150
+ * // Output: Last access time: 2023-10-01T12:00:00.000Z
151
+ * @returns {Date | null} The last access time of the file as a Date object, or null if the file does not exist.
152
+ */
153
+ get lastAccess(): Date | null;
154
+ /**
155
+ * @description Gets the name of the file.
156
+ * The name is the last part of the file path, which is typically the file name with its extension.
157
+ * If the file path ends with a separator, it returns an empty string.
158
+ * @example
159
+ * const file = new FileSync("path/to/file.txt");
160
+ * console.log("File name:", file.name);
161
+ * // Output: File name: file.txt
162
+ * @returns {string} The name of the file.
163
+ */
164
+ get name(): string;
165
+ /**
166
+ * @description Gets the file name without the extension.
167
+ * The name is the part of the file name before the last dot (.).
168
+ * If there is no dot in the file name, it returns the full name.
169
+ * @example
170
+ * const file = new FileSync("path/to/file.txt");
171
+ * console.log("File name without extension:", file.nameWithoutExtension);
172
+ * // Output: File name without extension: file
173
+ * @returns {string} The file name without the extension.
174
+ * If the file name does not contain a dot, it returns the full name.
175
+ */
176
+ get nameWithoutExtension(): string;
177
+ /**
178
+ * @description Gets the file extension.
179
+ * The extension is the part of the file name after the last dot (.)
180
+ * If there is no dot in the file name, it returns an empty string.
181
+ * @example
182
+ * const file = new FileSync("path/to/file.txt");
183
+ * console.log("File extension:", file.extension);
184
+ * // Output: File extension: txt
185
+ * @returns {string} The file extension, or an empty string if there is no extension.
186
+ */
187
+ get extension(): string;
188
+ /**
189
+ * @description Gets the parent directory of the file.
190
+ * If the file is in the root directory, it returns null.
191
+ * @example
192
+ * const file = new FileSync("path/to/file.txt");
193
+ * const parent = file.parent;
194
+ * if (parent) {
195
+ * console.log("Parent directory:", parent.path);
196
+ * } else {
197
+ * console.log("This file is in the root directory.");
198
+ * }
199
+ * @returns {FileSync | null} A new FileSync object representing the parent directory of the file,
200
+ * or null if the file is in the root directory.
201
+ */
202
+ get parent(): FileSync | null;
203
+ /**
204
+ * @description Gets the URI of the file.
205
+ * The URI is a string that represents the file's location in the file system.
206
+ * It is typically in the format `file:///path/to/file`.
207
+ * @example
208
+ * const file = new FileSync("path/to/file.txt");
209
+ * console.log("File URI:", file.uri);
210
+ * // Output: File URI: file:///path/to/file.txt
211
+ * @returns {string} The URI of the file.
212
+ */
213
+ get uri(): string;
214
+ /**
215
+ * @description Gets the path separator used by the file system.
216
+ * This is typically the forward slash (/) on Unix-like systems and the backslash (\) on Windows.
217
+ * @example
218
+ * const file = new FileSync("path/to/file.txt");
219
+ * console.log("Path separator:", file.separator);
220
+ * // Output: Path separator: /
221
+ * @returns {string} The path separator used by the file system.
222
+ */
223
+ get separator(): string;
224
+ /**
225
+ * @description Checks if the file is a directory.
226
+ * A directory is a file that contains other files or directories.
227
+ * @example
228
+ * const dir = new FileSync("path/to/directory");
229
+ * if (dir.isDirectory) {
230
+ * console.log("This is a directory.");
231
+ * } else {
232
+ * console.log("This is not a directory.");
233
+ * }
234
+ * @returns {boolean | null} True if the file is a directory, false if it is not, or null if the file does not exist.
235
+ */
236
+ get isDirectory(): boolean | null;
237
+ /**
238
+ * @description Checks if the file is a regular file.
239
+ * A regular file is a file that is not a directory or a symbolic link.
240
+ * @example
241
+ * const file = new FileSync("path/to/file.txt");
242
+ * if (file.isFile) {
243
+ * console.log("This is a regular file.");
244
+ * } else {
245
+ * console.log("This is not a regular file.");
246
+ * }
247
+ * @returns {boolean | null} True if the file is a regular file, false if it is not, or null if the file does not exist.
248
+ */
249
+ get isFile(): boolean | null;
250
+ /**
251
+ * @description Checks if the file is hidden.
252
+ * A file is considered hidden if its name starts with a dot (.) or if any part of its path starts with a dot.
253
+ * @example
254
+ * const file = new FileSync("path/to/.hiddenfile");
255
+ * if (file.isHidden) {
256
+ * console.log("This file is hidden.");
257
+ * } else {
258
+ * console.log("This file is not hidden.");
259
+ * }
260
+ * @returns {boolean} True if the file is hidden, false otherwise.
261
+ */
262
+ get isHidden(): boolean;
263
+ /**
264
+ * @description Checks if the file is a symbolic link.
265
+ * @example
266
+ * const file = new FileSync("path/to/symlink");
267
+ * if (file.isSymbolicLink) {
268
+ * console.log("This is a symbolic link.");
269
+ * } else {
270
+ * console.log("This is not a symbolic link.");
271
+ * }
272
+ * @returns {boolean | null} True if the file is a symbolic link, false if it is not, or null if the file does not exist.
273
+ */
274
+ get isSymbolicLink(): boolean | null;
275
+ /**
276
+ * @description Gets the size of the file in bytes.
277
+ * @example
278
+ * const file = new FileSync("path/to/file.txt");
279
+ * console.log("File size:", file.size, "bytes");
280
+ * @returns {number} The size of the file in bytes, or null if the file does not exist.
281
+ */
282
+ get size(): number | null;
283
+ /**
284
+ * @description Gets the size of the file in kilobytes (KB).
285
+ * This is calculated by dividing the size in bytes by 1024.
286
+ * If the file does not exist, it returns null.
287
+ * @example
288
+ * const file = new FileSync("path/to/file.txt");
289
+ * console.log("File size:", file.sizeKB, "KB");
290
+ * @returns {number | null} The size of the file in kilobytes (KB), or null if the file does not exist.
291
+ */
292
+ get sizeKB(): number | null;
293
+ /**
294
+ * @description Gets the size of the file in megabytes (MB).
295
+ * This is calculated by dividing the size in bytes by 1024 * 1024.
296
+ * If the file does not exist, it returns null.
297
+ * @example
298
+ * const file = new FileSync("path/to/file.txt");
299
+ * console.log("File size:", file.sizeMB, "MB");
300
+ * @returns {number | null} The size of the file in megabytes (MB), or null if the file does not exist.
301
+ */
302
+ get sizeMB(): number | null;
303
+ /**
304
+ * @description Gets the size of the file in gigabytes (GB).
305
+ * This is calculated by dividing the size in bytes by 1024 * 1024 * 1024.
306
+ * If the file does not exist, it returns null.
307
+ * @example
308
+ * const file = new FileSync("path/to/file.txt");
309
+ * console.log("File size:", file.sizeGB, "GB");
310
+ * @returns {number | null} The size of the file in gigabytes (GB), or null if the file does not exist.
311
+ */
312
+ get sizeGB(): number | null;
313
+ /**
314
+ * @description Creates a new FileSync object with the specified paths appended to the current file's path.
315
+ * This method allows you to create a new file or directory relative to the current file's path.
316
+ * @example
317
+ * const file = new FileSync("path/to/file.txt");
318
+ * const newFile = file.to("subdir", "newfile.txt");
319
+ * console.log("New file path:", newFile.path);
320
+ * // Output: New file path: path/to/file.txt/subdir/newfile.txt
321
+ * @param {...string} paths - The paths to append to the current file's path.
322
+ * @returns {FileSync} A new FileSync object with the updated path.
323
+ */
324
+ to(...paths: string[]): FileSync;
325
+ /**
326
+ * @description Checks if the current file path contains the specified path.
327
+ * This method checks if the current file's path is a parent of the specified path.
328
+ * @example
329
+ * const file = new FileSync("path/to/file.txt");
330
+ * const subFile = new FileSync("path/to/file.txt/subdir/subfile.txt");
331
+ * console.log(file.contains(subFile)); // Output: true
332
+ * @param {FileSync} path - The FileSync object to check against the current file's path.
333
+ * @returns {boolean} True if the current file's path contains the specified path, false otherwise.
334
+ */
335
+ contains(path: FileSync): boolean;
336
+ /**
337
+ * @description Creates a new file if it does not exist.
338
+ * @example
339
+ * const file = new FileSync("path/to/file.txt");
340
+ * if (file.createFile()) {
341
+ * console.log("File created or already exists.");
342
+ * } else {
343
+ * console.log("Failed to create file.");
344
+ * }
345
+ * @returns {FileSync | null} The FileSync object if the file was created successfully or already exists,
346
+ * or null if the file could not be created.
347
+ */
348
+ createFile(): FileSync | null;
349
+ /**
350
+ * @description Deletes the file or directory.
351
+ * If the file is a directory and `recursive` is true, it will delete all files and subdirectories within it.
352
+ * If `force` is true, it will ignore errors when deleting files or directories.
353
+ * @example
354
+ * const file = new FileSync("path/to/file.txt");
355
+ * if (file.delete(true)) {
356
+ * console.log("File deleted successfully.");
357
+ * } else {
358
+ * console.log("Failed to delete file.");
359
+ * }
360
+ * @param {boolean} recursive - Whether to delete the directory and its contents recursively.
361
+ * @param {boolean} [force=false] - Whether to force the deletion, ignoring errors.
362
+ * @returns {FileSync | null} The FileSync object if the file or directory was deleted successfully,
363
+ * or null if the file or directory does not exist or could not be deleted.
364
+ */
365
+ delete(recursive?: boolean, force?: boolean): FileSync | null;
366
+ /**
367
+ * @description Schedules the file or directory for deletion on exit.
368
+ * This method adds the file or directory to a queue that will be processed when the process
369
+ * exits. If `recursive` is true, it will delete all files and subdirectories within it.
370
+ * @example
371
+ * const file = new FileSync("path/to/file.txt");
372
+ * file.deleteOnExit(true);
373
+ * // The file will be deleted when the process exits.
374
+ * @param {boolean} [recursive=false] - Whether to delete the directory and its contents recursively.
375
+ * @returns {void}
376
+ */
377
+ deleteOnExit(recursive?: boolean): void;
378
+ /**
379
+ * @description Clears the contents of the file or directory.
380
+ * If the file is a directory and `recursive` is true, it will delete all
381
+ * files and subdirectories within it.
382
+ * If the file is not a directory, it will write an empty string to the file
383
+ * to clear its contents.
384
+ * @example
385
+ * const file = new FileSync("path/to/file.txt");
386
+ * if (file.clear(true)) {
387
+ * console.log("Directory cleared successfully.");
388
+ * } else {
389
+ * console.log("Failed to clear directory.");
390
+ * }
391
+ * @param {boolean} recursive - Whether to clear the directory and its contents recursively.
392
+ * @returns {FileSync | null} The FileSync object if the directory was cleared successfully,
393
+ * or null if the file is not a directory or could not be cleared.
394
+ */
395
+ clear(recursive: boolean): FileSync | null;
396
+ /**
397
+ * @description Lists all files in the directory.
398
+ * If the file is not a directory, it returns null.
399
+ * @example
400
+ * const dir = new FileSync("path/to/directory");
401
+ * const files = dir.listFiles();
402
+ * if (files) {
403
+ * files.forEach(file => console.log(file.name));
404
+ * } else {
405
+ * console.log("Not a directory or no files found.");
406
+ * }
407
+ * @returns {FileSync[] | null} An array of FileSync objects representing the files in the directory,
408
+ * or null if the file is not a directory.
409
+ */
410
+ listFiles(): FileSync[] | null;
411
+ /**
412
+ * @description Reads the contents of the directory.
413
+ * If the file is not a directory, it returns null.
414
+ * @example
415
+ * const dir = new FileSync("path/to/directory");
416
+ * const contents = dir.listFilenames();
417
+ * if (contents) {
418
+ * contents.forEach(item => console.log(item));
419
+ * } else {
420
+ * console.log("Not a directory or no contents found.");
421
+ * }
422
+ * @returns {string[] | null} An array of strings representing the names of the files and directories
423
+ * in the directory, or null if the file is not a directory.
424
+ */
425
+ listFilenames(): string[] | null;
426
+ /**
427
+ * @description Creates a directory at the specified path.
428
+ * If the directory already exists, it does nothing.
429
+ * If `recursive` is true, it will create all necessary parent directories.
430
+ * @example
431
+ * const dir = new FileSync("path/to/directory");
432
+ * if (dir.mkdir()) {
433
+ * console.log("Directory created successfully.");
434
+ * } else {
435
+ * console.log("Failed to create directory.");
436
+ * }
437
+ * @param {boolean} [recursive=false] - Whether to create parent directories if they do not exist.
438
+ * @returns {FileSync | null} The FileSync object if the directory was created successfully,
439
+ * or null if the directory could not be created.
440
+ */
441
+ mkdir(recursive?: boolean): FileSync | null;
442
+ /**
443
+ * @description Creates the directory and all necessary parent directories.
444
+ * If the directory already exists, it does nothing.
445
+ * This is a convenience method that calls `mkdir` with `recursive` set to true.
446
+ * @example
447
+ * const dir = new FileSync("path/to/directory");
448
+ * if (dir.mkdirs()) {
449
+ * console.log("Directories created successfully.");
450
+ * } else {
451
+ * console.log("Failed to create directories.");
452
+ * }
453
+ * @returns {FileSync | null} The FileSync object if the directories were created successfully,
454
+ */
455
+ mkdirs(): FileSync | null;
456
+ /**
457
+ * @description Renames the file or directory to the specified destination.
458
+ * If the destination already exists and `overwrite` is false, it will not overwrite it.
459
+ * If `recursive` is true, it will create parent directories if they do not exist.
460
+ * If the source and destination paths are the same, it does nothing and returns the current FileSync object.
461
+ * @example
462
+ * const file = new FileSync("path/to/source.txt");
463
+ * const dest = new FileSync("path/to/destination.txt");
464
+ * if (file.renameTo(dest, true)) {
465
+ * console.log("File renamed successfully.");
466
+ * } else {
467
+ * console.log("Failed to rename file.");
468
+ * }
469
+ * @param {FileSync} dest - The destination directory to rename to.
470
+ * @param {boolean} [overwrite=false] - Whether to overwrite the destination if it already exists.
471
+ * @param {boolean} [recursive=false] - Whether to create parent directories if they do not exist and
472
+ * delete the destination directory recursively if it already exists.
473
+ * @returns {FileSync | null} The FileSync object if the directory was renamed successfully,
474
+ * or null if the directory could not be renamed.
475
+ */
476
+ renameTo(dest: FileSync, overwrite?: boolean, recursive?: boolean): FileSync | null;
477
+ /**
478
+ * @description Copies the file to the specified destination.
479
+ * If the destination file already exists and `overwrite` is false, it will not overwrite it.
480
+ * If `recursive` is true, it will copy the contents of the directory recursively.
481
+ * @example
482
+ * const file = new FileSync("path/to/source.txt");
483
+ * const dest = new FileSync("path/to/destination.txt");
484
+ * if (file.copyTo(dest, true)) {
485
+ * console.log("File copied successfully.");
486
+ * } else {
487
+ * console.log("Failed to copy file.");
488
+ * }
489
+ * @param {FileSync} dest - The destination file to copy to.
490
+ * @param {boolean} [overwrite=false] - Whether to overwrite the destination file if it already exists.
491
+ * @param {boolean} [recursive=false] - Whether to copy the contents of the directory recursively and
492
+ * delete the destination directory recursively if it already exists.
493
+ * @returns {FileSync | null} The FileSync object if the file was copied successfully,
494
+ * or null if the file could not be copied.
495
+ */
496
+ copyTo(dest: FileSync, overwrite?: boolean, recursive?: boolean): FileSync | null;
497
+ /**
498
+ * @description Walks through the directory and yields each file.
499
+ * If the file is a directory, it will yield the directory and then recursively yield all files within it.
500
+ * If the file is not a directory, it will yield the file itself.
501
+ * @example
502
+ * const dir = new FileSync("path/to/directory");
503
+ * for (const file of dir.walk()) {
504
+ * console.log(file.name);
505
+ * }
506
+ * @returns {Generator<FileSync>} A generator that yields FileSync objects representing the files
507
+ * in the directory and its subdirectories.
508
+ * If the file is not a directory, it will yield the file itself.
509
+ * @yields {FileSync} Each file or directory found during the walk, including subdirectories and their contents.
510
+ */
511
+ walk(): Generator<FileSync>;
512
+ /**
513
+ * @description Reads the contents of the file.
514
+ * If the file is a text file, it will return the contents as a string.
515
+ * If the file is a binary file, it will return the contents as a Buffer.
516
+ * @example
517
+ * const file = new FileSync("path/to/file.txt");
518
+ * const contents = file.read("utf8");
519
+ * if (contents) {
520
+ * console.log("File contents:", contents);
521
+ * } else {
522
+ * console.log("Failed to read file.");
523
+ * }
524
+ * @param {BufferEncoding} [encoding="utf8"] - The encoding to use when reading the file.
525
+ * If not specified, it will return a Buffer for binary files.
526
+ * If specified, it will return a string for text files.
527
+ * @returns {string | Buffer} The contents of the file as a string if encoding is specified,
528
+ * or as a Buffer if encoding is not specified.
529
+ * If reading fails, it will return null.
530
+ */
531
+ read(encoding?: BufferEncoding): string | null;
532
+ /**
533
+ * @description Reads the contents of the file as a Buffer.
534
+ * If the file is a binary file, it will return the contents as a Buffer.
535
+ * If the file is a text file, it will return the contents as a Buffer.
536
+ * @example
537
+ * const file = new FileSync("path/to/file.txt");
538
+ * const contents = file.read();
539
+ * if (contents) {
540
+ * console.log("File contents as Buffer:", contents);
541
+ * } else {
542
+ * console.log("Failed to read file.");
543
+ * }
544
+ * @returns {Buffer} The contents of the file as a Buffer.
545
+ * If reading fails, it will return null.
546
+ */
547
+ read(): Buffer | null;
548
+ /**
549
+ * @description Reads the contents of the file as an array of lines.
550
+ * If the file is a text file, it will split the contents by new lines.
551
+ * If the file is a binary file, it will return null.
552
+ * @example
553
+ * const file = new FileSync("path/to/file.txt");
554
+ * const lines = file.readLines("utf8");
555
+ * if (lines) {
556
+ * lines.forEach(line => console.log(line));
557
+ * } else {
558
+ * console.log("Failed to read file or not a text file.");
559
+ * }
560
+ * @param {BufferEncoding} [encoding="utf8"] - The encoding to use when reading the file.
561
+ * If not specified, it will return null for binary files.
562
+ * @returns {string[] | null} An array of strings representing the lines in the file,
563
+ * or null if the file is a binary file or if reading failed.
564
+ */
565
+ readLines(encoding?: BufferEncoding): string[] | null;
566
+ /**
567
+ * @description Reads the contents of the file as JSON.
568
+ * If the file is a valid JSON file, it will parse and return the contents as an object.
569
+ * If the file is not a valid JSON file or reading fails, it will return null.
570
+ * @example
571
+ * const file = new FileSync("path/to/file.json");
572
+ * const jsonData = file.readJSON();
573
+ * if (jsonData) {
574
+ * console.log("JSON data:", jsonData);
575
+ * } else {
576
+ * console.log("Failed to read JSON or not a valid JSON file.");
577
+ * }
578
+ * @returns The parsed JSON data as an object of type T, or null if reading failed or not valid JSON.
579
+ */
580
+ readJSON<T = unknown>(): T | null;
581
+ /**
582
+ * @description Reads the symbolic link target of the file.
583
+ * If the file is a symbolic link, it will return a new FileSync object pointing to the target.
584
+ * If the file is not a symbolic link, it will return null.
585
+ * @example
586
+ * const link = new FileSync("path/to/symlink");
587
+ * const target = link.readlink();
588
+ * if (target) {
589
+ * console.log("Symbolic link points to:", target.path);
590
+ * } else {
591
+ * console.log("Not a symbolic link or reading failed.");
592
+ * }
593
+ * @returns {FileSync | null} A new FileSync object pointing to the target of the symbolic link,
594
+ * or null if the file is not a symbolic link.
595
+ */
596
+ readlink(): FileSync | null;
597
+ /**
598
+ * @description Writes data to the file.
599
+ * If the file does not exist, it will create the file.
600
+ * If the file exists, it will overwrite the contents with the provided data.
601
+ * @example
602
+ * const file = new FileSync("path/to/file.txt");
603
+ * if (file.write("Hello, World!", "utf8")) {
604
+ * console.log("Data written successfully.");
605
+ * } else {
606
+ * console.log("Failed to write data.");
607
+ * }
608
+ * @param data - The data to write to the file.
609
+ * @param {Object} encoding - The encoding to use when writing the data.
610
+ * @returns {FileSync | null} True if the data was written successfully, false otherwise.
611
+ */
612
+ write<T>(data: T, encoding: {
613
+ write(): T;
614
+ }): FileSync | null;
615
+ /**
616
+ * @description Writes data to the file.
617
+ * If the file does not exist, it will create the file.
618
+ * If the file exists, it will overwrite the contents with the provided data.
619
+ * @example
620
+ * const file = new FileSync("path/to/file.txt");
621
+ * if (file.write("Hello, World!", "utf8")) {
622
+ * console.log("Data written successfully.");
623
+ * } else {
624
+ * console.log("Failed to write data.");
625
+ * }
626
+ * @param {string | Buffer} data - The data to write to the file.
627
+ * @param {BufferEncoding} [encoding="utf8"] - The encoding to use when writing the data.
628
+ * If not specified, it will write the data as a Buffer.
629
+ * @returns {FileSync | null} True if the data was written successfully, false otherwise.
630
+ */
631
+ write(data: string | Buffer, encoding?: BufferEncoding): FileSync | null;
632
+ /**
633
+ * @description Writes JSON data to the file.
634
+ * If the file does not exist, it will create the file.
635
+ * If the file exists, it will overwrite the contents with the provided JSON data.
636
+ * @example
637
+ * const file = new FileSync("path/to/file.json");
638
+ * const jsonData = { key: "value" };
639
+ * if (file.writeJSON(jsonData)) {
640
+ * console.log("JSON data written successfully.");
641
+ * } else {
642
+ * console.log("Failed to write JSON data.");
643
+ * }
644
+ * @param {unknown} data - The JSON data to write to the file.
645
+ * @returns {boolean} True if the JSON data was written successfully, false otherwise.
646
+ */
647
+ writeJSON(data: unknown): FileSync | null;
648
+ /**
649
+ * @description Appends data to the file.
650
+ * If the file does not exist, it will create the file.
651
+ * If the file exists, it will append the data to the end of the file.
652
+ * @example
653
+ * const file = new FileSync("path/to/file.txt");
654
+ * if (file.append("Hello, World!", "utf8")) {
655
+ * console.log("Data appended successfully.");
656
+ * } else {
657
+ * console.log("Failed to append data.");
658
+ * }
659
+ * @param {string | Buffer} data - The data to append to the file.
660
+ * @param {BufferEncoding} [encoding="utf8"] - The encoding to use when appending the data.
661
+ * If not specified, it will append the data as a Buffer.
662
+ * @returns {FileSync | null} The FileSync object if the data was appended successfully,
663
+ * or null if appending failed.
664
+ */
665
+ append(data: string | Buffer, encoding?: BufferEncoding): FileSync | null;
666
+ get async(): FileAsync;
667
+ }