@gjsify/fs 0.0.4 → 0.1.0

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.
Files changed (91) hide show
  1. package/README.md +31 -2
  2. package/lib/esm/callback.js +251 -15
  3. package/lib/esm/dirent.js +47 -6
  4. package/lib/esm/encoding.js +2 -3
  5. package/lib/esm/errors.js +13 -0
  6. package/lib/esm/file-handle.js +108 -66
  7. package/lib/esm/fs-watcher.js +44 -7
  8. package/lib/esm/index.js +140 -5
  9. package/lib/esm/promises.js +290 -69
  10. package/lib/esm/read-stream.js +82 -57
  11. package/lib/esm/stats.js +138 -18
  12. package/lib/esm/sync.js +293 -44
  13. package/lib/esm/write-stream.js +4 -4
  14. package/lib/types/callback.d.ts +233 -0
  15. package/lib/types/dirent.d.ts +77 -0
  16. package/lib/types/encoding.d.ts +6 -0
  17. package/lib/types/errors.d.ts +7 -0
  18. package/lib/types/file-handle.d.ts +367 -0
  19. package/lib/types/fs-watcher.d.ts +17 -0
  20. package/lib/types/index.d.ts +149 -0
  21. package/lib/types/promises.d.ts +158 -0
  22. package/lib/types/read-stream.d.ts +21 -0
  23. package/lib/types/stats.d.ts +67 -0
  24. package/lib/types/sync.d.ts +109 -0
  25. package/lib/types/types/encoding-option.d.ts +2 -0
  26. package/lib/types/types/file-read-options.d.ts +15 -0
  27. package/lib/types/types/file-read-result.d.ts +4 -0
  28. package/lib/types/types/flag-and-open-mode.d.ts +5 -0
  29. package/lib/types/types/index.d.ts +6 -0
  30. package/lib/types/types/open-flags.d.ts +1 -0
  31. package/lib/types/types/read-options.d.ts +5 -0
  32. package/lib/types/utils.d.ts +2 -0
  33. package/lib/types/write-stream.d.ts +45 -0
  34. package/package.json +22 -35
  35. package/src/callback.spec.ts +284 -30
  36. package/src/callback.ts +352 -39
  37. package/src/dirent.ts +56 -8
  38. package/src/encoding.ts +7 -2
  39. package/src/errors.spec.ts +389 -0
  40. package/src/errors.ts +19 -0
  41. package/src/extended.spec.ts +706 -0
  42. package/src/file-handle.spec.ts +104 -23
  43. package/src/file-handle.ts +147 -79
  44. package/src/fs-watcher.ts +55 -8
  45. package/src/index.ts +146 -2
  46. package/src/new-apis.spec.ts +505 -0
  47. package/src/promises.spec.ts +651 -11
  48. package/src/promises.ts +353 -81
  49. package/src/read-stream.ts +98 -74
  50. package/src/stat.spec.ts +22 -14
  51. package/src/stats.ts +176 -75
  52. package/src/streams.spec.ts +455 -0
  53. package/src/symlink.spec.ts +176 -26
  54. package/src/sync.spec.ts +204 -32
  55. package/src/sync.ts +363 -58
  56. package/src/test.mts +7 -2
  57. package/src/types/encoding-option.ts +1 -1
  58. package/src/types/flag-and-open-mode.ts +1 -1
  59. package/src/types/read-options.ts +2 -2
  60. package/src/utils.ts +2 -0
  61. package/src/write-stream.ts +9 -7
  62. package/tsconfig.json +23 -10
  63. package/tsconfig.tsbuildinfo +1 -0
  64. package/lib/cjs/callback.js +0 -112
  65. package/lib/cjs/dirent.js +0 -98
  66. package/lib/cjs/encoding.js +0 -34
  67. package/lib/cjs/file-handle.js +0 -444
  68. package/lib/cjs/fs-watcher.js +0 -50
  69. package/lib/cjs/index.js +0 -95
  70. package/lib/cjs/promises.js +0 -160
  71. package/lib/cjs/read-stream.js +0 -78
  72. package/lib/cjs/stats.js +0 -45
  73. package/lib/cjs/sync.js +0 -126
  74. package/lib/cjs/types/encoding-option.js +0 -0
  75. package/lib/cjs/types/file-read-options.js +0 -0
  76. package/lib/cjs/types/file-read-result.js +0 -0
  77. package/lib/cjs/types/flag-and-open-mode.js +0 -0
  78. package/lib/cjs/types/index.js +0 -6
  79. package/lib/cjs/types/open-flags.js +0 -0
  80. package/lib/cjs/types/read-options.js +0 -0
  81. package/lib/cjs/utils.js +0 -18
  82. package/lib/cjs/write-stream.js +0 -116
  83. package/test/watch.js +0 -1
  84. package/test.gjs.js +0 -35359
  85. package/test.gjs.js.map +0 -7
  86. package/test.gjs.mjs +0 -40534
  87. package/test.gjs.mjs.meta.json +0 -1
  88. package/test.node.js +0 -1479
  89. package/test.node.js.map +0 -7
  90. package/test.node.mjs +0 -710
  91. package/tsconfig.types.json +0 -8
