@zenfs/core 1.11.4 → 2.0.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/backends/backend.d.ts +19 -15
- package/dist/backends/backend.js +31 -15
- package/dist/backends/cow.d.ts +20 -30
- package/dist/backends/cow.js +52 -142
- package/dist/backends/fetch.d.ts +1 -0
- package/dist/backends/fetch.js +3 -1
- package/dist/backends/index.d.ts +1 -1
- package/dist/backends/index.js +1 -1
- package/dist/backends/memory.d.ts +5 -7
- package/dist/backends/memory.js +2 -3
- package/dist/backends/passthrough.d.ts +19 -22
- package/dist/backends/passthrough.js +85 -160
- package/dist/backends/port.d.ts +207 -0
- package/dist/backends/port.js +297 -0
- package/dist/backends/single_buffer.d.ts +11 -5
- package/dist/backends/single_buffer.js +18 -12
- package/dist/backends/store/fs.d.ts +11 -27
- package/dist/backends/store/fs.js +67 -91
- package/dist/backends/store/store.d.ts +7 -12
- package/dist/config.d.ts +1 -10
- package/dist/config.js +7 -8
- package/dist/context.d.ts +8 -21
- package/dist/context.js +33 -10
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/internal/contexts.d.ts +63 -0
- package/dist/internal/contexts.js +15 -0
- package/dist/internal/credentials.d.ts +2 -11
- package/dist/internal/credentials.js +0 -19
- package/dist/internal/devices.d.ts +18 -80
- package/dist/internal/devices.js +76 -279
- package/dist/internal/file_index.js +3 -3
- package/dist/internal/filesystem.d.ts +31 -89
- package/dist/internal/filesystem.js +21 -20
- package/dist/internal/index.d.ts +0 -1
- package/dist/internal/index.js +0 -1
- package/dist/internal/index_fs.d.ts +12 -30
- package/dist/internal/index_fs.js +23 -55
- package/dist/internal/inode.d.ts +147 -9
- package/dist/internal/inode.js +333 -25
- package/dist/internal/log.d.ts +19 -13
- package/dist/internal/log.js +81 -80
- package/dist/mixins/async.js +26 -90
- package/dist/mixins/mutexed.d.ts +17 -16
- package/dist/mixins/mutexed.js +29 -31
- package/dist/mixins/readonly.d.ts +7 -6
- package/dist/mixins/readonly.js +6 -0
- package/dist/mixins/sync.js +8 -8
- package/dist/{vfs/path.d.ts → path.d.ts} +3 -4
- package/dist/{vfs/path.js → path.js} +6 -9
- package/dist/readline.d.ts +134 -0
- package/dist/readline.js +623 -0
- package/dist/utils.d.ts +4 -35
- package/dist/utils.js +8 -73
- package/dist/vfs/acl.d.ts +42 -0
- package/dist/vfs/acl.js +249 -0
- package/dist/vfs/async.d.ts +7 -21
- package/dist/vfs/async.js +19 -19
- package/dist/vfs/config.d.ts +6 -18
- package/dist/vfs/config.js +8 -18
- package/dist/vfs/dir.d.ts +3 -3
- package/dist/vfs/dir.js +9 -8
- package/dist/vfs/file.d.ts +106 -0
- package/dist/vfs/file.js +235 -0
- package/dist/vfs/flags.d.ts +19 -0
- package/dist/vfs/flags.js +62 -0
- package/dist/vfs/index.d.ts +4 -10
- package/dist/vfs/index.js +4 -13
- package/dist/vfs/ioctl.d.ts +87 -0
- package/dist/vfs/ioctl.js +304 -0
- package/dist/vfs/promises.d.ts +78 -16
- package/dist/vfs/promises.js +273 -122
- package/dist/vfs/shared.d.ts +7 -26
- package/dist/vfs/shared.js +25 -53
- package/dist/{stats.d.ts → vfs/stats.d.ts} +14 -28
- package/dist/{stats.js → vfs/stats.js} +11 -66
- package/dist/vfs/streams.d.ts +1 -0
- package/dist/vfs/streams.js +24 -19
- package/dist/vfs/sync.d.ts +4 -3
- package/dist/vfs/sync.js +143 -128
- package/dist/vfs/watchers.d.ts +2 -2
- package/dist/vfs/watchers.js +6 -6
- package/dist/vfs/xattr.d.ts +116 -0
- package/dist/vfs/xattr.js +218 -0
- package/package.json +3 -3
- package/readme.md +1 -1
- package/tests/backend/config.worker.js +4 -1
- package/tests/backend/fetch.test.ts +3 -0
- package/tests/backend/port.test.ts +21 -35
- package/tests/backend/remote.worker.js +4 -1
- package/tests/backend/single-buffer.test.ts +24 -0
- package/tests/common/context.test.ts +1 -1
- package/tests/common/handle.test.ts +17 -12
- package/tests/common/path.test.ts +1 -1
- package/tests/common/readline.test.ts +104 -0
- package/tests/common.ts +4 -19
- package/tests/fetch/fetch.ts +1 -1
- package/tests/fs/links.test.ts +1 -1
- package/tests/fs/permissions.test.ts +7 -6
- package/tests/fs/readFile.test.ts +3 -3
- package/tests/fs/stat.test.ts +6 -6
- package/tests/fs/streams.test.ts +2 -11
- package/tests/fs/times.test.ts +1 -1
- package/tests/fs/xattr.test.ts +85 -0
- package/tests/logs.js +22 -0
- package/tests/setup/context.ts +1 -1
- package/tests/setup/index.ts +3 -3
- package/tests/setup/port.ts +1 -1
- package/dist/backends/port/fs.d.ts +0 -84
- package/dist/backends/port/fs.js +0 -151
- package/dist/backends/port/rpc.d.ts +0 -77
- package/dist/backends/port/rpc.js +0 -100
- package/dist/backends/store/simple.d.ts +0 -20
- package/dist/backends/store/simple.js +0 -13
- package/dist/internal/file.d.ts +0 -359
- package/dist/internal/file.js +0 -751
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import type { TransferListItem } from 'node:worker_threads';
|
|
2
|
-
import type { WithOptional } from 'utilium';
|
|
3
|
-
import type { ErrnoErrorJSON } from '../../internal/error.js';
|
|
4
|
-
import type { Backend, FilesystemOf } from '../backend.js';
|
|
5
|
-
import type { PortFS } from './fs.js';
|
|
6
|
-
import { type StatsLike } from '../../stats.js';
|
|
7
|
-
type _MessageEvent<T = any> = T | {
|
|
8
|
-
data: T;
|
|
9
|
-
};
|
|
10
|
-
/** @internal */
|
|
11
|
-
export interface Port {
|
|
12
|
-
postMessage(value: unknown, transfer?: TransferListItem[]): void;
|
|
13
|
-
on?(event: 'message' | 'online', listener: (value: unknown) => void): this;
|
|
14
|
-
off?(event: 'message', listener: (value: unknown) => void): this;
|
|
15
|
-
addEventListener?(type: 'message', listener: (ev: _MessageEvent) => void): void;
|
|
16
|
-
removeEventListener?(type: 'message', listener: (ev: _MessageEvent) => void): void;
|
|
17
|
-
}
|
|
18
|
-
export interface Options {
|
|
19
|
-
/**
|
|
20
|
-
* The target port that you want to connect to, or the current port if in a port context.
|
|
21
|
-
*/
|
|
22
|
-
port: Port;
|
|
23
|
-
/**
|
|
24
|
-
* How long to wait for a request to complete
|
|
25
|
-
*/
|
|
26
|
-
timeout?: number;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* An RPC message
|
|
30
|
-
*/
|
|
31
|
-
export interface Message {
|
|
32
|
-
_zenfs: true;
|
|
33
|
-
id: string;
|
|
34
|
-
method: string;
|
|
35
|
-
stack: string;
|
|
36
|
-
}
|
|
37
|
-
export interface Request extends Message {
|
|
38
|
-
args: unknown[];
|
|
39
|
-
}
|
|
40
|
-
interface _ResponseWithError extends Message {
|
|
41
|
-
error: true;
|
|
42
|
-
value: WithOptional<ErrnoErrorJSON, 'code' | 'errno'>;
|
|
43
|
-
}
|
|
44
|
-
interface _ResponseWithValue<T> extends Message {
|
|
45
|
-
error: false;
|
|
46
|
-
value: Awaited<T> extends File ? FileData : Awaited<T>;
|
|
47
|
-
}
|
|
48
|
-
interface _ResponseRead extends Message {
|
|
49
|
-
error: false;
|
|
50
|
-
method: 'read';
|
|
51
|
-
value: Uint8Array;
|
|
52
|
-
}
|
|
53
|
-
export type Response<T = unknown> = _ResponseWithError | _ResponseWithValue<T> | _ResponseRead;
|
|
54
|
-
export interface FileData {
|
|
55
|
-
path: string;
|
|
56
|
-
flag: string;
|
|
57
|
-
stats: StatsLike<number>;
|
|
58
|
-
}
|
|
59
|
-
export type { FileData as File };
|
|
60
|
-
export declare function isMessage(arg: unknown): arg is Message;
|
|
61
|
-
type _Executor = Parameters<ConstructorParameters<typeof Promise<any>>[0]>;
|
|
62
|
-
export interface Executor {
|
|
63
|
-
resolve: _Executor[0];
|
|
64
|
-
reject: _Executor[1];
|
|
65
|
-
fs?: PortFS;
|
|
66
|
-
}
|
|
67
|
-
export declare function request<const TRequest extends Request, TValue>(request: Omit<TRequest, 'id' | 'stack' | '_zenfs'>, { port, timeout, fs }?: Partial<Options> & {
|
|
68
|
-
fs?: PortFS;
|
|
69
|
-
}): Promise<TValue>;
|
|
70
|
-
export declare function handleResponse<const TResponse extends Response>(response: TResponse): void;
|
|
71
|
-
export declare function attach<T extends Message>(port: Port, handler: (message: T) => unknown): void;
|
|
72
|
-
export declare function detach<T extends Message>(port: Port, handler: (message: T) => unknown): void;
|
|
73
|
-
export declare function catchMessages<T extends Backend>(port: Port): (fs: FilesystemOf<T>) => Promise<void>;
|
|
74
|
-
/**
|
|
75
|
-
* @internal
|
|
76
|
-
*/
|
|
77
|
-
export declare function waitOnline(port: Port): Promise<void>;
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { Errno, ErrnoError } from '../../internal/error.js';
|
|
2
|
-
import { LazyFile } from '../../internal/file.js';
|
|
3
|
-
import { err, info } from '../../internal/log.js';
|
|
4
|
-
import { Stats } from '../../stats.js';
|
|
5
|
-
import { handleRequest } from './fs.js';
|
|
6
|
-
function isFileData(value) {
|
|
7
|
-
return typeof value == 'object' && value != null && 'path' in value && 'flag' in value;
|
|
8
|
-
}
|
|
9
|
-
// general types
|
|
10
|
-
export function isMessage(arg) {
|
|
11
|
-
return typeof arg == 'object' && arg != null && '_zenfs' in arg && !!arg._zenfs;
|
|
12
|
-
}
|
|
13
|
-
const executors = new Map();
|
|
14
|
-
export function request(request, { port, timeout = 1000, fs } = {}) {
|
|
15
|
-
const stack = '\n' + new Error().stack.slice('Error:'.length);
|
|
16
|
-
if (!port)
|
|
17
|
-
throw err(new ErrnoError(Errno.EINVAL, 'Can not make an RPC request without a port'));
|
|
18
|
-
return new Promise((resolve, reject) => {
|
|
19
|
-
const id = Math.random().toString(16).slice(10);
|
|
20
|
-
executors.set(id, { resolve, reject, fs });
|
|
21
|
-
port.postMessage({ ...request, _zenfs: true, id, stack });
|
|
22
|
-
const _ = setTimeout(() => {
|
|
23
|
-
const error = err(new ErrnoError(Errno.EIO, 'RPC Failed', typeof request.args[0] == 'string' ? request.args[0] : '', request.method), {
|
|
24
|
-
fs,
|
|
25
|
-
});
|
|
26
|
-
error.stack += stack;
|
|
27
|
-
reject(error);
|
|
28
|
-
if (typeof _ == 'object')
|
|
29
|
-
_.unref();
|
|
30
|
-
}, timeout);
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
export function handleResponse(response) {
|
|
34
|
-
if (!isMessage(response)) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
const { id, value, error, stack } = response;
|
|
38
|
-
if (!executors.has(id)) {
|
|
39
|
-
const error = err(new ErrnoError(Errno.EIO, 'Invalid RPC id:' + id));
|
|
40
|
-
error.stack += stack;
|
|
41
|
-
throw error;
|
|
42
|
-
}
|
|
43
|
-
const { resolve, reject, fs } = executors.get(id);
|
|
44
|
-
if (error) {
|
|
45
|
-
const e = ErrnoError.fromJSON({ code: 'EIO', errno: Errno.EIO, ...value });
|
|
46
|
-
e.stack += stack;
|
|
47
|
-
reject(e);
|
|
48
|
-
executors.delete(id);
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
if (isFileData(value)) {
|
|
52
|
-
const { path, flag, stats } = value;
|
|
53
|
-
const file = new LazyFile(fs, path, flag, new Stats(stats));
|
|
54
|
-
resolve(file);
|
|
55
|
-
executors.delete(id);
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
resolve(value);
|
|
59
|
-
executors.delete(id);
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
export function attach(port, handler) {
|
|
63
|
-
if (!port)
|
|
64
|
-
throw err(new ErrnoError(Errno.EINVAL, 'Cannot attach to non-existent port'));
|
|
65
|
-
info('Attached handler to port: ' + handler.name);
|
|
66
|
-
port['on' in port ? 'on' : 'addEventListener']('message', (message) => {
|
|
67
|
-
handler(typeof message == 'object' && message !== null && 'data' in message ? message.data : message);
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
export function detach(port, handler) {
|
|
71
|
-
if (!port)
|
|
72
|
-
throw err(new ErrnoError(Errno.EINVAL, 'Cannot detach from non-existent port'));
|
|
73
|
-
info('Detached handler from port: ' + handler.name);
|
|
74
|
-
port['off' in port ? 'off' : 'removeEventListener']('message', (message) => {
|
|
75
|
-
handler(typeof message == 'object' && message !== null && 'data' in message ? message.data : message);
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
export function catchMessages(port) {
|
|
79
|
-
const events = [];
|
|
80
|
-
const handler = events.push.bind(events);
|
|
81
|
-
attach(port, handler);
|
|
82
|
-
return async function (fs) {
|
|
83
|
-
detach(port, handler);
|
|
84
|
-
for (const event of events) {
|
|
85
|
-
const request = 'data' in event ? event.data : event;
|
|
86
|
-
await handleRequest(port, fs, request);
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* @internal
|
|
92
|
-
*/
|
|
93
|
-
export async function waitOnline(port) {
|
|
94
|
-
if (!('on' in port))
|
|
95
|
-
return; // Only need to wait in Node.js
|
|
96
|
-
const online = Promise.withResolvers();
|
|
97
|
-
setTimeout(online.reject, 500);
|
|
98
|
-
port.on('online', online.resolve);
|
|
99
|
-
await online.promise;
|
|
100
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { AsyncMap, SyncMapStore } from './map.js';
|
|
2
|
-
import { SyncMapTransaction } from './map.js';
|
|
3
|
-
import type { Store } from './store.js';
|
|
4
|
-
/**
|
|
5
|
-
* @category Stores and Transactions
|
|
6
|
-
* @deprecated Use `MapStore` instead.
|
|
7
|
-
*/
|
|
8
|
-
export type SimpleSyncStore = SyncMapStore;
|
|
9
|
-
/**
|
|
10
|
-
* @category Stores and Transactions
|
|
11
|
-
* @deprecated Use `AsyncMapStore` instead.
|
|
12
|
-
*/
|
|
13
|
-
export type SimpleAsyncStore = AsyncMap & Store;
|
|
14
|
-
/**
|
|
15
|
-
* @category Stores and Transactions
|
|
16
|
-
* @deprecated Use `MapTransaction` instead.
|
|
17
|
-
*/
|
|
18
|
-
export declare class SimpleTransaction extends SyncMapTransaction {
|
|
19
|
-
constructor(store: SyncMapStore);
|
|
20
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { log_deprecated } from '../../internal/log.js';
|
|
2
|
-
import { SyncMapTransaction } from './map.js';
|
|
3
|
-
/**
|
|
4
|
-
* @category Stores and Transactions
|
|
5
|
-
* @deprecated Use `MapTransaction` instead.
|
|
6
|
-
*/
|
|
7
|
-
export class SimpleTransaction extends SyncMapTransaction {
|
|
8
|
-
constructor(store) {
|
|
9
|
-
log_deprecated('SimpleTransaction');
|
|
10
|
-
super(store);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
/* node:coverage enable */
|
package/dist/internal/file.d.ts
DELETED
|
@@ -1,359 +0,0 @@
|
|
|
1
|
-
import { Stats, type StatsLike } from '../stats.js';
|
|
2
|
-
import type { FileSystem, StreamOptions } from './filesystem.js';
|
|
3
|
-
import '../polyfills.js';
|
|
4
|
-
/**
|
|
5
|
-
* @internal @hidden
|
|
6
|
-
*/
|
|
7
|
-
export declare function parseFlag(flag: string | number): string;
|
|
8
|
-
/**
|
|
9
|
-
* @internal @hidden
|
|
10
|
-
*/
|
|
11
|
-
export declare function flagToString(flag: number): string;
|
|
12
|
-
/**
|
|
13
|
-
* @internal @hidden
|
|
14
|
-
*/
|
|
15
|
-
export declare function flagToNumber(flag: string): number;
|
|
16
|
-
/**
|
|
17
|
-
* Parses a flag as a mode (W_OK, R_OK, and/or X_OK)
|
|
18
|
-
* @param flag the flag to parse
|
|
19
|
-
* @internal @hidden
|
|
20
|
-
*/
|
|
21
|
-
export declare function flagToMode(flag: string): number;
|
|
22
|
-
/** @hidden */
|
|
23
|
-
export declare function isReadable(flag: string): boolean;
|
|
24
|
-
/** @hidden */
|
|
25
|
-
export declare function isWriteable(flag: string): boolean;
|
|
26
|
-
/** @hidden */
|
|
27
|
-
export declare function isTruncating(flag: string): boolean;
|
|
28
|
-
/** @hidden */
|
|
29
|
-
export declare function isAppendable(flag: string): boolean;
|
|
30
|
-
/** @hidden */
|
|
31
|
-
export declare function isSynchronous(flag: string): boolean;
|
|
32
|
-
/** @hidden */
|
|
33
|
-
export declare function isExclusive(flag: string): boolean;
|
|
34
|
-
/** @hidden */
|
|
35
|
-
export interface FileReadResult<T extends ArrayBufferView> {
|
|
36
|
-
bytesRead: number;
|
|
37
|
-
buffer: T;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* @category Internals
|
|
41
|
-
*/
|
|
42
|
-
export declare abstract class File<FS extends FileSystem = FileSystem> {
|
|
43
|
-
/**
|
|
44
|
-
* @internal
|
|
45
|
-
* The file system that created the file
|
|
46
|
-
*/
|
|
47
|
-
fs: FS;
|
|
48
|
-
readonly path: string;
|
|
49
|
-
constructor(
|
|
50
|
-
/**
|
|
51
|
-
* @internal
|
|
52
|
-
* The file system that created the file
|
|
53
|
-
*/
|
|
54
|
-
fs: FS, path: string);
|
|
55
|
-
/**
|
|
56
|
-
* Get the current file position.
|
|
57
|
-
*/
|
|
58
|
-
abstract position: number;
|
|
59
|
-
abstract stat(): Promise<Stats>;
|
|
60
|
-
abstract statSync(): Stats;
|
|
61
|
-
abstract close(): Promise<void>;
|
|
62
|
-
abstract closeSync(): void;
|
|
63
|
-
[Symbol.asyncDispose](): Promise<void>;
|
|
64
|
-
[Symbol.dispose](): void;
|
|
65
|
-
abstract truncate(len: number): Promise<void>;
|
|
66
|
-
abstract truncateSync(len: number): void;
|
|
67
|
-
abstract sync(): Promise<void>;
|
|
68
|
-
abstract syncSync(): void;
|
|
69
|
-
/**
|
|
70
|
-
* Write buffer to the file.
|
|
71
|
-
* @param buffer Uint8Array containing the data to write to the file.
|
|
72
|
-
* @param offset Offset in the buffer to start reading data from.
|
|
73
|
-
* @param length The amount of bytes to write to the file.
|
|
74
|
-
* @param position Offset from the beginning of the file where this data should be written.
|
|
75
|
-
* If position is null, the data will be written at the current position.
|
|
76
|
-
* @returns Promise resolving to the new length of the buffer
|
|
77
|
-
*/
|
|
78
|
-
abstract write(buffer: Uint8Array, offset?: number, length?: number, position?: number): Promise<number>;
|
|
79
|
-
/**
|
|
80
|
-
* Write buffer to the file.
|
|
81
|
-
* @param buffer Uint8Array containing the data to write to the file.
|
|
82
|
-
* @param offset Offset in the buffer to start reading data from.
|
|
83
|
-
* @param length The amount of bytes to write to the file.
|
|
84
|
-
* @param position Offset from the beginning of the file where this data should be written.
|
|
85
|
-
* If position is null, the data will be written at the current position.
|
|
86
|
-
*/
|
|
87
|
-
abstract writeSync(buffer: Uint8Array, offset?: number, length?: number, position?: number): number;
|
|
88
|
-
/**
|
|
89
|
-
* Read data from the file.
|
|
90
|
-
* @param buffer The buffer that the data will be written to.
|
|
91
|
-
* @param offset The offset within the buffer where writing will start.
|
|
92
|
-
* @param length An integer specifying the number of bytes to read.
|
|
93
|
-
* @param position An integer specifying where to begin reading from in the file.
|
|
94
|
-
* If position is null, data will be read from the current file position.
|
|
95
|
-
* @returns Promise resolving to the new length of the buffer
|
|
96
|
-
*/
|
|
97
|
-
abstract read<TBuffer extends ArrayBufferView>(buffer: TBuffer, offset?: number, length?: number, position?: number): Promise<FileReadResult<TBuffer>>;
|
|
98
|
-
/**
|
|
99
|
-
* Read data from the file.
|
|
100
|
-
* @param buffer The buffer that the data will be written to.
|
|
101
|
-
* @param offset The offset within the buffer where writing will start.
|
|
102
|
-
* @param length An integer specifying the number of bytes to read.
|
|
103
|
-
* @param position An integer specifying where to begin reading from in the file.
|
|
104
|
-
* If position is null, data will be read from the current file position.
|
|
105
|
-
*/
|
|
106
|
-
abstract readSync(buffer: ArrayBufferView, offset?: number, length?: number, position?: number): number;
|
|
107
|
-
/**
|
|
108
|
-
* Default implementation maps to `sync`.
|
|
109
|
-
*/
|
|
110
|
-
datasync(): Promise<void>;
|
|
111
|
-
/**
|
|
112
|
-
* Default implementation maps to `syncSync`.
|
|
113
|
-
*/
|
|
114
|
-
datasyncSync(): void;
|
|
115
|
-
abstract chown(uid: number, gid: number): Promise<void>;
|
|
116
|
-
abstract chownSync(uid: number, gid: number): void;
|
|
117
|
-
abstract chmod(mode: number): Promise<void>;
|
|
118
|
-
abstract chmodSync(mode: number): void;
|
|
119
|
-
/**
|
|
120
|
-
* Change the file timestamps of the file.
|
|
121
|
-
*/
|
|
122
|
-
abstract utimes(atime: number, mtime: number): Promise<void>;
|
|
123
|
-
/**
|
|
124
|
-
* Change the file timestamps of the file.
|
|
125
|
-
*/
|
|
126
|
-
abstract utimesSync(atime: number, mtime: number): void;
|
|
127
|
-
/**
|
|
128
|
-
* Create a stream for reading the file.
|
|
129
|
-
*/
|
|
130
|
-
streamRead(options: StreamOptions): ReadableStream;
|
|
131
|
-
/**
|
|
132
|
-
* Create a stream for writing the file.
|
|
133
|
-
*/
|
|
134
|
-
streamWrite(options: StreamOptions): WritableStream;
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* An implementation of `File` that operates completely in-memory.
|
|
138
|
-
* `PreloadFile`s are backed by a `Uint8Array`.
|
|
139
|
-
* @category Internals
|
|
140
|
-
*/
|
|
141
|
-
export declare class PreloadFile<FS extends FileSystem> extends File<FS> {
|
|
142
|
-
readonly flag: string;
|
|
143
|
-
readonly stats: Stats;
|
|
144
|
-
/**
|
|
145
|
-
* A buffer containing the entire contents of the file.
|
|
146
|
-
*/
|
|
147
|
-
protected _buffer: Uint8Array;
|
|
148
|
-
/**
|
|
149
|
-
* Current position
|
|
150
|
-
*/
|
|
151
|
-
protected _position: number;
|
|
152
|
-
/**
|
|
153
|
-
* Whether the file has changes which have not been written to the FS
|
|
154
|
-
*/
|
|
155
|
-
protected dirty: boolean;
|
|
156
|
-
/**
|
|
157
|
-
* Whether the file is open or closed
|
|
158
|
-
*/
|
|
159
|
-
protected closed: boolean;
|
|
160
|
-
/**
|
|
161
|
-
* Creates a file with `path` and, optionally, the given contents.
|
|
162
|
-
* Note that, if contents is specified, it will be mutated by the file.
|
|
163
|
-
*/
|
|
164
|
-
constructor(fs: FS, path: string, flag: string, stats: Stats,
|
|
165
|
-
/**
|
|
166
|
-
* A buffer containing the entire contents of the file.
|
|
167
|
-
*/
|
|
168
|
-
_buffer?: Uint8Array);
|
|
169
|
-
/**
|
|
170
|
-
* Get the underlying buffer for this file. Mutating not recommended and will mess up dirty tracking.
|
|
171
|
-
*/
|
|
172
|
-
get buffer(): Uint8Array;
|
|
173
|
-
/**
|
|
174
|
-
* Get the current file position.
|
|
175
|
-
*
|
|
176
|
-
* We emulate the following bug mentioned in the Node documentation:
|
|
177
|
-
*
|
|
178
|
-
* On Linux, positional writes don't work when the file is opened in append mode.
|
|
179
|
-
* The kernel ignores the position argument and always appends the data to the end of the file.
|
|
180
|
-
* @returns The current file position.
|
|
181
|
-
*/
|
|
182
|
-
get position(): number;
|
|
183
|
-
set position(value: number);
|
|
184
|
-
sync(): Promise<void>;
|
|
185
|
-
syncSync(): void;
|
|
186
|
-
close(): Promise<void>;
|
|
187
|
-
closeSync(): void;
|
|
188
|
-
/**
|
|
189
|
-
* Cleans up. This will *not* sync the file data to the FS
|
|
190
|
-
*/
|
|
191
|
-
protected dispose(force?: boolean): void;
|
|
192
|
-
stat(): Promise<Stats>;
|
|
193
|
-
statSync(): Stats;
|
|
194
|
-
protected _truncate(length: number): void;
|
|
195
|
-
truncate(length: number): Promise<void>;
|
|
196
|
-
truncateSync(length: number): void;
|
|
197
|
-
protected _write(buffer: Uint8Array, offset?: number, length?: number, position?: number): number;
|
|
198
|
-
/**
|
|
199
|
-
* Write buffer to the file.
|
|
200
|
-
* @param buffer Uint8Array containing the data to write to the file.
|
|
201
|
-
* @param offset Offset in the buffer to start reading data from.
|
|
202
|
-
* @param length The amount of bytes to write to the file.
|
|
203
|
-
* @param position Offset from the beginning of the file where this data should be written.
|
|
204
|
-
* If position is null, the data will be written at the current position.
|
|
205
|
-
*/
|
|
206
|
-
write(buffer: Uint8Array, offset?: number, length?: number, position?: number): Promise<number>;
|
|
207
|
-
/**
|
|
208
|
-
* Write buffer to the file.
|
|
209
|
-
* @param buffer Uint8Array containing the data to write to the file.
|
|
210
|
-
* @param offset Offset in the buffer to start reading data from.
|
|
211
|
-
* @param length The amount of bytes to write to the file.
|
|
212
|
-
* @param position Offset from the beginning of the file where this data should be written.
|
|
213
|
-
* If position is null, the data will be written at the current position.
|
|
214
|
-
* @returns bytes written
|
|
215
|
-
*/
|
|
216
|
-
writeSync(buffer: Uint8Array, offset?: number, length?: number, position?: number): number;
|
|
217
|
-
protected _read(buffer: ArrayBufferView, offset?: number, length?: number, position?: number): number;
|
|
218
|
-
/**
|
|
219
|
-
* Read data from the file.
|
|
220
|
-
* @param buffer The buffer that the data will be written to.
|
|
221
|
-
* @param offset The offset within the buffer where writing will start.
|
|
222
|
-
* @param length An integer specifying the number of bytes to read.
|
|
223
|
-
* @param position An integer specifying where to begin reading from in the file.
|
|
224
|
-
* If position is null, data will be read from the current file position.
|
|
225
|
-
*/
|
|
226
|
-
read<TBuffer extends ArrayBufferView>(buffer: TBuffer, offset?: number, length?: number, position?: number): Promise<{
|
|
227
|
-
bytesRead: number;
|
|
228
|
-
buffer: TBuffer;
|
|
229
|
-
}>;
|
|
230
|
-
/**
|
|
231
|
-
* Read data from the file.
|
|
232
|
-
* @param buffer The buffer that the data will be written to.
|
|
233
|
-
* @param offset The offset within the buffer where writing will start.
|
|
234
|
-
* @param length An integer specifying the number of bytes to read.
|
|
235
|
-
* @param position An integer specifying where to begin reading from in the file.
|
|
236
|
-
* If position is null, data will be read from the current file position.
|
|
237
|
-
* @returns number of bytes written
|
|
238
|
-
*/
|
|
239
|
-
readSync(buffer: ArrayBufferView, offset?: number, length?: number, position?: number): number;
|
|
240
|
-
chmod(mode: number): Promise<void>;
|
|
241
|
-
chmodSync(mode: number): void;
|
|
242
|
-
chown(uid: number, gid: number): Promise<void>;
|
|
243
|
-
chownSync(uid: number, gid: number): void;
|
|
244
|
-
utimes(atime: number, mtime: number): Promise<void>;
|
|
245
|
-
utimesSync(atime: number, mtime: number): void;
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* For the file systems which do not sync to anything.
|
|
249
|
-
* @category Internals
|
|
250
|
-
* @deprecated
|
|
251
|
-
*/
|
|
252
|
-
export declare class NoSyncFile<T extends FileSystem> extends PreloadFile<T> {
|
|
253
|
-
constructor(...args: ConstructorParameters<typeof PreloadFile<T>>);
|
|
254
|
-
sync(): Promise<void>;
|
|
255
|
-
syncSync(): void;
|
|
256
|
-
close(): Promise<void>;
|
|
257
|
-
closeSync(): void;
|
|
258
|
-
}
|
|
259
|
-
/**
|
|
260
|
-
* An implementation of `File` that uses the FS
|
|
261
|
-
* @category Internals
|
|
262
|
-
*/
|
|
263
|
-
export declare class LazyFile<FS extends FileSystem> extends File<FS> {
|
|
264
|
-
readonly flag: string;
|
|
265
|
-
readonly stats: StatsLike<number>;
|
|
266
|
-
protected _buffer?: Uint8Array;
|
|
267
|
-
/**
|
|
268
|
-
* Current position
|
|
269
|
-
*/
|
|
270
|
-
protected _position: number;
|
|
271
|
-
/**
|
|
272
|
-
* Get the current file position.
|
|
273
|
-
*
|
|
274
|
-
* We emulate the following bug mentioned in the Node documentation:
|
|
275
|
-
*
|
|
276
|
-
* On Linux, positional writes don't work when the file is opened in append mode.
|
|
277
|
-
* The kernel ignores the position argument and always appends the data to the end of the file.
|
|
278
|
-
* @returns The current file position.
|
|
279
|
-
*/
|
|
280
|
-
get position(): number;
|
|
281
|
-
set position(value: number);
|
|
282
|
-
/**
|
|
283
|
-
* Whether the file has changes which have not been written to the FS
|
|
284
|
-
*/
|
|
285
|
-
protected dirty: boolean;
|
|
286
|
-
/**
|
|
287
|
-
* Whether the file is open or closed
|
|
288
|
-
*/
|
|
289
|
-
protected closed: boolean;
|
|
290
|
-
/**
|
|
291
|
-
* Creates a file with `path` and, optionally, the given contents.
|
|
292
|
-
* Note that, if contents is specified, it will be mutated by the file.
|
|
293
|
-
*/
|
|
294
|
-
constructor(fs: FS, path: string, flag: string, stats: StatsLike<number>);
|
|
295
|
-
sync(): Promise<void>;
|
|
296
|
-
syncSync(): void;
|
|
297
|
-
close(): Promise<void>;
|
|
298
|
-
closeSync(): void;
|
|
299
|
-
/**
|
|
300
|
-
* Cleans up. This will *not* sync the file data to the FS
|
|
301
|
-
*/
|
|
302
|
-
protected dispose(force?: boolean): void;
|
|
303
|
-
stat(): Promise<Stats>;
|
|
304
|
-
statSync(): Stats;
|
|
305
|
-
truncate(length: number): Promise<void>;
|
|
306
|
-
truncateSync(length: number): void;
|
|
307
|
-
protected prepareWrite(buffer: Uint8Array, offset: number, length: number, position: number): Uint8Array;
|
|
308
|
-
/**
|
|
309
|
-
* Write buffer to the file.
|
|
310
|
-
* @param buffer Uint8Array containing the data to write to the file.
|
|
311
|
-
* @param offset Offset in the buffer to start reading data from.
|
|
312
|
-
* @param length The amount of bytes to write to the file.
|
|
313
|
-
* @param position Offset from the beginning of the file where this data should be written.
|
|
314
|
-
* If position is null, the data will be written at the current position.
|
|
315
|
-
*/
|
|
316
|
-
write(buffer: Uint8Array, offset?: number, length?: number, position?: number): Promise<number>;
|
|
317
|
-
/**
|
|
318
|
-
* Write buffer to the file.
|
|
319
|
-
* @param buffer Uint8Array containing the data to write to the file.
|
|
320
|
-
* @param offset Offset in the buffer to start reading data from.
|
|
321
|
-
* @param length The amount of bytes to write to the file.
|
|
322
|
-
* @param position Offset from the beginning of the file where this data should be written.
|
|
323
|
-
* If position is null, the data will be written at the current position.
|
|
324
|
-
* @returns bytes written
|
|
325
|
-
*/
|
|
326
|
-
writeSync(buffer: Uint8Array, offset?: number, length?: number, position?: number): number;
|
|
327
|
-
/**
|
|
328
|
-
* Computes position information for reading
|
|
329
|
-
*/
|
|
330
|
-
protected prepareRead(length: number, position: number): number;
|
|
331
|
-
/**
|
|
332
|
-
* Read data from the file.
|
|
333
|
-
* @param buffer The buffer that the data will be written to.
|
|
334
|
-
* @param offset The offset within the buffer where writing will start.
|
|
335
|
-
* @param length An integer specifying the number of bytes to read.
|
|
336
|
-
* @param position An integer specifying where to begin reading from in the file.
|
|
337
|
-
* If position is unset, data will be read from the current file position.
|
|
338
|
-
*/
|
|
339
|
-
read<TBuffer extends ArrayBufferView>(buffer: TBuffer, offset?: number, length?: number, position?: number): Promise<{
|
|
340
|
-
bytesRead: number;
|
|
341
|
-
buffer: TBuffer;
|
|
342
|
-
}>;
|
|
343
|
-
/**
|
|
344
|
-
* Read data from the file.
|
|
345
|
-
* @param buffer The buffer that the data will be written to.
|
|
346
|
-
* @param offset The offset within the buffer where writing will start.
|
|
347
|
-
* @param length An integer specifying the number of bytes to read.
|
|
348
|
-
* @param position An integer specifying where to begin reading from in the file.
|
|
349
|
-
* If position is null, data will be read from the current file position.
|
|
350
|
-
* @returns number of bytes written
|
|
351
|
-
*/
|
|
352
|
-
readSync(buffer: ArrayBufferView, offset?: number, length?: number, position?: number): number;
|
|
353
|
-
chmod(mode: number): Promise<void>;
|
|
354
|
-
chmodSync(mode: number): void;
|
|
355
|
-
chown(uid: number, gid: number): Promise<void>;
|
|
356
|
-
chownSync(uid: number, gid: number): void;
|
|
357
|
-
utimes(atime: number, mtime: number): Promise<void>;
|
|
358
|
-
utimesSync(atime: number, mtime: number): void;
|
|
359
|
-
}
|