@zenfs/core 0.0.12 → 0.2.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.
- package/dist/ApiError.d.ts +52 -15
- package/dist/ApiError.js +77 -50
- package/dist/FileIndex.d.ts +32 -35
- package/dist/FileIndex.js +93 -109
- package/dist/backends/AsyncMirror.d.ts +42 -43
- package/dist/backends/AsyncMirror.js +154 -147
- package/dist/backends/AsyncStore.d.ts +29 -28
- package/dist/backends/AsyncStore.js +375 -482
- package/dist/backends/FolderAdapter.js +8 -19
- package/dist/backends/InMemory.d.ts +16 -13
- package/dist/backends/InMemory.js +29 -14
- package/dist/backends/Locked.d.ts +8 -28
- package/dist/backends/Locked.js +74 -224
- package/dist/backends/OverlayFS.d.ts +26 -34
- package/dist/backends/OverlayFS.js +303 -511
- package/dist/backends/SyncStore.d.ts +54 -72
- package/dist/backends/SyncStore.js +159 -161
- package/dist/backends/backend.d.ts +45 -29
- package/dist/backends/backend.js +83 -13
- package/dist/backends/index.d.ts +6 -7
- package/dist/backends/index.js +5 -6
- package/dist/browser.min.js +21 -6
- package/dist/browser.min.js.map +4 -4
- package/dist/emulation/callbacks.d.ts +119 -113
- package/dist/emulation/callbacks.js +129 -92
- package/dist/emulation/constants.js +1 -1
- package/dist/emulation/dir.d.ts +55 -0
- package/dist/emulation/dir.js +104 -0
- package/dist/emulation/fs.d.ts +1 -2
- package/dist/emulation/fs.js +0 -1
- package/dist/emulation/index.d.ts +3 -0
- package/dist/emulation/index.js +3 -0
- package/dist/emulation/promises.d.ts +265 -145
- package/dist/emulation/promises.js +526 -383
- package/dist/emulation/shared.d.ts +20 -6
- package/dist/emulation/shared.js +22 -23
- package/dist/emulation/streams.d.ts +102 -0
- package/dist/emulation/streams.js +55 -0
- package/dist/emulation/sync.d.ts +98 -69
- package/dist/emulation/sync.js +280 -133
- package/dist/file.d.ts +175 -173
- package/dist/file.js +257 -273
- package/dist/filesystem.d.ts +71 -244
- package/dist/filesystem.js +67 -472
- package/dist/index.d.ts +7 -44
- package/dist/index.js +22 -75
- package/dist/inode.d.ts +37 -28
- package/dist/inode.js +123 -65
- package/dist/stats.d.ts +91 -36
- package/dist/stats.js +138 -110
- package/dist/utils.d.ts +26 -13
- package/dist/utils.js +79 -107
- package/package.json +7 -4
- package/readme.md +2 -40
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
import { Cred } from '../cred.js';
|
|
3
3
|
import { FileSystem } from '../filesystem.js';
|
|
4
|
-
import { File } from '../file.js';
|
|
5
|
-
import { BackendConstructor } from '../backends/backend.js';
|
|
4
|
+
import type { File } from '../file.js';
|
|
6
5
|
/**
|
|
7
|
-
* converts Date or number to a
|
|
6
|
+
* converts Date or number to a integer UNIX timestamp
|
|
8
7
|
* Grabbed from NodeJS sources (lib/fs.js)
|
|
9
8
|
*/
|
|
10
9
|
export declare function _toUnixTimestamp(time: Date | number): number;
|
|
11
|
-
export declare function normalizeMode(mode: unknown, def
|
|
12
|
-
export declare function normalizeTime(time: number | Date): Date;
|
|
10
|
+
export declare function normalizeMode(mode: string | number | unknown, def?: number): number;
|
|
11
|
+
export declare function normalizeTime(time: string | number | Date): Date;
|
|
13
12
|
export declare function normalizePath(p: string): string;
|
|
14
13
|
export declare function normalizeOptions(options: any, defEnc: string | null, defFlag: string, defMode: number | null): {
|
|
15
14
|
encoding: BufferEncoding;
|
|
@@ -23,7 +22,7 @@ export declare const fdMap: Map<number, File>;
|
|
|
23
22
|
export declare function getFdForFile(file: File): number;
|
|
24
23
|
export declare function fd2file(fd: number): File;
|
|
25
24
|
export interface MountMapping {
|
|
26
|
-
[point: string]:
|
|
25
|
+
[point: string]: FileSystem;
|
|
27
26
|
}
|
|
28
27
|
export declare const mounts: Map<string, FileSystem>;
|
|
29
28
|
/**
|
|
@@ -60,3 +59,18 @@ export declare function fixError<E extends Error>(e: E, paths: {
|
|
|
60
59
|
[from: string]: string;
|
|
61
60
|
}): E;
|
|
62
61
|
export declare function initialize(mountMapping: MountMapping): void;
|
|
62
|
+
/**
|
|
63
|
+
* Types supports as path parameters.
|
|
64
|
+
*
|
|
65
|
+
* In the future, maybe support URL?
|
|
66
|
+
*/
|
|
67
|
+
export type PathLike = string;
|
|
68
|
+
/**
|
|
69
|
+
* @internal
|
|
70
|
+
*
|
|
71
|
+
* Recursivly converts `From` in `Target` to `To`
|
|
72
|
+
*/
|
|
73
|
+
export type Convert<Target, From, To> = Target extends From ? To : Target extends (...args: any[]) => unknown ? (...args: Convert<Parameters<Target>, From, To> & Array<unknown>) => Convert<ReturnType<Target>, From, To> : Target extends object ? {
|
|
74
|
+
[K in keyof Target]: Convert<Target[K], From, To>;
|
|
75
|
+
} : Target;
|
|
76
|
+
export type BufferToUint8Array<T> = Convert<T, Buffer, Uint8Array>;
|
package/dist/emulation/shared.js
CHANGED
|
@@ -2,18 +2,17 @@
|
|
|
2
2
|
import { resolve } from './path.js';
|
|
3
3
|
import { ApiError, ErrorCode } from '../ApiError.js';
|
|
4
4
|
import { Cred } from '../cred.js';
|
|
5
|
-
|
|
6
|
-
import { InMemoryFileSystem } from '../backends/InMemory.js';
|
|
5
|
+
import { InMemory } from '../backends/InMemory.js';
|
|
7
6
|
/**
|
|
8
|
-
* converts Date or number to a
|
|
7
|
+
* converts Date or number to a integer UNIX timestamp
|
|
9
8
|
* Grabbed from NodeJS sources (lib/fs.js)
|
|
10
9
|
*/
|
|
11
10
|
export function _toUnixTimestamp(time) {
|
|
12
11
|
if (typeof time === 'number') {
|
|
13
|
-
return time;
|
|
12
|
+
return Math.floor(time);
|
|
14
13
|
}
|
|
15
|
-
|
|
16
|
-
return time.getTime() / 1000;
|
|
14
|
+
if (time instanceof Date) {
|
|
15
|
+
return Math.floor(time.getTime() / 1000);
|
|
17
16
|
}
|
|
18
17
|
throw new Error('Cannot parse time: ' + time);
|
|
19
18
|
}
|
|
@@ -28,20 +27,23 @@ export function normalizeMode(mode, def) {
|
|
|
28
27
|
if (!isNaN(trueMode)) {
|
|
29
28
|
return trueMode;
|
|
30
29
|
}
|
|
31
|
-
// Invalid string.
|
|
32
|
-
return def;
|
|
33
|
-
default:
|
|
34
|
-
return def;
|
|
35
30
|
}
|
|
31
|
+
if (typeof def == 'number') {
|
|
32
|
+
return def;
|
|
33
|
+
}
|
|
34
|
+
throw new ApiError(ErrorCode.EINVAL, 'Invalid mode: ' + mode?.toString());
|
|
36
35
|
}
|
|
37
36
|
export function normalizeTime(time) {
|
|
38
37
|
if (time instanceof Date) {
|
|
39
38
|
return time;
|
|
40
39
|
}
|
|
41
|
-
if (typeof time
|
|
40
|
+
if (typeof time == 'number') {
|
|
42
41
|
return new Date(time * 1000);
|
|
43
42
|
}
|
|
44
|
-
|
|
43
|
+
if (typeof time == 'string') {
|
|
44
|
+
return new Date(time);
|
|
45
|
+
}
|
|
46
|
+
throw new ApiError(ErrorCode.EINVAL, 'Invalid time.');
|
|
45
47
|
}
|
|
46
48
|
export function normalizePath(p) {
|
|
47
49
|
// Node doesn't allow null characters in paths.
|
|
@@ -99,17 +101,15 @@ export function getFdForFile(file) {
|
|
|
99
101
|
}
|
|
100
102
|
export function fd2file(fd) {
|
|
101
103
|
if (!fdMap.has(fd)) {
|
|
102
|
-
throw new ApiError(ErrorCode.EBADF
|
|
104
|
+
throw new ApiError(ErrorCode.EBADF);
|
|
103
105
|
}
|
|
104
106
|
return fdMap.get(fd);
|
|
105
107
|
}
|
|
106
108
|
export const mounts = new Map();
|
|
107
109
|
/*
|
|
108
110
|
Set a default root.
|
|
109
|
-
There is a very small but not 0 change that initialize() will try to unmount the default before it is mounted.
|
|
110
|
-
This can be fixed by using a top-level await, which is not done to maintain ES6 compatibility.
|
|
111
111
|
*/
|
|
112
|
-
|
|
112
|
+
mount('/', InMemory.create({ name: 'root' }));
|
|
113
113
|
/**
|
|
114
114
|
* Gets the file system mounted at `mountPoint`
|
|
115
115
|
*/
|
|
@@ -152,6 +152,7 @@ export function umount(mountPoint) {
|
|
|
152
152
|
* Gets the internal FileSystem for the path, then returns it along with the path relative to the FS' root
|
|
153
153
|
*/
|
|
154
154
|
export function resolveFS(path) {
|
|
155
|
+
path = normalizePath(path);
|
|
155
156
|
const sortedMounts = [...mounts].sort((a, b) => (a[0].length > b[0].length ? -1 : 1)); // decending order of the string length
|
|
156
157
|
for (const [mountPoint, fs] of sortedMounts) {
|
|
157
158
|
// We know path is normalized, so it would be a substring of the mount point.
|
|
@@ -170,24 +171,22 @@ export function resolveFS(path) {
|
|
|
170
171
|
*/
|
|
171
172
|
export function fixPaths(text, paths) {
|
|
172
173
|
for (const [from, to] of Object.entries(paths)) {
|
|
173
|
-
text = text
|
|
174
|
+
text = text?.replaceAll(from, to);
|
|
174
175
|
}
|
|
175
176
|
return text;
|
|
176
177
|
}
|
|
177
178
|
export function fixError(e, paths) {
|
|
178
|
-
|
|
179
|
+
if (typeof e.stack == 'string') {
|
|
180
|
+
e.stack = fixPaths(e.stack, paths);
|
|
181
|
+
}
|
|
179
182
|
e.message = fixPaths(e.message, paths);
|
|
180
183
|
return e;
|
|
181
184
|
}
|
|
182
185
|
export function initialize(mountMapping) {
|
|
183
|
-
if (
|
|
186
|
+
if ('/' in mountMapping) {
|
|
184
187
|
umount('/');
|
|
185
188
|
}
|
|
186
189
|
for (const [point, fs] of Object.entries(mountMapping)) {
|
|
187
|
-
const FS = fs.constructor;
|
|
188
|
-
if (!FS.isAvailable()) {
|
|
189
|
-
throw new ApiError(ErrorCode.EINVAL, `Can not mount "${point}" since the filesystem is unavailable.`);
|
|
190
|
-
}
|
|
191
190
|
mount(point, fs);
|
|
192
191
|
}
|
|
193
192
|
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
+
import type * as Node from 'fs';
|
|
4
|
+
import { Readable, Writable } from 'readable-stream';
|
|
5
|
+
import { NoArgCallback } from '../filesystem.js';
|
|
6
|
+
export declare class ReadStream extends Readable implements Node.ReadStream {
|
|
7
|
+
close(callback?: NoArgCallback): void;
|
|
8
|
+
bytesRead: number;
|
|
9
|
+
path: string | Buffer;
|
|
10
|
+
pending: boolean;
|
|
11
|
+
addListener(event: 'close', listener: () => void): this;
|
|
12
|
+
addListener(event: 'data', listener: (chunk: Buffer | string) => void): this;
|
|
13
|
+
addListener(event: 'end', listener: () => void): this;
|
|
14
|
+
addListener(event: 'error', listener: (err: Error) => void): this;
|
|
15
|
+
addListener(event: 'open', listener: (fd: number) => void): this;
|
|
16
|
+
addListener(event: 'pause', listener: () => void): this;
|
|
17
|
+
addListener(event: 'readable', listener: () => void): this;
|
|
18
|
+
addListener(event: 'ready', listener: () => void): this;
|
|
19
|
+
addListener(event: 'resume', listener: () => void): this;
|
|
20
|
+
on(event: 'close', listener: () => void): this;
|
|
21
|
+
on(event: 'data', listener: (chunk: Buffer | string) => void): this;
|
|
22
|
+
on(event: 'end', listener: () => void): this;
|
|
23
|
+
on(event: 'error', listener: (err: Error) => void): this;
|
|
24
|
+
on(event: 'open', listener: (fd: number) => void): this;
|
|
25
|
+
on(event: 'pause', listener: () => void): this;
|
|
26
|
+
on(event: 'readable', listener: () => void): this;
|
|
27
|
+
on(event: 'ready', listener: () => void): this;
|
|
28
|
+
on(event: 'resume', listener: () => void): this;
|
|
29
|
+
once(event: 'close', listener: () => void): this;
|
|
30
|
+
once(event: 'data', listener: (chunk: Buffer | string) => void): this;
|
|
31
|
+
once(event: 'end', listener: () => void): this;
|
|
32
|
+
once(event: 'error', listener: (err: Error) => void): this;
|
|
33
|
+
once(event: 'open', listener: (fd: number) => void): this;
|
|
34
|
+
once(event: 'pause', listener: () => void): this;
|
|
35
|
+
once(event: 'readable', listener: () => void): this;
|
|
36
|
+
once(event: 'ready', listener: () => void): this;
|
|
37
|
+
once(event: 'resume', listener: () => void): this;
|
|
38
|
+
prependListener(event: 'close', listener: () => void): this;
|
|
39
|
+
prependListener(event: 'data', listener: (chunk: Buffer | string) => void): this;
|
|
40
|
+
prependListener(event: 'end', listener: () => void): this;
|
|
41
|
+
prependListener(event: 'error', listener: (err: Error) => void): this;
|
|
42
|
+
prependListener(event: 'open', listener: (fd: number) => void): this;
|
|
43
|
+
prependListener(event: 'pause', listener: () => void): this;
|
|
44
|
+
prependListener(event: 'readable', listener: () => void): this;
|
|
45
|
+
prependListener(event: 'ready', listener: () => void): this;
|
|
46
|
+
prependListener(event: 'resume', listener: () => void): this;
|
|
47
|
+
prependOnceListener(event: 'close', listener: () => void): this;
|
|
48
|
+
prependOnceListener(event: 'data', listener: (chunk: Buffer | string) => void): this;
|
|
49
|
+
prependOnceListener(event: 'end', listener: () => void): this;
|
|
50
|
+
prependOnceListener(event: 'error', listener: (err: Error) => void): this;
|
|
51
|
+
prependOnceListener(event: 'open', listener: (fd: number) => void): this;
|
|
52
|
+
prependOnceListener(event: 'pause', listener: () => void): this;
|
|
53
|
+
prependOnceListener(event: 'readable', listener: () => void): this;
|
|
54
|
+
prependOnceListener(event: 'ready', listener: () => void): this;
|
|
55
|
+
prependOnceListener(event: 'resume', listener: () => void): this;
|
|
56
|
+
}
|
|
57
|
+
export declare class WriteStream extends Writable implements Node.WriteStream {
|
|
58
|
+
close(callback?: NoArgCallback): void;
|
|
59
|
+
bytesWritten: number;
|
|
60
|
+
path: string | Buffer;
|
|
61
|
+
pending: boolean;
|
|
62
|
+
addListener(event: 'close', listener: () => void): this;
|
|
63
|
+
addListener(event: 'drain', listener: () => void): this;
|
|
64
|
+
addListener(event: 'error', listener: (err: Error) => void): this;
|
|
65
|
+
addListener(event: 'finish', listener: () => void): this;
|
|
66
|
+
addListener(event: 'open', listener: (fd: number) => void): this;
|
|
67
|
+
addListener(event: 'pipe', listener: (src: Readable) => void): this;
|
|
68
|
+
addListener(event: 'ready', listener: () => void): this;
|
|
69
|
+
addListener(event: 'unpipe', listener: (src: Readable) => void): this;
|
|
70
|
+
on(event: 'close', listener: () => void): this;
|
|
71
|
+
on(event: 'drain', listener: () => void): this;
|
|
72
|
+
on(event: 'error', listener: (err: Error) => void): this;
|
|
73
|
+
on(event: 'finish', listener: () => void): this;
|
|
74
|
+
on(event: 'open', listener: (fd: number) => void): this;
|
|
75
|
+
on(event: 'pipe', listener: (src: Readable) => void): this;
|
|
76
|
+
on(event: 'ready', listener: () => void): this;
|
|
77
|
+
on(event: 'unpipe', listener: (src: Readable) => void): this;
|
|
78
|
+
once(event: 'close', listener: () => void): this;
|
|
79
|
+
once(event: 'drain', listener: () => void): this;
|
|
80
|
+
once(event: 'error', listener: (err: Error) => void): this;
|
|
81
|
+
once(event: 'finish', listener: () => void): this;
|
|
82
|
+
once(event: 'open', listener: (fd: number) => void): this;
|
|
83
|
+
once(event: 'pipe', listener: (src: Readable) => void): this;
|
|
84
|
+
once(event: 'ready', listener: () => void): this;
|
|
85
|
+
once(event: 'unpipe', listener: (src: Readable) => void): this;
|
|
86
|
+
prependListener(event: 'close', listener: () => void): this;
|
|
87
|
+
prependListener(event: 'drain', listener: () => void): this;
|
|
88
|
+
prependListener(event: 'error', listener: (err: Error) => void): this;
|
|
89
|
+
prependListener(event: 'finish', listener: () => void): this;
|
|
90
|
+
prependListener(event: 'open', listener: (fd: number) => void): this;
|
|
91
|
+
prependListener(event: 'pipe', listener: (src: Readable) => void): this;
|
|
92
|
+
prependListener(event: 'ready', listener: () => void): this;
|
|
93
|
+
prependListener(event: 'unpipe', listener: (src: Readable) => void): this;
|
|
94
|
+
prependOnceListener(event: 'close', listener: () => void): this;
|
|
95
|
+
prependOnceListener(event: 'drain', listener: () => void): this;
|
|
96
|
+
prependOnceListener(event: 'error', listener: (err: Error) => void): this;
|
|
97
|
+
prependOnceListener(event: 'finish', listener: () => void): this;
|
|
98
|
+
prependOnceListener(event: 'open', listener: (fd: number) => void): this;
|
|
99
|
+
prependOnceListener(event: 'pipe', listener: (src: Readable) => void): this;
|
|
100
|
+
prependOnceListener(event: 'ready', listener: () => void): this;
|
|
101
|
+
prependOnceListener(event: 'unpipe', listener: (src: Readable) => void): this;
|
|
102
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Readable, Writable } from 'readable-stream';
|
|
2
|
+
export class ReadStream extends Readable {
|
|
3
|
+
close(callback = () => null) {
|
|
4
|
+
try {
|
|
5
|
+
super.destroy();
|
|
6
|
+
super.emit('close');
|
|
7
|
+
callback();
|
|
8
|
+
}
|
|
9
|
+
catch (err) {
|
|
10
|
+
callback(err);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
addListener(event, listener) {
|
|
14
|
+
return super.addListener(event, listener);
|
|
15
|
+
}
|
|
16
|
+
on(event, listener) {
|
|
17
|
+
return super.on(event, listener);
|
|
18
|
+
}
|
|
19
|
+
once(event, listener) {
|
|
20
|
+
return super.once(event, listener);
|
|
21
|
+
}
|
|
22
|
+
prependListener(event, listener) {
|
|
23
|
+
return super.prependListener(event, listener);
|
|
24
|
+
}
|
|
25
|
+
prependOnceListener(event, listener) {
|
|
26
|
+
return super.prependOnceListener(event, listener);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export class WriteStream extends Writable {
|
|
30
|
+
close(callback = () => null) {
|
|
31
|
+
try {
|
|
32
|
+
super.destroy();
|
|
33
|
+
super.emit('close');
|
|
34
|
+
callback();
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
callback(err);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
addListener(event, listener) {
|
|
41
|
+
return super.addListener(event, listener);
|
|
42
|
+
}
|
|
43
|
+
on(event, listener) {
|
|
44
|
+
return super.on(event, listener);
|
|
45
|
+
}
|
|
46
|
+
once(event, listener) {
|
|
47
|
+
return super.once(event, listener);
|
|
48
|
+
}
|
|
49
|
+
prependListener(event, listener) {
|
|
50
|
+
return super.prependListener(event, listener);
|
|
51
|
+
}
|
|
52
|
+
prependOnceListener(event, listener) {
|
|
53
|
+
return super.prependOnceListener(event, listener);
|
|
54
|
+
}
|
|
55
|
+
}
|
package/dist/emulation/sync.d.ts
CHANGED
|
@@ -1,60 +1,77 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
/// <reference types="node" resolution-mode="require"/>
|
|
3
3
|
import { FileContents } from '../filesystem.js';
|
|
4
|
-
import { Stats } from '../stats.js';
|
|
5
|
-
import type { symlink, ReadSyncOptions } from 'fs';
|
|
4
|
+
import { BigIntStats, Stats } from '../stats.js';
|
|
5
|
+
import type { symlink, ReadSyncOptions, BaseEncodingOptions, BufferEncodingOption } from 'fs';
|
|
6
|
+
import type * as Node from 'fs';
|
|
7
|
+
import { PathLike } from './shared.js';
|
|
8
|
+
import { Dir, Dirent } from './dir.js';
|
|
6
9
|
/**
|
|
7
10
|
* Synchronous rename.
|
|
8
11
|
* @param oldPath
|
|
9
12
|
* @param newPath
|
|
10
13
|
*/
|
|
11
|
-
export declare function renameSync(oldPath:
|
|
14
|
+
export declare function renameSync(oldPath: PathLike, newPath: PathLike): void;
|
|
12
15
|
/**
|
|
13
16
|
* Test whether or not the given path exists by checking with the file system.
|
|
14
17
|
* @param path
|
|
15
18
|
*/
|
|
16
|
-
export declare function existsSync(path:
|
|
19
|
+
export declare function existsSync(path: PathLike): boolean;
|
|
17
20
|
/**
|
|
18
21
|
* Synchronous `stat`.
|
|
19
22
|
* @param path
|
|
20
23
|
* @returns Stats
|
|
21
24
|
*/
|
|
22
|
-
export declare function statSync(path:
|
|
25
|
+
export declare function statSync(path: PathLike, options?: {
|
|
26
|
+
bigint: false;
|
|
27
|
+
}): Stats;
|
|
28
|
+
export declare function statSync(path: PathLike, options: {
|
|
29
|
+
bigint: true;
|
|
30
|
+
}): BigIntStats;
|
|
23
31
|
/**
|
|
24
32
|
* Synchronous `lstat`.
|
|
25
33
|
* `lstat()` is identical to `stat()`, except that if path is a symbolic link,
|
|
26
34
|
* then the link itself is stat-ed, not the file that it refers to.
|
|
27
35
|
* @param path
|
|
28
|
-
* @return [ZenFS.node.fs.Stats]
|
|
29
36
|
*/
|
|
30
|
-
export declare function lstatSync(path:
|
|
37
|
+
export declare function lstatSync(path: PathLike, options?: {
|
|
38
|
+
bigint: false;
|
|
39
|
+
}): Stats;
|
|
40
|
+
export declare function lstatSync(path: PathLike, options: {
|
|
41
|
+
bigint: true;
|
|
42
|
+
}): BigIntStats;
|
|
31
43
|
/**
|
|
32
44
|
* Synchronous `truncate`.
|
|
33
45
|
* @param path
|
|
34
46
|
* @param len
|
|
35
47
|
*/
|
|
36
|
-
export declare function truncateSync(path:
|
|
48
|
+
export declare function truncateSync(path: PathLike, len?: number): void;
|
|
37
49
|
/**
|
|
38
50
|
* Synchronous `unlink`.
|
|
39
51
|
* @param path
|
|
40
52
|
*/
|
|
41
|
-
export declare function unlinkSync(path:
|
|
53
|
+
export declare function unlinkSync(path: PathLike): void;
|
|
42
54
|
/**
|
|
43
55
|
* Synchronous file open.
|
|
44
56
|
* @see http://www.manpagez.com/man/2/open/
|
|
45
|
-
* @param
|
|
46
|
-
*
|
|
47
|
-
* @param mode
|
|
48
|
-
*
|
|
57
|
+
* @param flags Handles the complexity of the various file
|
|
58
|
+
* modes. See its API for more details.
|
|
59
|
+
* @param mode Mode to use to open the file. Can be ignored if the
|
|
60
|
+
* filesystem doesn't support permissions.
|
|
61
|
+
*/
|
|
62
|
+
export declare function openSync(path: PathLike, flag: string, mode?: Node.Mode): number;
|
|
63
|
+
/**
|
|
64
|
+
* Opens a file or symlink
|
|
65
|
+
* @internal
|
|
49
66
|
*/
|
|
50
|
-
export declare function
|
|
67
|
+
export declare function lopenSync(path: PathLike, flag: string, mode?: Node.Mode): number;
|
|
51
68
|
/**
|
|
52
69
|
* Synchronously reads the entire contents of a file.
|
|
53
70
|
* @param filename
|
|
54
71
|
* @param options
|
|
55
|
-
* @option options
|
|
56
|
-
* @option options
|
|
57
|
-
* @
|
|
72
|
+
* @option options encoding The string encoding for the file contents. Defaults to `null`.
|
|
73
|
+
* @option options flag Defaults to `'r'`.
|
|
74
|
+
* @returns file contents
|
|
58
75
|
*/
|
|
59
76
|
export declare function readFileSync(filename: string, options?: {
|
|
60
77
|
flag?: string;
|
|
@@ -72,46 +89,37 @@ export declare function readFileSync(filename: string, encoding: string): string
|
|
|
72
89
|
* @param filename
|
|
73
90
|
* @param data
|
|
74
91
|
* @param options
|
|
75
|
-
* @option options
|
|
76
|
-
* @option options
|
|
77
|
-
* @option options
|
|
92
|
+
* @option options encoding Defaults to `'utf8'`.
|
|
93
|
+
* @option options mode Defaults to `0644`.
|
|
94
|
+
* @option options flag Defaults to `'w'`.
|
|
78
95
|
*/
|
|
79
|
-
export declare function writeFileSync(filename: string, data: FileContents, options?:
|
|
80
|
-
|
|
81
|
-
mode?: number | string;
|
|
82
|
-
flag?: string;
|
|
83
|
-
}): void;
|
|
84
|
-
export declare function writeFileSync(filename: string, data: FileContents, encoding?: string): void;
|
|
96
|
+
export declare function writeFileSync(filename: string, data: FileContents, options?: Node.WriteFileOptions): void;
|
|
97
|
+
export declare function writeFileSync(filename: string, data: FileContents, encoding?: BufferEncoding): void;
|
|
85
98
|
/**
|
|
86
99
|
* Asynchronously append data to a file, creating the file if it not yet
|
|
87
100
|
* exists.
|
|
88
101
|
*
|
|
89
|
-
* @example Usage example
|
|
90
|
-
* fs.appendFile('message.txt', 'data to append', function (err) {
|
|
91
|
-
* if (err) throw err;
|
|
92
|
-
* console.log('The "data to append" was appended to file!');
|
|
93
|
-
* });
|
|
94
102
|
* @param filename
|
|
95
103
|
* @param data
|
|
96
104
|
* @param options
|
|
97
|
-
* @option options
|
|
98
|
-
* @option options
|
|
99
|
-
* @option options
|
|
105
|
+
* @option options encoding Defaults to `'utf8'`.
|
|
106
|
+
* @option options mode Defaults to `0644`.
|
|
107
|
+
* @option options flag Defaults to `'a'`.
|
|
100
108
|
*/
|
|
101
|
-
export declare function appendFileSync(filename: string, data: FileContents, options?:
|
|
102
|
-
encoding?: string;
|
|
103
|
-
mode?: number | string;
|
|
104
|
-
flag?: string;
|
|
105
|
-
}): void;
|
|
109
|
+
export declare function appendFileSync(filename: string, data: FileContents, options?: Node.WriteFileOptions): void;
|
|
106
110
|
export declare function appendFileSync(filename: string, data: FileContents, encoding?: string): void;
|
|
107
111
|
/**
|
|
108
112
|
* Synchronous `fstat`.
|
|
109
113
|
* `fstat()` is identical to `stat()`, except that the file to be stat-ed is
|
|
110
114
|
* specified by the file descriptor `fd`.
|
|
111
115
|
* @param fd
|
|
112
|
-
* @return [ZenFS.node.fs.Stats]
|
|
113
116
|
*/
|
|
114
|
-
export declare function fstatSync(fd: number
|
|
117
|
+
export declare function fstatSync(fd: number, options?: {
|
|
118
|
+
bigint?: false;
|
|
119
|
+
}): Stats;
|
|
120
|
+
export declare function fstatSync(fd: number, options: {
|
|
121
|
+
bigint: true;
|
|
122
|
+
}): BigIntStats;
|
|
115
123
|
/**
|
|
116
124
|
* Synchronous close.
|
|
117
125
|
* @param fd
|
|
@@ -138,7 +146,7 @@ export declare function fdatasyncSync(fd: number): void;
|
|
|
138
146
|
* Note that it is unsafe to use fs.write multiple times on the same file
|
|
139
147
|
* without waiting for it to return.
|
|
140
148
|
* @param fd
|
|
141
|
-
* @param
|
|
149
|
+
* @param data Uint8Array containing the data to write to
|
|
142
150
|
* the file.
|
|
143
151
|
* @param offset Offset in the buffer to start reading data from.
|
|
144
152
|
* @param length The amount of bytes to write to the file.
|
|
@@ -146,8 +154,8 @@ export declare function fdatasyncSync(fd: number): void;
|
|
|
146
154
|
* data should be written. If position is null, the data will be written at
|
|
147
155
|
* the current position.
|
|
148
156
|
*/
|
|
149
|
-
export declare function writeSync(fd: number,
|
|
150
|
-
export declare function writeSync(fd: number, data: string, position?: number
|
|
157
|
+
export declare function writeSync(fd: number, data: Uint8Array, offset: number, length: number, position?: number): number;
|
|
158
|
+
export declare function writeSync(fd: number, data: string, position?: number, encoding?: BufferEncoding): number;
|
|
151
159
|
/**
|
|
152
160
|
* Read data from the file specified by `fd`.
|
|
153
161
|
* @param fd
|
|
@@ -182,97 +190,118 @@ export declare function fchmodSync(fd: number, mode: number | string): void;
|
|
|
182
190
|
* @param atime
|
|
183
191
|
* @param mtime
|
|
184
192
|
*/
|
|
185
|
-
export declare function futimesSync(fd: number, atime: number | Date, mtime: number | Date): void;
|
|
193
|
+
export declare function futimesSync(fd: number, atime: string | number | Date, mtime: string | number | Date): void;
|
|
186
194
|
/**
|
|
187
195
|
* Synchronous `rmdir`.
|
|
188
196
|
* @param path
|
|
189
197
|
*/
|
|
190
|
-
export declare function rmdirSync(path:
|
|
198
|
+
export declare function rmdirSync(path: PathLike): void;
|
|
191
199
|
/**
|
|
192
200
|
* Synchronous `mkdir`.
|
|
193
201
|
* @param path
|
|
194
|
-
* @param mode defaults to
|
|
202
|
+
* @param mode defaults to o777
|
|
203
|
+
* @todo Implement recursion
|
|
195
204
|
*/
|
|
196
|
-
export declare function mkdirSync(path:
|
|
205
|
+
export declare function mkdirSync(path: PathLike, options: Node.MakeDirectoryOptions & {
|
|
206
|
+
recursive: true;
|
|
207
|
+
}): string;
|
|
208
|
+
export declare function mkdirSync(path: PathLike, options?: Node.Mode | (Node.MakeDirectoryOptions & {
|
|
209
|
+
recursive?: false;
|
|
210
|
+
})): void;
|
|
197
211
|
/**
|
|
198
212
|
* Synchronous `readdir`. Reads the contents of a directory.
|
|
199
213
|
* @param path
|
|
200
|
-
* @return [String[]]
|
|
201
214
|
*/
|
|
202
|
-
export declare function readdirSync(path:
|
|
215
|
+
export declare function readdirSync(path: PathLike, options?: {
|
|
216
|
+
encoding?: BufferEncoding;
|
|
217
|
+
withFileTypes?: false;
|
|
218
|
+
} | BufferEncoding): string[];
|
|
219
|
+
export declare function readdirSync(path: PathLike, options: {
|
|
220
|
+
encoding: 'buffer';
|
|
221
|
+
withFileTypes?: false;
|
|
222
|
+
} | 'buffer'): Uint8Array[];
|
|
223
|
+
export declare function readdirSync(path: PathLike, options: {
|
|
224
|
+
withFileTypes: true;
|
|
225
|
+
}): Dirent[];
|
|
203
226
|
/**
|
|
204
227
|
* Synchronous `link`.
|
|
205
|
-
* @param
|
|
206
|
-
* @param
|
|
228
|
+
* @param existing
|
|
229
|
+
* @param newpath
|
|
207
230
|
*/
|
|
208
|
-
export declare function linkSync(
|
|
231
|
+
export declare function linkSync(existing: PathLike, newpath: PathLike): void;
|
|
209
232
|
/**
|
|
210
233
|
* Synchronous `symlink`.
|
|
211
|
-
* @param
|
|
212
|
-
* @param
|
|
234
|
+
* @param target target path
|
|
235
|
+
* @param path link path
|
|
213
236
|
* @param type can be either `'dir'` or `'file'` (default is `'file'`)
|
|
214
237
|
*/
|
|
215
|
-
export declare function symlinkSync(
|
|
238
|
+
export declare function symlinkSync(target: PathLike, path: PathLike, type?: symlink.Type): void;
|
|
216
239
|
/**
|
|
217
240
|
* Synchronous readlink.
|
|
218
241
|
* @param path
|
|
219
|
-
* @return [String]
|
|
220
242
|
*/
|
|
221
|
-
export declare function readlinkSync(path:
|
|
243
|
+
export declare function readlinkSync(path: PathLike, options?: BufferEncodingOption): Uint8Array;
|
|
244
|
+
export declare function readlinkSync(path: PathLike, options: BaseEncodingOptions | BufferEncoding): string;
|
|
222
245
|
/**
|
|
223
246
|
* Synchronous `chown`.
|
|
224
247
|
* @param path
|
|
225
248
|
* @param uid
|
|
226
249
|
* @param gid
|
|
227
250
|
*/
|
|
228
|
-
export declare function chownSync(path:
|
|
251
|
+
export declare function chownSync(path: PathLike, uid: number, gid: number): void;
|
|
229
252
|
/**
|
|
230
253
|
* Synchronous `lchown`.
|
|
231
254
|
* @param path
|
|
232
255
|
* @param uid
|
|
233
256
|
* @param gid
|
|
234
257
|
*/
|
|
235
|
-
export declare function lchownSync(path:
|
|
258
|
+
export declare function lchownSync(path: PathLike, uid: number, gid: number): void;
|
|
236
259
|
/**
|
|
237
260
|
* Synchronous `chmod`.
|
|
238
261
|
* @param path
|
|
239
262
|
* @param mode
|
|
240
263
|
*/
|
|
241
|
-
export declare function chmodSync(path:
|
|
264
|
+
export declare function chmodSync(path: PathLike, mode: Node.Mode): void;
|
|
242
265
|
/**
|
|
243
266
|
* Synchronous `lchmod`.
|
|
244
267
|
* @param path
|
|
245
268
|
* @param mode
|
|
246
269
|
*/
|
|
247
|
-
export declare function lchmodSync(path:
|
|
270
|
+
export declare function lchmodSync(path: PathLike, mode: number | string): void;
|
|
248
271
|
/**
|
|
249
272
|
* Change file timestamps of the file referenced by the supplied path.
|
|
250
273
|
* @param path
|
|
251
274
|
* @param atime
|
|
252
275
|
* @param mtime
|
|
253
276
|
*/
|
|
254
|
-
export declare function utimesSync(path:
|
|
277
|
+
export declare function utimesSync(path: PathLike, atime: string | number | Date, mtime: string | number | Date): void;
|
|
255
278
|
/**
|
|
256
279
|
* Change file timestamps of the file referenced by the supplied path.
|
|
257
280
|
* @param path
|
|
258
281
|
* @param atime
|
|
259
282
|
* @param mtime
|
|
260
283
|
*/
|
|
261
|
-
export declare function lutimesSync(path:
|
|
284
|
+
export declare function lutimesSync(path: PathLike, atime: string | number | Date, mtime: string | number | Date): void;
|
|
262
285
|
/**
|
|
263
286
|
* Synchronous `realpath`.
|
|
264
287
|
* @param path
|
|
265
288
|
* @param cache An object literal of mapped paths that can be used to
|
|
266
289
|
* force a specific path resolution or avoid additional `fs.stat` calls for
|
|
267
290
|
* known real paths.
|
|
268
|
-
* @
|
|
291
|
+
* @returns the real path
|
|
269
292
|
*/
|
|
270
|
-
export declare function realpathSync(path:
|
|
271
|
-
|
|
272
|
-
}): string;
|
|
293
|
+
export declare function realpathSync(path: PathLike, options: BufferEncodingOption): Uint8Array;
|
|
294
|
+
export declare function realpathSync(path: PathLike, options?: BaseEncodingOptions | BufferEncoding): string;
|
|
273
295
|
/**
|
|
274
296
|
* Synchronous `access`.
|
|
275
297
|
* @param path
|
|
276
298
|
* @param mode
|
|
277
299
|
*/
|
|
278
|
-
export declare function accessSync(path:
|
|
300
|
+
export declare function accessSync(path: PathLike, mode?: number): void;
|
|
301
|
+
export declare function rmSync(path: PathLike): void;
|
|
302
|
+
export declare function mkdtempSync(prefix: string, options: BufferEncodingOption): Uint8Array;
|
|
303
|
+
export declare function mkdtempSync(prefix: string, options?: BaseEncodingOptions | BufferEncoding): string;
|
|
304
|
+
export declare function copyFileSync(src: string, dest: string, flags?: number): void;
|
|
305
|
+
export declare function readvSync(fd: number, buffers: readonly Uint8Array[], position?: number): number;
|
|
306
|
+
export declare function writevSync(fd: number, buffers: readonly Uint8Array[], position?: number): number;
|
|
307
|
+
export declare function opendirSync(path: PathLike, options?: Node.OpenDirOptions): Dir;
|