@@ -0,0 +1,158 @@
1
+ import { FileHandle } from './file-handle.js';
2
+ import { Dirent } from './dirent.js';
3
+ import { Stats, BigIntStats } from './stats.js';
4
+ import type { OpenFlags, ReadOptions } from './types/index.js';
5
+ import type { PathLike, Mode, RmOptions, ObjectEncodingOptions, BufferEncodingOption, MakeDirectoryOptions, RmDirOptions } from 'node:fs';
6
+ /**
7
+ * Asynchronously creates a directory.
8
+ *
9
+ * The optional `options` argument can be an integer specifying `mode` (permission
10
+ * and sticky bits), or an object with a `mode` property and a `recursive`property indicating whether parent directories should be created. Calling`fsPromises.mkdir()` when `path` is a directory
11
+ * that exists results in a
12
+ * rejection only when `recursive` is false.
13
+ * @since v10.0.0
14
+ * @return Upon success, fulfills with `undefined` if `recursive` is `false`, or the first directory path created if `recursive` is `true`.
15
+ */
16
+ declare function mkdir(path: PathLike, options: MakeDirectoryOptions & {
17
+ recursive: true;
18
+ }): Promise<string | undefined>;
19
+ /**
20
+ * Asynchronous mkdir(2) - create a directory.
21
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
22
+ * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
23
+ * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
24
+ */
25
+ declare function mkdir(path: PathLike, options?: Mode | (MakeDirectoryOptions & {
26
+ recursive?: false | undefined;
27
+ }) | null): Promise<void>;
28
+ /**
29
+ * Asynchronous mkdir(2) - create a directory.
30
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
31
+ * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
32
+ * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
33
+ */
34
+ declare function mkdir(path: PathLike, options?: Mode | MakeDirectoryOptions | null): Promise<string | undefined>;
35
+ declare function readFile(path: PathLike | FileHandle, options?: ReadOptions): Promise<string | Buffer<ArrayBuffer>>;
36
+ /**
37
+ * Creates a unique temporary directory. A unique directory name is generated by
38
+ * appending six random characters to the end of the provided `prefix`. Due to
39
+ * platform inconsistencies, avoid trailing `X` characters in `prefix`. Some
40
+ * platforms, notably the BSDs, can return more than six random characters, and
41
+ * replace trailing `X` characters in `prefix` with random characters.
42
+ *
43
+ * The optional `options` argument can be a string specifying an encoding, or an
44
+ * object with an `encoding` property specifying the character encoding to use.
45
+ *
46
+ * ```js
47
+ * import { mkdtemp } from 'node:fs/promises';
48
+ *
49
+ * try {
50
+ * await mkdtemp(path.join(os.tmpdir(), 'foo-'));
51
+ * } catch (err) {
52
+ * console.error(err);
53
+ * }
54
+ * ```
55
+ *
56
+ * The `fsPromises.mkdtemp()` method will append the six randomly selected
57
+ * characters directly to the `prefix` string. For instance, given a directory`/tmp`, if the intention is to create a temporary directory _within_`/tmp`, the`prefix` must end with a trailing
58
+ * platform-specific path separator
59
+ * (`require('path').sep`).
60
+ * @since v10.0.0
61
+ * @return Fulfills with a string containing the filesystem path of the newly created temporary directory.
62
+ */
63
+ declare function mkdtemp(prefix: string, options?: ObjectEncodingOptions | BufferEncoding | null): Promise<string>;
64
+ /**
65
+ * Asynchronously creates a unique temporary directory.
66
+ * Generates six random characters to be appended behind a required `prefix` to create a unique temporary directory.
67
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
68
+ */
69
+ declare function mkdtemp(prefix: string, options: BufferEncodingOption): Promise<Buffer>;
70
+ /**
71
+ * Asynchronously creates a unique temporary directory.
72
+ * Generates six random characters to be appended behind a required `prefix` to create a unique temporary directory.
73
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
74
+ */
75
+ declare function mkdtemp(prefix: string, options?: ObjectEncodingOptions | BufferEncoding | null): Promise<string | Buffer>;
76
+ declare function writeFile(path: string, data: string | Uint8Array | unknown): Promise<void>;
77
+ /**
78
+ * Removes the directory identified by `path`.
79
+ *
80
+ * Using `fsPromises.rmdir()` on a file (not a directory) results in the
81
+ * promise being rejected with an `ENOENT` error on Windows and an `ENOTDIR`error on POSIX.
82
+ *
83
+ * To get a behavior similar to the `rm -rf` Unix command, use `fsPromises.rm()` with options `{ recursive: true, force: true }`.
84
+ * @since v10.0.0
85
+ * @return Fulfills with `undefined` upon success.
86
+ */
87
+ declare function rmdir(path: PathLike, _options?: RmDirOptions): Promise<void>;
88
+ declare function unlink(path: string): Promise<void>;
89
+ declare function open(path: PathLike, flags?: OpenFlags, mode?: Mode): Promise<FileHandle>;
90
+ declare function write<TBuffer extends Uint8Array>(fd: number, buffer: TBuffer, offset?: number | null, length?: number | null, position?: number | null): Promise<{
91
+ bytesWritten: number;
92
+ buffer: TBuffer;
93
+ }>;
94
+ declare function write(fd: number, data: string, position?: number | null, encoding?: BufferEncoding | null): Promise<{
95
+ bytesWritten: number;
96
+ buffer: string;
97
+ }>;
98
+ declare function stat(path: PathLike, options?: {
99
+ bigint?: boolean;
100
+ }): Promise<Stats | BigIntStats>;
101
+ declare function lstat(path: PathLike, options?: {
102
+ bigint?: boolean;
103
+ }): Promise<Stats | BigIntStats>;
104
+ declare function readdir(path: PathLike, options?: {
105
+ withFileTypes?: boolean;
106
+ encoding?: string;
107
+ recursive?: boolean;
108
+ }): Promise<string[] | Dirent[]>;
109
+ declare function realpath(path: PathLike): Promise<string>;
110
+ declare function symlink(target: PathLike, path: PathLike, _type?: string): Promise<void>;
111
+ /**
112
+ * Removes files and directories (modeled on the standard POSIX `rm` utility).
113
+ * @since v14.14.0
114
+ * @return Fulfills with `undefined` upon success.
115
+ */
116
+ declare function rm(path: PathLike, options?: RmOptions): Promise<void>;
117
+ declare function rename(oldPath: PathLike, newPath: PathLike): Promise<void>;
118
+ declare function copyFile(src: PathLike, dest: PathLike, mode?: number): Promise<void>;
119
+ declare function access(path: PathLike, mode?: number): Promise<void>;
120
+ declare function appendFile(path: PathLike, data: string | Uint8Array, options?: {
121
+ encoding?: string;
122
+ mode?: number;
123
+ flag?: string;
124
+ } | string): Promise<void>;
125
+ declare function readlink(path: PathLike, options?: {
126
+ encoding?: string;
127
+ } | string): Promise<string | Buffer>;
128
+ declare function truncate(path: PathLike, len?: number): Promise<void>;
129
+ declare function chmod(path: PathLike, mode: number | string): Promise<void>;
130
+ declare function chown(path: PathLike, uid: number, gid: number): Promise<void>;
131
+ declare function link(existingPath: PathLike, newPath: PathLike): Promise<void>;
132
+ export { readFile, mkdir, mkdtemp, realpath, readdir, writeFile, rmdir, unlink, open, write, rm, lstat, symlink, stat, rename, copyFile, access, appendFile, readlink, truncate, chmod, chown, link, };
133
+ declare const _default: {
134
+ readFile: typeof readFile;
135
+ mkdir: typeof mkdir;
136
+ mkdtemp: typeof mkdtemp;
137
+ realpath: typeof realpath;
138
+ readdir: typeof readdir;
139
+ writeFile: typeof writeFile;
140
+ rmdir: typeof rmdir;
141
+ unlink: typeof unlink;
142
+ open: typeof open;
143
+ write: typeof write;
144
+ rm: typeof rm;
145
+ lstat: typeof lstat;
146
+ symlink: typeof symlink;
147
+ stat: typeof stat;
148
+ rename: typeof rename;
149
+ copyFile: typeof copyFile;
150
+ access: typeof access;
151
+ appendFile: typeof appendFile;
152
+ readlink: typeof readlink;
153
+ truncate: typeof truncate;
154
+ chmod: typeof chmod;
155
+ chown: typeof chown;
156
+ link: typeof link;
157
+ };
158
+ export default _default;
@@ -0,0 +1,21 @@
1
+ import { Buffer } from "node:buffer";
2
+ import { Readable } from "node:stream";
3
+ import { URL } from "node:url";
4
+ import type { CreateReadStreamOptions } from 'node:fs/promises';
5
+ import type { PathLike, ReadStream as IReadStream } from 'node:fs';
6
+ export declare class ReadStream extends Readable implements IReadStream {
7
+ bytesRead: number;
8
+ path: string | Buffer;
9
+ pending: boolean;
10
+ fd: number | null;
11
+ private _gioFile;
12
+ private _inputStream;
13
+ private _start;
14
+ private _end;
15
+ private _pos;
16
+ close(callback?: (err?: NodeJS.ErrnoException | null) => void): void;
17
+ constructor(path: PathLike, opts?: CreateReadStreamOptions);
18
+ _read(size: number): void;
19
+ _destroy(error: Error | null, callback: (error?: Error | null) => void): void;
20
+ }
21
+ export declare function createReadStream(path: string | URL, options?: CreateReadStreamOptions): ReadStream;
@@ -0,0 +1,67 @@
1
+ import Gio from '@girs/gio-2.0';
2
+ import { Dirent } from './dirent.js';
3
+ import type { Stats as NodeStats, BigIntStats as NodeBigIntStats, PathLike } from 'node:fs';
4
+ export declare const STAT_ATTRIBUTES = "standard::*,time::*,unix::*";
5
+ /**
6
+ * A `fs.Stats` object provides information about a file.
7
+ * @since v0.1.21
8
+ */
9
+ export declare class Stats extends Dirent implements NodeStats {
10
+ dev: number;
11
+ ino: number;
12
+ mode: number;
13
+ nlink: number;
14
+ uid: number;
15
+ gid: number;
16
+ rdev: number;
17
+ size: number;
18
+ blksize: number;
19
+ blocks: number;
20
+ atimeMs: number;
21
+ mtimeMs: number;
22
+ ctimeMs: number;
23
+ birthtimeMs: number;
24
+ atime: Date;
25
+ mtime: Date;
26
+ ctime: Date;
27
+ birthtime: Date;
28
+ protected _info: Gio.FileInfo;
29
+ /**
30
+ * Create Stats from a pre-queried FileInfo, or from a path.
31
+ * @param infoOrPath - A Gio.FileInfo or a file path
32
+ * @param pathOrFilename - The file path (when first arg is FileInfo) or filename
33
+ * @param filename - Optional filename (when first arg is FileInfo)
34
+ */
35
+ constructor(info: Gio.FileInfo, path: PathLike, filename?: string);
36
+ constructor(path: PathLike, filename?: string);
37
+ }
38
+ /**
39
+ * BigIntStats — same as Stats but with bigint fields and nanosecond precision.
40
+ */
41
+ export declare class BigIntStats extends Dirent implements NodeBigIntStats {
42
+ dev: bigint;
43
+ ino: bigint;
44
+ mode: bigint;
45
+ nlink: bigint;
46
+ uid: bigint;
47
+ gid: bigint;
48
+ rdev: bigint;
49
+ size: bigint;
50
+ blksize: bigint;
51
+ blocks: bigint;
52
+ atimeMs: bigint;
53
+ mtimeMs: bigint;
54
+ ctimeMs: bigint;
55
+ birthtimeMs: bigint;
56
+ atimeNs: bigint;
57
+ mtimeNs: bigint;
58
+ ctimeNs: bigint;
59
+ birthtimeNs: bigint;
60
+ atime: Date;
61
+ mtime: Date;
62
+ ctime: Date;
63
+ birthtime: Date;
64
+ protected _info: Gio.FileInfo;
65
+ constructor(info: Gio.FileInfo, path: PathLike, filename?: string);
66
+ constructor(path: PathLike, filename?: string);
67
+ }
@@ -0,0 +1,109 @@
1
+ import { existsSync } from '@gjsify/utils';
2
+ import { Buffer } from 'node:buffer';
3
+ import FSWatcher from './fs-watcher.js';
4
+ import { FileHandle } from './file-handle.js';
5
+ import { Dirent } from './dirent.js';
6
+ import { Stats, BigIntStats } from './stats.js';
7
+ import type { OpenFlags, EncodingOption } from './types/index.js';
8
+ import type { PathLike, Mode, MakeDirectoryOptions, BufferEncodingOption, RmOptions, RmDirOptions, StatSyncOptions } from 'node:fs';
9
+ export { existsSync };
10
+ export declare function statSync(path: PathLike, options?: StatSyncOptions): Stats | BigIntStats | undefined;
11
+ export declare function lstatSync(path: PathLike, options?: StatSyncOptions): Stats | BigIntStats | undefined;
12
+ export declare function readdirSync(path: PathLike, options?: {
13
+ withFileTypes?: boolean;
14
+ encoding?: string;
15
+ recursive?: boolean;
16
+ }): string[] | Dirent[];
17
+ export declare function realpathSync(path: PathLike): string;
18
+ export declare function symlinkSync(target: PathLike, path: PathLike, _type?: 'file' | 'dir' | 'junction'): void;
19
+ export declare function readFileSync(path: string, options?: {
20
+ encoding: any;
21
+ flag: string;
22
+ }): string | Buffer<ArrayBuffer>;
23
+ /**
24
+ * Synchronously creates a directory. Returns `undefined`, or if `recursive` is`true`, the first directory path created.
25
+ * This is the synchronous version of {@link mkdir}.
26
+ *
27
+ * See the POSIX [`mkdir(2)`](http://man7.org/linux/man-pages/man2/mkdir.2.html) documentation for more details.
28
+ * @since v0.1.21
29
+ */
30
+ export declare function mkdirSync(path: PathLike, options: MakeDirectoryOptions & {
31
+ recursive: true;
32
+ }): string | undefined;
33
+ /**
34
+ * Synchronous mkdir(2) - create a directory.
35
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
36
+ * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
37
+ * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
38
+ */
39
+ export declare function mkdirSync(path: PathLike, options?: Mode | (MakeDirectoryOptions & {
40
+ recursive?: false | undefined;
41
+ }) | null): void;
42
+ /**
43
+ * Synchronous mkdir(2) - create a directory.
44
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
45
+ * @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
46
+ * should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
47
+ */
48
+ export declare function mkdirSync(path: PathLike, options?: Mode | MakeDirectoryOptions | null): string | undefined | void;
49
+ /**
50
+ * Synchronous [`rmdir(2)`](http://man7.org/linux/man-pages/man2/rmdir.2.html). Returns `undefined`.
51
+ *
52
+ * Using `fs.rmdirSync()` on a file (not a directory) results in an `ENOENT` error
53
+ * on Windows and an `ENOTDIR` error on POSIX.
54
+ *
55
+ * To get a behavior similar to the `rm -rf` Unix command, use {@link rmSync} with options `{ recursive: true, force: true }`.
56
+ * @since v0.1.21
57
+ */
58
+ export declare function rmdirSync(path: PathLike, _options?: RmDirOptions): void;
59
+ export declare function unlinkSync(path: PathLike): void;
60
+ export declare function writeFileSync(path: string, data: string | Uint8Array): void;
61
+ export declare function renameSync(oldPath: PathLike, newPath: PathLike): void;
62
+ export declare function copyFileSync(src: PathLike, dest: PathLike, mode?: number): void;
63
+ export declare function accessSync(path: PathLike, mode?: number): void;
64
+ export declare function appendFileSync(path: PathLike, data: string | Uint8Array, options?: {
65
+ encoding?: string;
66
+ mode?: number;
67
+ flag?: string;
68
+ } | string): void;
69
+ export declare function readlinkSync(path: PathLike, options?: {
70
+ encoding?: string;
71
+ } | string): string | Buffer;
72
+ export declare function linkSync(existingPath: PathLike, newPath: PathLike): void;
73
+ export declare function truncateSync(path: PathLike, len?: number): void;
74
+ export declare function chmodSync(path: PathLike, mode: Mode): void;
75
+ export declare function chownSync(path: PathLike, uid: number, gid: number): void;
76
+ export declare function watch(filename: string, options: {
77
+ persistent?: boolean;
78
+ recursive?: boolean;
79
+ encoding?: string;
80
+ } | undefined, listener: ((eventType: string, filename: string | null) => void) | undefined): FSWatcher;
81
+ export declare function openSync(path: PathLike, flags?: OpenFlags, mode?: Mode): FileHandle;
82
+ /**
83
+ * Returns the created directory path.
84
+ *
85
+ * For detailed information, see the documentation of the asynchronous version of
86
+ * this API: {@link mkdtemp}.
87
+ *
88
+ * The optional `options` argument can be a string specifying an encoding, or an
89
+ * object with an `encoding` property specifying the character encoding to use.
90
+ * @since v5.10.0
91
+ */
92
+ export declare function mkdtempSync(prefix: string, options?: EncodingOption): string;
93
+ /**
94
+ * Synchronously creates a unique temporary directory.
95
+ * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
96
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
97
+ */
98
+ export declare function mkdtempSync(prefix: string, options: BufferEncodingOption): Buffer;
99
+ /**
100
+ * Synchronously creates a unique temporary directory.
101
+ * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
102
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
103
+ */
104
+ export declare function mkdtempSync(prefix: string, options?: EncodingOption): string | Buffer;
105
+ /**
106
+ * Synchronously removes files and directories (modeled on the standard POSIX `rm`utility). Returns `undefined`.
107
+ * @since v14.14.0
108
+ */
109
+ export declare function rmSync(path: PathLike, options?: RmOptions): void;
@@ -0,0 +1,2 @@
1
+ import type { ObjectEncodingOptions } from 'node:fs';
2
+ export type EncodingOption = ObjectEncodingOptions | BufferEncoding | undefined | null;
@@ -0,0 +1,15 @@
1
+ export interface FileReadOptions<T extends NodeJS.ArrayBufferView = Buffer> {
2
+ /**
3
+ * @default `Buffer.alloc(0xffff)`
4
+ */
5
+ buffer?: T;
6
+ /**
7
+ * @default 0
8
+ */
9
+ offset?: number | null;
10
+ /**
11
+ * @default `buffer.byteLength`
12
+ */
13
+ length?: number | null;
14
+ position?: number | null;
15
+ }
@@ -0,0 +1,4 @@
1
+ export interface FileReadResult<T extends NodeJS.ArrayBufferView> {
2
+ bytesRead: number;
3
+ buffer: T;
4
+ }
@@ -0,0 +1,5 @@
1
+ import type { Mode, OpenMode } from 'node:fs';
2
+ export interface FlagAndOpenMode {
3
+ mode?: Mode | undefined;
4
+ flag?: OpenMode | undefined;
5
+ }
@@ -0,0 +1,6 @@
1
+ export * from './encoding-option.js';
2
+ export * from './file-read-options.js';
3
+ export * from './file-read-result.js';
4
+ export * from './flag-and-open-mode.js';
5
+ export * from './open-flags.js';
6
+ export * from './read-options.js';
@@ -0,0 +1 @@
1
+ export type OpenFlags = "a" | "ax" | "a+" | "ax+" | "as" | "as+" | "r" | "r+" | "rs+" | "w" | "wx" | "w+" | "wx+";
@@ -0,0 +1,5 @@
1
+ import type { Abortable } from 'node:events';
2
+ import type { ObjectEncodingOptions, OpenMode } from 'node:fs';
3
+ export type ReadOptions = (ObjectEncodingOptions & Abortable & {
4
+ flag?: OpenMode | undefined;
5
+ }) | BufferEncoding | null;
@@ -0,0 +1,2 @@
1
+ export declare function randomName(): string;
2
+ export declare function tempDirPath(prefix: string): string;
@@ -0,0 +1,45 @@
1
+ import { Writable } from "node:stream";
2
+ import { URL } from "node:url";
3
+ import type { OpenFlags } from './types/index.js';
4
+ import type { PathLike, WriteStream as IWriteStream } from 'node:fs';
5
+ import type { CreateWriteStreamOptions } from 'node:fs/promises';
6
+ declare const kIsPerformingIO: unique symbol;
7
+ export declare function toPathIfFileURL(fileURLOrPath: string | Buffer | URL): string | Buffer;
8
+ export declare class WriteStream extends Writable implements IWriteStream {
9
+ /**
10
+ * Closes `writeStream`. Optionally accepts a
11
+ * callback that will be executed once the `writeStream`is closed.
12
+ * @since v0.9.4
13
+ */
14
+ close(callback?: (err?: NodeJS.ErrnoException | null) => void, err?: Error | null): void;
15
+ /**
16
+ * The number of bytes written so far. Does not include data that is still queued
17
+ * for writing.
18
+ * @since v0.4.7
19
+ */
20
+ bytesWritten: number;
21
+ /**
22
+ * The path to the file the stream is writing to as specified in the first
23
+ * argument to {@link createWriteStream}. If `path` is passed as a string, then`writeStream.path` will be a string. If `path` is passed as a `Buffer`, then`writeStream.path` will be a
24
+ * `Buffer`.
25
+ * @since v0.1.93
26
+ */
27
+ path: string | Buffer;
28
+ /**
29
+ * This property is `true` if the underlying file has not been opened yet,
30
+ * i.e. before the `'ready'` event is emitted.
31
+ * @since v11.2.0
32
+ */
33
+ pending: boolean;
34
+ fd: number | null;
35
+ flags: OpenFlags;
36
+ mode: number;
37
+ pos: number;
38
+ [kIsPerformingIO]: boolean;
39
+ constructor(path: PathLike, opts?: CreateWriteStreamOptions);
40
+ _construct(callback: (err?: Error) => void): void;
41
+ _write(data: Buffer, _encoding: string, cb: (err?: Error | null) => void): void;
42
+ _destroy(err: Error, cb: (err?: Error | null) => void): void;
43
+ }
44
+ export declare function createWriteStream(path: string | Buffer, opts: CreateWriteStreamOptions): WriteStream;
45
+ export {};
package/package.json CHANGED
@@ -1,42 +1,30 @@
1
1
  {
2
2
  "name": "@gjsify/fs",
3
- "version": "0.0.4",
3
+ "version": "0.1.0",
4
4
  "description": "Node.js fs module for Gjs",
5
- "main": "lib/cjs/index.js",
6
5
  "module": "lib/esm/index.js",
6
+ "types": "lib/types/index.d.ts",
7
7
  "type": "module",
8
8
  "exports": {
9
9
  ".": {
10
- "import": {
11
- "types": "./lib/types/index.d.ts",
12
- "default": "./lib/esm/index.js"
13
- },
14
- "require": {
15
- "types": "./lib/types/index.d.ts",
16
- "default": "./lib/cjs/index.js"
17
- }
10
+ "types": "./lib/types/index.d.ts",
11
+ "default": "./lib/esm/index.js"
18
12
  },
19
13
  "./promises": {
20
- "import": {
21
- "types": "./lib/types/promises.d.ts",
22
- "default": "./lib/esm/promises.js"
23
- },
24
- "require": {
25
- "types": "./lib/types/promises.d.ts",
26
- "default": "./lib/cjs/promises.js"
27
- }
14
+ "types": "./lib/types/promises.d.ts",
15
+ "default": "./lib/esm/promises.js"
28
16
  }
29
17
  },
30
18
  "scripts": {
31
- "clear": "rm -rf lib tsconfig.tsbuildinfo tsconfig.types.tsbuildinfo || exit 0",
32
- "print:name": "echo '@gjsify/fs'",
33
- "build": "yarn print:name && yarn build:gjsify",
19
+ "clear": "rm -rf lib tsconfig.tsbuildinfo tsconfig.types.tsbuildinfo test.gjs.mjs test.node.mjs || exit 0",
20
+ "check": "tsc --noEmit",
21
+ "build": "yarn build:gjsify && yarn build:types",
34
22
  "build:gjsify": "gjsify build --library 'src/**/*.{ts,js}' --exclude 'src/**/*.spec.{mts,ts}' 'src/test.{mts,ts}'",
35
- "build:types": "tsc --project tsconfig.types.json || exit 0",
23
+ "build:types": "tsc",
36
24
  "build:test": "yarn build:test:gjs && yarn build:test:node",
37
25
  "build:test:gjs": "gjsify build src/test.mts --app gjs --outfile test.gjs.mjs",
38
26
  "build:test:node": "gjsify build src/test.mts --app node --outfile test.node.mjs",
39
- "test": "yarn print:name && yarn build:gjsify && yarn build:test && yarn test:node && yarn test:gjs",
27
+ "test": "yarn build:gjsify && yarn build:test && yarn test:node && yarn test:gjs",
40
28
  "test:gjs": "gjs -m test.gjs.mjs",
41
29
  "test:node": "node test.node.mjs"
42
30
  },
@@ -46,19 +34,18 @@
46
34
  "fs"
47
35
  ],
