memfs 3.6.0 → 4.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.
- package/LICENSE +201 -24
- package/README.md +21 -92
- package/lib/Dirent.d.ts +2 -1
- package/lib/__tests__/util.d.ts +13 -0
- package/lib/__tests__/util.js +29 -0
- package/lib/consts/AMODE.d.ts +9 -0
- package/lib/consts/FLAG.d.ts +22 -0
- package/lib/consts/FLAG.js +2 -0
- package/lib/fsa/types.d.ts +82 -0
- package/lib/fsa/types.js +2 -0
- package/lib/fsa-to-node/FsaNodeCore.d.ts +32 -0
- package/lib/fsa-to-node/FsaNodeCore.js +168 -0
- package/lib/fsa-to-node/FsaNodeDirent.d.ts +13 -0
- package/lib/fsa-to-node/FsaNodeDirent.js +31 -0
- package/lib/fsa-to-node/FsaNodeFs.d.ts +171 -0
- package/lib/fsa-to-node/FsaNodeFs.js +842 -0
- package/lib/fsa-to-node/FsaNodeFsOpenFile.d.ts +24 -0
- package/lib/fsa-to-node/FsaNodeFsOpenFile.js +46 -0
- package/lib/fsa-to-node/FsaNodeReadStream.d.ts +24 -0
- package/lib/fsa-to-node/FsaNodeReadStream.js +100 -0
- package/lib/fsa-to-node/FsaNodeStats.d.ts +30 -0
- package/lib/fsa-to-node/FsaNodeStats.js +52 -0
- package/lib/fsa-to-node/FsaNodeWriteStream.d.ts +48 -0
- package/lib/fsa-to-node/FsaNodeWriteStream.js +162 -0
- package/lib/fsa-to-node/__tests__/FsaNodeFs.test.d.ts +1 -0
- package/lib/fsa-to-node/__tests__/FsaNodeFs.test.js +873 -0
- package/lib/fsa-to-node/__tests__/util.test.d.ts +1 -0
- package/lib/fsa-to-node/__tests__/util.test.js +28 -0
- package/lib/fsa-to-node/constants.d.ts +3 -0
- package/lib/fsa-to-node/constants.js +2 -0
- package/lib/fsa-to-node/index.d.ts +2 -0
- package/lib/fsa-to-node/index.js +7 -0
- package/lib/fsa-to-node/json.d.ts +4 -0
- package/lib/fsa-to-node/json.js +7 -0
- package/lib/fsa-to-node/types.d.ts +37 -0
- package/lib/fsa-to-node/types.js +2 -0
- package/lib/fsa-to-node/util.d.ts +4 -0
- package/lib/fsa-to-node/util.js +40 -0
- package/lib/fsa-to-node/worker/FsaNodeSyncAdapterWorker.d.ts +10 -0
- package/lib/fsa-to-node/worker/FsaNodeSyncAdapterWorker.js +72 -0
- package/lib/fsa-to-node/worker/FsaNodeSyncWorker.d.ts +20 -0
- package/lib/fsa-to-node/worker/FsaNodeSyncWorker.js +190 -0
- package/lib/fsa-to-node/worker/SyncMessenger.d.ts +24 -0
- package/lib/fsa-to-node/worker/SyncMessenger.js +80 -0
- package/lib/fsa-to-node/worker/constants.d.ts +8 -0
- package/lib/fsa-to-node/worker/constants.js +2 -0
- package/lib/fsa-to-node/worker/types.d.ts +17 -0
- package/lib/fsa-to-node/worker/types.js +2 -0
- package/lib/index.d.ts +5 -4
- package/lib/index.js +1 -1
- package/lib/node/constants.d.ts +41 -0
- package/lib/node/constants.js +56 -0
- package/lib/node/options.d.ts +23 -0
- package/lib/node/options.js +94 -0
- package/lib/node/promises.d.ts +1 -1
- package/lib/node/promises.js +1 -3
- package/lib/node/types/FsCommonObjects.d.ts +17 -0
- package/lib/node/types/FsCommonObjects.js +2 -0
- package/lib/node/types/{sync.d.ts → FsSynchronousApi.d.ts} +36 -37
- package/lib/node/types/FsSynchronousApi.js +2 -0
- package/lib/node/types/callback.d.ts +57 -58
- package/lib/node/types/index.d.ts +1 -1
- package/lib/node/types/misc.d.ts +6 -8
- package/lib/node/types/options.d.ts +20 -6
- package/lib/node/types/promises.d.ts +2 -2
- package/lib/node/util.d.ts +19 -0
- package/lib/node/util.js +265 -1
- package/lib/node-to-fsa/NodeFileSystemDirectoryHandle.d.ts +71 -0
- package/lib/node-to-fsa/NodeFileSystemDirectoryHandle.js +264 -0
- package/lib/node-to-fsa/NodeFileSystemFileHandle.d.ts +28 -0
- package/lib/node-to-fsa/NodeFileSystemFileHandle.js +73 -0
- package/lib/node-to-fsa/NodeFileSystemHandle.d.ts +33 -0
- package/lib/node-to-fsa/NodeFileSystemHandle.js +53 -0
- package/lib/node-to-fsa/NodeFileSystemSyncAccessHandle.d.ts +42 -0
- package/lib/node-to-fsa/NodeFileSystemSyncAccessHandle.js +116 -0
- package/lib/node-to-fsa/NodeFileSystemWritableFileStream.d.ts +54 -0
- package/lib/node-to-fsa/NodeFileSystemWritableFileStream.js +195 -0
- package/lib/node-to-fsa/NodePermissionStatus.d.ts +8 -0
- package/lib/node-to-fsa/NodePermissionStatus.js +13 -0
- package/lib/node-to-fsa/__tests__/NodeFileSystemDirectoryHandle.test.d.ts +1 -0
- package/lib/node-to-fsa/__tests__/NodeFileSystemDirectoryHandle.test.js +627 -0
- package/lib/node-to-fsa/__tests__/NodeFileSystemFileHandle.test.d.ts +1 -0
- package/lib/node-to-fsa/__tests__/NodeFileSystemFileHandle.test.js +191 -0
- package/lib/node-to-fsa/__tests__/NodeFileSystemHandle.test.d.ts +1 -0
- package/lib/node-to-fsa/__tests__/NodeFileSystemHandle.test.js +49 -0
- package/lib/node-to-fsa/__tests__/NodeFileSystemSyncAccessHandle.test.d.ts +1 -0
- package/lib/node-to-fsa/__tests__/NodeFileSystemSyncAccessHandle.test.js +183 -0
- package/lib/node-to-fsa/__tests__/NodeFileSystemWritableFileStream.test.d.ts +1 -0
- package/lib/node-to-fsa/__tests__/NodeFileSystemWritableFileStream.test.js +106 -0
- package/lib/node-to-fsa/__tests__/scenarios.test.d.ts +1 -0
- package/lib/node-to-fsa/__tests__/scenarios.test.js +46 -0
- package/lib/node-to-fsa/__tests__/util.test.d.ts +1 -0
- package/lib/node-to-fsa/__tests__/util.test.js +25 -0
- package/lib/node-to-fsa/index.d.ts +7 -0
- package/lib/node-to-fsa/index.js +26 -0
- package/lib/node-to-fsa/types.d.ts +12 -0
- package/lib/node-to-fsa/types.js +2 -0
- package/lib/node-to-fsa/util.d.ts +11 -0
- package/lib/node-to-fsa/util.js +33 -0
- package/lib/node.d.ts +1 -1
- package/lib/volume.d.ts +45 -126
- package/lib/volume.js +204 -562
- package/lib/webfs/index.d.ts +1 -0
- package/lib/webfs/index.js +22 -0
- package/package.json +28 -5
- /package/lib/{node/types/sync.js → consts/AMODE.js} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import type { TEncodingExtended, TFlags, TMode } from './misc';
|
|
2
|
+
import type { IFileHandle, TEncodingExtended, TFlags, TMode } from './misc';
|
|
3
3
|
export interface IOptions {
|
|
4
4
|
encoding?: BufferEncoding | TEncodingExtended;
|
|
5
5
|
}
|
|
@@ -34,7 +34,6 @@ export interface IMkdirOptions {
|
|
|
34
34
|
recursive?: boolean;
|
|
35
35
|
}
|
|
36
36
|
export interface IRmdirOptions {
|
|
37
|
-
/** @deprecated */
|
|
38
37
|
recursive?: boolean;
|
|
39
38
|
maxRetries?: number;
|
|
40
39
|
retryDelay?: number;
|
|
@@ -49,21 +48,36 @@ export interface IWatchFileOptions {
|
|
|
49
48
|
persistent?: boolean;
|
|
50
49
|
interval?: number;
|
|
51
50
|
}
|
|
52
|
-
export interface IReadStreamOptions {
|
|
51
|
+
export interface IReadStreamOptions extends IOptions {
|
|
52
|
+
/** Defaults to `'r'`. */
|
|
53
53
|
flags?: TFlags;
|
|
54
|
+
/** Defaults to `null`. */
|
|
54
55
|
encoding?: BufferEncoding;
|
|
55
|
-
|
|
56
|
+
/** Defaults to `null`. */
|
|
57
|
+
fd?: number | IFileHandle | null;
|
|
58
|
+
/** Defaults to 0o666 */
|
|
56
59
|
mode?: TMode;
|
|
60
|
+
/** Defaults to `true`. */
|
|
57
61
|
autoClose?: boolean;
|
|
62
|
+
/** Defaults to `true`. */
|
|
63
|
+
emitClose?: boolean;
|
|
58
64
|
start?: number;
|
|
65
|
+
/** Defaults to `Infinity`. */
|
|
59
66
|
end?: number;
|
|
67
|
+
/** Defaults to `64 * 1024`. */
|
|
68
|
+
highWaterMark?: number;
|
|
69
|
+
/** Defaults to `null`. */
|
|
70
|
+
fs?: object | null;
|
|
71
|
+
/** Defaults to `null`. */
|
|
72
|
+
signal?: AbortSignal | null;
|
|
60
73
|
}
|
|
61
74
|
export interface IWriteStreamOptions {
|
|
62
75
|
flags?: TFlags;
|
|
63
|
-
|
|
64
|
-
fd?: number;
|
|
76
|
+
encoding?: BufferEncoding;
|
|
77
|
+
fd?: number | IFileHandle;
|
|
65
78
|
mode?: TMode;
|
|
66
79
|
autoClose?: boolean;
|
|
80
|
+
emitClose?: boolean;
|
|
67
81
|
start?: number;
|
|
68
82
|
}
|
|
69
83
|
export interface IWatchOptions extends IOptions {
|
|
@@ -12,9 +12,9 @@ export interface FsPromisesApi {
|
|
|
12
12
|
lchown(path: misc.PathLike, uid: number, gid: number): Promise<void>;
|
|
13
13
|
link(existingPath: misc.PathLike, newPath: misc.PathLike): Promise<void>;
|
|
14
14
|
lstat(path: misc.PathLike, options?: opts.IStatOptions): Promise<misc.IStats>;
|
|
15
|
-
mkdir(path: misc.PathLike, options?: misc.TMode | opts.IMkdirOptions): Promise<
|
|
15
|
+
mkdir(path: misc.PathLike, options?: misc.TMode | opts.IMkdirOptions): Promise<string | undefined>;
|
|
16
16
|
mkdtemp(prefix: string, options?: opts.IOptions): Promise<misc.TDataOut>;
|
|
17
|
-
open(path: misc.PathLike, flags
|
|
17
|
+
open(path: misc.PathLike, flags?: misc.TFlags, mode?: misc.TMode): Promise<misc.IFileHandle>;
|
|
18
18
|
readdir(path: misc.PathLike, options?: opts.IReaddirOptions | string): Promise<misc.TDataOut[] | misc.IDirent[]>;
|
|
19
19
|
readFile(id: misc.TFileHandle, options?: opts.IReadFileOptions | string): Promise<misc.TDataOut>;
|
|
20
20
|
readlink(path: misc.PathLike, options?: opts.IOptions): Promise<misc.TDataOut>;
|
package/lib/node/util.d.ts
CHANGED
|
@@ -1,2 +1,21 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
1
3
|
import type { FsCallbackApi } from './types';
|
|
4
|
+
import type * as misc from './types/misc';
|
|
5
|
+
import { TEncodingExtended } from '../encoding';
|
|
6
|
+
export declare const isWin: boolean;
|
|
2
7
|
export declare function promisify(fs: FsCallbackApi, fn: string, getResult?: (result: any) => any): (...args: any[]) => Promise<any>;
|
|
8
|
+
export declare function validateCallback<T>(callback: T): misc.AssertCallback<T>;
|
|
9
|
+
export declare function modeToNumber(mode: misc.TMode | undefined, def?: any): number;
|
|
10
|
+
export declare function nullCheck(path: any, callback?: any): boolean;
|
|
11
|
+
export declare function pathToFilename(path: misc.PathLike): string;
|
|
12
|
+
export declare function createError(errorCode: string, func?: string, path?: string, path2?: string, Constructor?: ErrorConstructor): Error;
|
|
13
|
+
export declare function genRndStr6(): string;
|
|
14
|
+
export declare function flagsToNumber(flags: misc.TFlags | undefined): number;
|
|
15
|
+
export declare function isFd(path: any): boolean;
|
|
16
|
+
export declare function validateFd(fd: any): void;
|
|
17
|
+
export declare function dataToBuffer(data: misc.TData, encoding?: string): Buffer;
|
|
18
|
+
export declare const bufToUint8: (buf: Buffer) => Uint8Array;
|
|
19
|
+
export declare const getWriteArgs: (fd: number, a?: unknown, b?: unknown, c?: unknown, d?: unknown, e?: unknown) => [fd: number, dataAsStr: boolean, buf: Buffer, offset: number, length: number, position: number | null, callback: (...args: any[]) => void];
|
|
20
|
+
export declare const getWriteSyncArgs: (fd: number, a: string | Buffer | ArrayBufferView | DataView, b?: number, c?: number | BufferEncoding, d?: number) => [fd: number, buf: Buffer, offset: number, length?: number | undefined, position?: number | undefined];
|
|
21
|
+
export declare function bufferToEncoding(buffer: Buffer, encoding?: TEncodingExtended): misc.TDataOut;
|
package/lib/node/util.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.promisify = void 0;
|
|
3
|
+
exports.bufferToEncoding = exports.getWriteSyncArgs = exports.getWriteArgs = exports.bufToUint8 = exports.dataToBuffer = exports.validateFd = exports.isFd = exports.flagsToNumber = exports.genRndStr6 = exports.createError = exports.pathToFilename = exports.nullCheck = exports.modeToNumber = exports.validateCallback = exports.promisify = exports.isWin = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
const errors = require("../internal/errors");
|
|
6
|
+
const encoding_1 = require("../encoding");
|
|
7
|
+
const buffer_1 = require("../internal/buffer");
|
|
8
|
+
exports.isWin = process.platform === 'win32';
|
|
4
9
|
function promisify(fs, fn, getResult = input => input) {
|
|
5
10
|
return (...args) => new Promise((resolve, reject) => {
|
|
6
11
|
fs[fn].bind(fs)(...args, (error, result) => {
|
|
@@ -11,3 +16,262 @@ function promisify(fs, fn, getResult = input => input) {
|
|
|
11
16
|
});
|
|
12
17
|
}
|
|
13
18
|
exports.promisify = promisify;
|
|
19
|
+
function validateCallback(callback) {
|
|
20
|
+
if (typeof callback !== 'function')
|
|
21
|
+
throw TypeError(constants_1.ERRSTR.CB);
|
|
22
|
+
return callback;
|
|
23
|
+
}
|
|
24
|
+
exports.validateCallback = validateCallback;
|
|
25
|
+
function _modeToNumber(mode, def) {
|
|
26
|
+
if (typeof mode === 'number')
|
|
27
|
+
return mode;
|
|
28
|
+
if (typeof mode === 'string')
|
|
29
|
+
return parseInt(mode, 8);
|
|
30
|
+
if (def)
|
|
31
|
+
return modeToNumber(def);
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
function modeToNumber(mode, def) {
|
|
35
|
+
const result = _modeToNumber(mode, def);
|
|
36
|
+
if (typeof result !== 'number' || isNaN(result))
|
|
37
|
+
throw new TypeError(constants_1.ERRSTR.MODE_INT);
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
exports.modeToNumber = modeToNumber;
|
|
41
|
+
function nullCheck(path, callback) {
|
|
42
|
+
if (('' + path).indexOf('\u0000') !== -1) {
|
|
43
|
+
const er = new Error('Path must be a string without null bytes');
|
|
44
|
+
er.code = 'ENOENT';
|
|
45
|
+
if (typeof callback !== 'function')
|
|
46
|
+
throw er;
|
|
47
|
+
process.nextTick(callback, er);
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
exports.nullCheck = nullCheck;
|
|
53
|
+
function getPathFromURLPosix(url) {
|
|
54
|
+
if (url.hostname !== '') {
|
|
55
|
+
throw new errors.TypeError('ERR_INVALID_FILE_URL_HOST', process.platform);
|
|
56
|
+
}
|
|
57
|
+
const pathname = url.pathname;
|
|
58
|
+
for (let n = 0; n < pathname.length; n++) {
|
|
59
|
+
if (pathname[n] === '%') {
|
|
60
|
+
const third = pathname.codePointAt(n + 2) | 0x20;
|
|
61
|
+
if (pathname[n + 1] === '2' && third === 102) {
|
|
62
|
+
throw new errors.TypeError('ERR_INVALID_FILE_URL_PATH', 'must not include encoded / characters');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return decodeURIComponent(pathname);
|
|
67
|
+
}
|
|
68
|
+
function pathToFilename(path) {
|
|
69
|
+
if (typeof path !== 'string' && !Buffer.isBuffer(path)) {
|
|
70
|
+
try {
|
|
71
|
+
if (!(path instanceof require('url').URL))
|
|
72
|
+
throw new TypeError(constants_1.ERRSTR.PATH_STR);
|
|
73
|
+
}
|
|
74
|
+
catch (err) {
|
|
75
|
+
throw new TypeError(constants_1.ERRSTR.PATH_STR);
|
|
76
|
+
}
|
|
77
|
+
path = getPathFromURLPosix(path);
|
|
78
|
+
}
|
|
79
|
+
const pathString = String(path);
|
|
80
|
+
nullCheck(pathString);
|
|
81
|
+
// return slash(pathString);
|
|
82
|
+
return pathString;
|
|
83
|
+
}
|
|
84
|
+
exports.pathToFilename = pathToFilename;
|
|
85
|
+
const ENOENT = 'ENOENT';
|
|
86
|
+
const EBADF = 'EBADF';
|
|
87
|
+
const EINVAL = 'EINVAL';
|
|
88
|
+
const EPERM = 'EPERM';
|
|
89
|
+
const EPROTO = 'EPROTO';
|
|
90
|
+
const EEXIST = 'EEXIST';
|
|
91
|
+
const ENOTDIR = 'ENOTDIR';
|
|
92
|
+
const EMFILE = 'EMFILE';
|
|
93
|
+
const EACCES = 'EACCES';
|
|
94
|
+
const EISDIR = 'EISDIR';
|
|
95
|
+
const ENOTEMPTY = 'ENOTEMPTY';
|
|
96
|
+
const ENOSYS = 'ENOSYS';
|
|
97
|
+
const ERR_FS_EISDIR = 'ERR_FS_EISDIR';
|
|
98
|
+
function formatError(errorCode, func = '', path = '', path2 = '') {
|
|
99
|
+
let pathFormatted = '';
|
|
100
|
+
if (path)
|
|
101
|
+
pathFormatted = ` '${path}'`;
|
|
102
|
+
if (path2)
|
|
103
|
+
pathFormatted += ` -> '${path2}'`;
|
|
104
|
+
switch (errorCode) {
|
|
105
|
+
case ENOENT:
|
|
106
|
+
return `ENOENT: no such file or directory, ${func}${pathFormatted}`;
|
|
107
|
+
case EBADF:
|
|
108
|
+
return `EBADF: bad file descriptor, ${func}${pathFormatted}`;
|
|
109
|
+
case EINVAL:
|
|
110
|
+
return `EINVAL: invalid argument, ${func}${pathFormatted}`;
|
|
111
|
+
case EPERM:
|
|
112
|
+
return `EPERM: operation not permitted, ${func}${pathFormatted}`;
|
|
113
|
+
case EPROTO:
|
|
114
|
+
return `EPROTO: protocol error, ${func}${pathFormatted}`;
|
|
115
|
+
case EEXIST:
|
|
116
|
+
return `EEXIST: file already exists, ${func}${pathFormatted}`;
|
|
117
|
+
case ENOTDIR:
|
|
118
|
+
return `ENOTDIR: not a directory, ${func}${pathFormatted}`;
|
|
119
|
+
case EISDIR:
|
|
120
|
+
return `EISDIR: illegal operation on a directory, ${func}${pathFormatted}`;
|
|
121
|
+
case EACCES:
|
|
122
|
+
return `EACCES: permission denied, ${func}${pathFormatted}`;
|
|
123
|
+
case ENOTEMPTY:
|
|
124
|
+
return `ENOTEMPTY: directory not empty, ${func}${pathFormatted}`;
|
|
125
|
+
case EMFILE:
|
|
126
|
+
return `EMFILE: too many open files, ${func}${pathFormatted}`;
|
|
127
|
+
case ENOSYS:
|
|
128
|
+
return `ENOSYS: function not implemented, ${func}${pathFormatted}`;
|
|
129
|
+
case ERR_FS_EISDIR:
|
|
130
|
+
return `[ERR_FS_EISDIR]: Path is a directory: ${func} returned EISDIR (is a directory) ${path}`;
|
|
131
|
+
default:
|
|
132
|
+
return `${errorCode}: error occurred, ${func}${pathFormatted}`;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function createError(errorCode, func = '', path = '', path2 = '', Constructor = Error) {
|
|
136
|
+
const error = new Constructor(formatError(errorCode, func, path, path2));
|
|
137
|
+
error.code = errorCode;
|
|
138
|
+
if (path) {
|
|
139
|
+
error.path = path;
|
|
140
|
+
}
|
|
141
|
+
return error;
|
|
142
|
+
}
|
|
143
|
+
exports.createError = createError;
|
|
144
|
+
function genRndStr6() {
|
|
145
|
+
const str = (Math.random() + 1).toString(36).substring(2, 8);
|
|
146
|
+
if (str.length === 6)
|
|
147
|
+
return str;
|
|
148
|
+
else
|
|
149
|
+
return genRndStr6();
|
|
150
|
+
}
|
|
151
|
+
exports.genRndStr6 = genRndStr6;
|
|
152
|
+
function flagsToNumber(flags) {
|
|
153
|
+
if (typeof flags === 'number')
|
|
154
|
+
return flags;
|
|
155
|
+
if (typeof flags === 'string') {
|
|
156
|
+
const flagsNum = constants_1.FLAGS[flags];
|
|
157
|
+
if (typeof flagsNum !== 'undefined')
|
|
158
|
+
return flagsNum;
|
|
159
|
+
}
|
|
160
|
+
// throw new TypeError(formatError(ERRSTR_FLAG(flags)));
|
|
161
|
+
throw new errors.TypeError('ERR_INVALID_OPT_VALUE', 'flags', flags);
|
|
162
|
+
}
|
|
163
|
+
exports.flagsToNumber = flagsToNumber;
|
|
164
|
+
function isFd(path) {
|
|
165
|
+
return path >>> 0 === path;
|
|
166
|
+
}
|
|
167
|
+
exports.isFd = isFd;
|
|
168
|
+
function validateFd(fd) {
|
|
169
|
+
if (!isFd(fd))
|
|
170
|
+
throw TypeError(constants_1.ERRSTR.FD);
|
|
171
|
+
}
|
|
172
|
+
exports.validateFd = validateFd;
|
|
173
|
+
function dataToBuffer(data, encoding = encoding_1.ENCODING_UTF8) {
|
|
174
|
+
if (Buffer.isBuffer(data))
|
|
175
|
+
return data;
|
|
176
|
+
else if (data instanceof Uint8Array)
|
|
177
|
+
return (0, buffer_1.bufferFrom)(data);
|
|
178
|
+
else
|
|
179
|
+
return (0, buffer_1.bufferFrom)(String(data), encoding);
|
|
180
|
+
}
|
|
181
|
+
exports.dataToBuffer = dataToBuffer;
|
|
182
|
+
const bufToUint8 = (buf) => new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
183
|
+
exports.bufToUint8 = bufToUint8;
|
|
184
|
+
const getWriteArgs = (fd, a, b, c, d, e) => {
|
|
185
|
+
validateFd(fd);
|
|
186
|
+
let offset = 0;
|
|
187
|
+
let length;
|
|
188
|
+
let position = null;
|
|
189
|
+
let encoding;
|
|
190
|
+
let callback;
|
|
191
|
+
const tipa = typeof a;
|
|
192
|
+
const tipb = typeof b;
|
|
193
|
+
const tipc = typeof c;
|
|
194
|
+
const tipd = typeof d;
|
|
195
|
+
if (tipa !== 'string') {
|
|
196
|
+
if (tipb === 'function') {
|
|
197
|
+
callback = b;
|
|
198
|
+
}
|
|
199
|
+
else if (tipc === 'function') {
|
|
200
|
+
offset = b | 0;
|
|
201
|
+
callback = c;
|
|
202
|
+
}
|
|
203
|
+
else if (tipd === 'function') {
|
|
204
|
+
offset = b | 0;
|
|
205
|
+
length = c;
|
|
206
|
+
callback = d;
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
offset = b | 0;
|
|
210
|
+
length = c;
|
|
211
|
+
position = d;
|
|
212
|
+
callback = e;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
if (tipb === 'function') {
|
|
217
|
+
callback = b;
|
|
218
|
+
}
|
|
219
|
+
else if (tipc === 'function') {
|
|
220
|
+
position = b;
|
|
221
|
+
callback = c;
|
|
222
|
+
}
|
|
223
|
+
else if (tipd === 'function') {
|
|
224
|
+
position = b;
|
|
225
|
+
encoding = c;
|
|
226
|
+
callback = d;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
const buf = dataToBuffer(a, encoding);
|
|
230
|
+
if (tipa !== 'string') {
|
|
231
|
+
if (typeof length === 'undefined')
|
|
232
|
+
length = buf.length;
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
offset = 0;
|
|
236
|
+
length = buf.length;
|
|
237
|
+
}
|
|
238
|
+
const cb = validateCallback(callback);
|
|
239
|
+
return [fd, tipa === 'string', buf, offset, length, position, cb];
|
|
240
|
+
};
|
|
241
|
+
exports.getWriteArgs = getWriteArgs;
|
|
242
|
+
const getWriteSyncArgs = (fd, a, b, c, d) => {
|
|
243
|
+
validateFd(fd);
|
|
244
|
+
let encoding;
|
|
245
|
+
let offset;
|
|
246
|
+
let length;
|
|
247
|
+
let position;
|
|
248
|
+
const isBuffer = typeof a !== 'string';
|
|
249
|
+
if (isBuffer) {
|
|
250
|
+
offset = (b || 0) | 0;
|
|
251
|
+
length = c;
|
|
252
|
+
position = d;
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
position = b;
|
|
256
|
+
encoding = c;
|
|
257
|
+
}
|
|
258
|
+
const buf = dataToBuffer(a, encoding);
|
|
259
|
+
if (isBuffer) {
|
|
260
|
+
if (typeof length === 'undefined') {
|
|
261
|
+
length = buf.length;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
offset = 0;
|
|
266
|
+
length = buf.length;
|
|
267
|
+
}
|
|
268
|
+
return [fd, buf, offset || 0, length, position];
|
|
269
|
+
};
|
|
270
|
+
exports.getWriteSyncArgs = getWriteSyncArgs;
|
|
271
|
+
function bufferToEncoding(buffer, encoding) {
|
|
272
|
+
if (!encoding || encoding === 'buffer')
|
|
273
|
+
return buffer;
|
|
274
|
+
else
|
|
275
|
+
return buffer.toString(encoding);
|
|
276
|
+
}
|
|
277
|
+
exports.bufferToEncoding = bufferToEncoding;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { NodeFileSystemHandle } from './NodeFileSystemHandle';
|
|
2
|
+
import type { NodeFsaContext, NodeFsaFs } from './types';
|
|
3
|
+
import type { GetDirectoryHandleOptions, GetFileHandleOptions, IFileSystemDirectoryHandle, IFileSystemFileHandle, RemoveEntryOptions } from '../fsa/types';
|
|
4
|
+
/**
|
|
5
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle
|
|
6
|
+
*/
|
|
7
|
+
export declare class NodeFileSystemDirectoryHandle extends NodeFileSystemHandle implements IFileSystemDirectoryHandle {
|
|
8
|
+
protected readonly fs: NodeFsaFs;
|
|
9
|
+
readonly __path: string;
|
|
10
|
+
protected readonly ctx: Partial<NodeFsaContext>;
|
|
11
|
+
constructor(fs: NodeFsaFs, __path: string, ctx?: Partial<NodeFsaContext>);
|
|
12
|
+
/**
|
|
13
|
+
* Returns a new array iterator containing the keys for each item in
|
|
14
|
+
* {@link NodeFileSystemDirectoryHandle} object.
|
|
15
|
+
*
|
|
16
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/keys
|
|
17
|
+
*/
|
|
18
|
+
keys(): AsyncIterableIterator<string>;
|
|
19
|
+
/**
|
|
20
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/entries
|
|
21
|
+
*/
|
|
22
|
+
entries(): AsyncIterableIterator<[string, NodeFileSystemHandle]>;
|
|
23
|
+
/**
|
|
24
|
+
* Returns a new array iterator containing the values for each index in the
|
|
25
|
+
* {@link FileSystemDirectoryHandle} object.
|
|
26
|
+
*
|
|
27
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/values
|
|
28
|
+
*/
|
|
29
|
+
values(): AsyncIterableIterator<NodeFileSystemHandle>;
|
|
30
|
+
/**
|
|
31
|
+
* Returns a {@link NodeFileSystemDirectoryHandle} for a subdirectory with the specified
|
|
32
|
+
* name within the directory handle on which the method is called.
|
|
33
|
+
*
|
|
34
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/getDirectoryHandle
|
|
35
|
+
* @param name A string representing the {@link NodeFileSystemHandle} name of
|
|
36
|
+
* the subdirectory you wish to retrieve.
|
|
37
|
+
* @param options An optional object containing options for the retrieved
|
|
38
|
+
* subdirectory.
|
|
39
|
+
*/
|
|
40
|
+
getDirectoryHandle(name: string, options?: GetDirectoryHandleOptions): Promise<IFileSystemDirectoryHandle>;
|
|
41
|
+
/**
|
|
42
|
+
* Returns a {@link FileSystemFileHandle} for a file with the specified name,
|
|
43
|
+
* within the directory the method is called.
|
|
44
|
+
*
|
|
45
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/getFileHandle
|
|
46
|
+
* @param name A string representing the {@link NodeFileSystemHandle} name of
|
|
47
|
+
* the file you wish to retrieve.
|
|
48
|
+
* @param options An optional object containing options for the retrieved file.
|
|
49
|
+
*/
|
|
50
|
+
getFileHandle(name: string, options?: GetFileHandleOptions): Promise<IFileSystemFileHandle>;
|
|
51
|
+
/**
|
|
52
|
+
* Attempts to remove an entry if the directory handle contains a file or
|
|
53
|
+
* directory called the name specified.
|
|
54
|
+
*
|
|
55
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/removeEntry
|
|
56
|
+
* @param name A string representing the {@link FileSystemHandle} name of the
|
|
57
|
+
* entry you wish to remove.
|
|
58
|
+
* @param options An optional object containing options.
|
|
59
|
+
*/
|
|
60
|
+
removeEntry(name: string, { recursive }?: RemoveEntryOptions): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* The `resolve()` method of the {@link FileSystemDirectoryHandle} interface
|
|
63
|
+
* returns an {@link Array} of directory names from the parent handle to the specified
|
|
64
|
+
* child entry, with the name of the child entry as the last array item.
|
|
65
|
+
*
|
|
66
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/resolve
|
|
67
|
+
* @param possibleDescendant The {@link NodeFileSystemFileHandle} from which
|
|
68
|
+
* to return the relative path.
|
|
69
|
+
*/
|
|
70
|
+
resolve(possibleDescendant: NodeFileSystemHandle): Promise<string[] | null>;
|
|
71
|
+
}
|