48
36
  "devDependencies": {
49
- "@gjsify/cli": "^0.0.4",
50
- "@gjsify/unit": "^0.0.4",
51
- "@types/node": "^20.10.5",
52
- "typescript": "^5.3.3"
37
+ "@gjsify/cli": "^0.1.0",
38
+ "@gjsify/unit": "^0.1.0",
39
+ "@types/node": "^25.5.0",
40
+ "typescript": "^6.0.2"
53
41
  },
54
42
  "dependencies": {
55
- "@girs/glib-2.0": "2.78.0-3.2.6",
56
- "@gjsify/buffer": "^0.0.4",
57
- "@gjsify/deno_std": "^0.0.4",
58
- "@gjsify/events": "^0.0.4",
59
- "@gjsify/gio-2.0": "^0.0.4",
60
- "@gjsify/stream": "^0.0.4",
61
- "@gjsify/url": "^0.0.4",
62
- "@gjsify/utils": "^0.0.4"
43
+ "@girs/gio-2.0": "^2.88.0-4.0.0-beta.42",
44
+ "@girs/glib-2.0": "^2.88.0-4.0.0-beta.42",
45
+ "@gjsify/buffer": "^0.1.0",
46
+ "@gjsify/events": "^0.1.0",
47
+ "@gjsify/stream": "^0.1.0",
48
+ "@gjsify/url": "^0.1.0",
49
+ "@gjsify/utils": "^0.1.0"
63
50
  }
64
51
  }