memfs 3.5.3 → 4.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.
@@ -0,0 +1,112 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
4
+ /// <reference types="node" />
5
+ import type { PathLike, symlink } from 'fs';
6
+ import type { constants } from '../../constants';
7
+ import type { EventEmitter } from 'events';
8
+ import type { TSetTimeout } from '../../setTimeoutUnref';
9
+ import type { IAppendFileOptions, IReadFileOptions, IReadStreamOptions, IStatOptions, IWriteFileOptions, IWriteStreamOptions } from './options';
10
+ import type { Readable, Writable } from 'stream';
11
+ export { PathLike, symlink };
12
+ export type TDataOut = string | Buffer;
13
+ export type TEncodingExtended = BufferEncoding | 'buffer';
14
+ export type TFileId = PathLike | number;
15
+ export type TData = TDataOut | ArrayBufferView | DataView;
16
+ export type TFlags = string | number;
17
+ export type TMode = string | number;
18
+ export type TTime = number | string | Date;
19
+ export type TCallback<TData> = (error?: IError | null, data?: TData) => void;
20
+ export interface IError extends Error {
21
+ code?: string;
22
+ }
23
+ export type TFlagsCopy = typeof constants.COPYFILE_EXCL | typeof constants.COPYFILE_FICLONE | typeof constants.COPYFILE_FICLONE_FORCE;
24
+ export type TStatNumber = number | bigint;
25
+ export interface IStats<T = TStatNumber> {
26
+ uid: T;
27
+ gid: T;
28
+ rdev: T;
29
+ blksize: T;
30
+ ino: T;
31
+ size: T;
32
+ blocks: T;
33
+ atime: Date;
34
+ mtime: Date;
35
+ ctime: Date;
36
+ birthtime: Date;
37
+ atimeMs: T;
38
+ mtimeMs: T;
39
+ ctimeMs: T;
40
+ birthtimeMs: T;
41
+ dev: T;
42
+ mode: T;
43
+ nlink: T;
44
+ isDirectory(): boolean;
45
+ isFile(): boolean;
46
+ isBlockDevice(): boolean;
47
+ isCharacterDevice(): boolean;
48
+ isSymbolicLink(): boolean;
49
+ isFIFO(): boolean;
50
+ isSocket(): boolean;
51
+ }
52
+ export interface IDirent {
53
+ name: TDataOut;
54
+ isDirectory(): boolean;
55
+ isFile(): boolean;
56
+ isBlockDevice(): boolean;
57
+ isCharacterDevice(): boolean;
58
+ isSymbolicLink(): boolean;
59
+ isFIFO(): boolean;
60
+ isSocket(): boolean;
61
+ }
62
+ export interface IStatWatcher extends EventEmitter {
63
+ filename: string;
64
+ interval: number;
65
+ timeoutRef?: any;
66
+ setTimeout: TSetTimeout;
67
+ prev: IStats;
68
+ start(path: string, persistent?: boolean, interval?: number): void;
69
+ stop(): void;
70
+ }
71
+ export interface IReadStream extends Readable {
72
+ new (path: PathLike, options: IReadStreamOptions): any;
73
+ open(): any;
74
+ close(callback: TCallback<void>): any;
75
+ bytesRead: number;
76
+ path: string;
77
+ }
78
+ export interface IWriteStream extends Writable {
79
+ bytesWritten: number;
80
+ path: string;
81
+ new (path: PathLike, options: IWriteStreamOptions): any;
82
+ open(): any;
83
+ close(): any;
84
+ }
85
+ export interface IFSWatcher extends EventEmitter {
86
+ start(path: PathLike, persistent?: boolean, recursive?: boolean, encoding?: BufferEncoding): void;
87
+ close(): void;
88
+ }
89
+ export interface IFileHandle {
90
+ fd: number;
91
+ appendFile(data: TData, options?: IAppendFileOptions | string): Promise<void>;
92
+ chmod(mode: TMode): Promise<void>;
93
+ chown(uid: number, gid: number): Promise<void>;
94
+ close(): Promise<void>;
95
+ datasync(): Promise<void>;
96
+ read(buffer: Buffer | Uint8Array, offset: number, length: number, position: number): Promise<TFileHandleReadResult>;
97
+ readFile(options?: IReadFileOptions | string): Promise<TDataOut>;
98
+ stat(options?: IStatOptions): Promise<IStats>;
99
+ truncate(len?: number): Promise<void>;
100
+ utimes(atime: TTime, mtime: TTime): Promise<void>;
101
+ write(buffer: Buffer | ArrayBufferView | DataView, offset?: number, length?: number, position?: number): Promise<TFileHandleWriteResult>;
102
+ writeFile(data: TData, options?: IWriteFileOptions): Promise<void>;
103
+ }
104
+ export type TFileHandle = PathLike | IFileHandle;
105
+ export interface TFileHandleReadResult {
106
+ bytesRead: number;
107
+ buffer: Buffer | Uint8Array;
108
+ }
109
+ export interface TFileHandleWriteResult {
110
+ bytesWritten: number;
111
+ buffer: Buffer | Uint8Array;
112
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,72 @@
1
+ /// <reference types="node" />
2
+ import type { TEncodingExtended, TFlags, TMode } from './misc';
3
+ export interface IOptions {
4
+ encoding?: BufferEncoding | TEncodingExtended;
5
+ }
6
+ export interface IFileOptions extends IOptions {
7
+ mode?: TMode;
8
+ flag?: TFlags;
9
+ }
10
+ export interface IWriteFileOptions extends IFileOptions {
11
+ }
12
+ export interface IReadFileOptions extends IOptions {
13
+ flag?: string;
14
+ }
15
+ export interface IRealpathOptions {
16
+ encoding?: TEncodingExtended;
17
+ }
18
+ export interface IAppendFileOptions extends IFileOptions {
19
+ }
20
+ export interface IStatOptions {
21
+ bigint?: boolean;
22
+ throwIfNoEntry?: boolean;
23
+ }
24
+ export interface IFStatOptions {
25
+ bigint?: boolean;
26
+ }
27
+ export interface IAppendFileOptions extends IFileOptions {
28
+ }
29
+ export interface IReaddirOptions extends IOptions {
30
+ withFileTypes?: boolean;
31
+ }
32
+ export interface IMkdirOptions {
33
+ mode?: TMode;
34
+ recursive?: boolean;
35
+ }
36
+ export interface IRmdirOptions {
37
+ /** @deprecated */
38
+ recursive?: boolean;
39
+ maxRetries?: number;
40
+ retryDelay?: number;
41
+ }
42
+ export interface IRmOptions {
43
+ force?: boolean;
44
+ maxRetries?: number;
45
+ recursive?: boolean;
46
+ retryDelay?: number;
47
+ }
48
+ export interface IWatchFileOptions {
49
+ persistent?: boolean;
50
+ interval?: number;
51
+ }
52
+ export interface IReadStreamOptions {
53
+ flags?: TFlags;
54
+ encoding?: BufferEncoding;
55
+ fd?: number;
56
+ mode?: TMode;
57
+ autoClose?: boolean;
58
+ start?: number;
59
+ end?: number;
60
+ }
61
+ export interface IWriteStreamOptions {
62
+ flags?: TFlags;
63
+ defaultEncoding?: BufferEncoding;
64
+ fd?: number;
65
+ mode?: TMode;
66
+ autoClose?: boolean;
67
+ start?: number;
68
+ }
69
+ export interface IWatchOptions extends IOptions {
70
+ persistent?: boolean;
71
+ recursive?: boolean;
72
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,31 @@
1
+ /// <reference types="node" />
2
+ import * as misc from './misc';
3
+ import * as opts from './options';
4
+ export interface FsPromisesApi {
5
+ FileHandle: new (...args: unknown[]) => misc.IFileHandle;
6
+ access(path: misc.PathLike, mode?: number): Promise<void>;
7
+ appendFile(path: misc.TFileHandle, data: misc.TData, options?: opts.IAppendFileOptions | string): Promise<void>;
8
+ chmod(path: misc.PathLike, mode: misc.TMode): Promise<void>;
9
+ chown(path: misc.PathLike, uid: number, gid: number): Promise<void>;
10
+ copyFile(src: misc.PathLike, dest: misc.PathLike, flags?: misc.TFlagsCopy): Promise<void>;
11
+ lchmod(path: misc.PathLike, mode: misc.TMode): Promise<void>;
12
+ lchown(path: misc.PathLike, uid: number, gid: number): Promise<void>;
13
+ link(existingPath: misc.PathLike, newPath: misc.PathLike): Promise<void>;
14
+ lstat(path: misc.PathLike, options?: opts.IStatOptions): Promise<misc.IStats>;
15
+ mkdir(path: misc.PathLike, options?: misc.TMode | opts.IMkdirOptions): Promise<void>;
16
+ mkdtemp(prefix: string, options?: opts.IOptions): Promise<misc.TDataOut>;
17
+ open(path: misc.PathLike, flags: misc.TFlags, mode?: misc.TMode): Promise<misc.IFileHandle>;
18
+ readdir(path: misc.PathLike, options?: opts.IReaddirOptions | string): Promise<misc.TDataOut[] | misc.IDirent[]>;
19
+ readFile(id: misc.TFileHandle, options?: opts.IReadFileOptions | string): Promise<misc.TDataOut>;
20
+ readlink(path: misc.PathLike, options?: opts.IOptions): Promise<misc.TDataOut>;
21
+ realpath(path: misc.PathLike, options?: opts.IRealpathOptions | string): Promise<misc.TDataOut>;
22
+ rename(oldPath: misc.PathLike, newPath: misc.PathLike): Promise<void>;
23
+ rmdir(path: misc.PathLike, options?: opts.IRmdirOptions): Promise<void>;
24
+ rm(path: misc.PathLike, options?: opts.IRmOptions): Promise<void>;
25
+ stat(path: misc.PathLike, options?: opts.IStatOptions): Promise<misc.IStats>;
26
+ symlink(target: misc.PathLike, path: misc.PathLike, type?: misc.symlink.Type): Promise<void>;
27
+ truncate(path: misc.PathLike, len?: number): Promise<void>;
28
+ unlink(path: misc.PathLike): Promise<void>;
29
+ utimes(path: misc.PathLike, atime: misc.TTime, mtime: misc.TTime): Promise<void>;
30
+ writeFile(id: misc.TFileHandle, data: misc.TData, options?: opts.IWriteFileOptions): Promise<void>;
31
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,100 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import type { PathLike, symlink } from 'fs';
4
+ import type * as misc from './misc';
5
+ import type * as opts from './options';
6
+ export interface FsSynchronousApi {
7
+ openSync(path: PathLike, flags: misc.TFlags, mode?: misc.TMode): number;
8
+ closeSync(fd: number): void;
9
+ readSync(fd: number, buffer: Buffer | ArrayBufferView | DataView, offset: number, length: number, position: number): number;
10
+ readFileSync(file: misc.TFileId, options?: opts.IReadFileOptions | string): misc.TDataOut;
11
+ writeSync(fd: number, buffer: Buffer | ArrayBufferView | DataView, offset?: number, length?: number, position?: number): number;
12
+ writeSync(fd: number, str: string, position?: number, encoding?: BufferEncoding): number;
13
+ writeFileSync(id: misc.TFileId, data: misc.TData, options?: opts.IWriteFileOptions): void;
14
+ copyFileSync(src: PathLike, dest: PathLike, flags?: misc.TFlagsCopy): void;
15
+ linkSync(existingPath: PathLike, newPath: PathLike): void;
16
+ unlinkSync(path: PathLike): void;
17
+ symlinkSync(target: PathLike, path: PathLike, type?: symlink.Type): void;
18
+ realpathSync(path: PathLike, options?: opts.IRealpathOptions | string): misc.TDataOut;
19
+ lstatSync(path: PathLike): misc.IStats<number>;
20
+ lstatSync(path: PathLike, options: {
21
+ throwIfNoEntry?: true | undefined;
22
+ }): misc.IStats<number>;
23
+ lstatSync(path: PathLike, options: {
24
+ bigint: false;
25
+ throwIfNoEntry?: true | undefined;
26
+ }): misc.IStats<number>;
27
+ lstatSync(path: PathLike, options: {
28
+ bigint: true;
29
+ throwIfNoEntry?: true | undefined;
30
+ }): misc.IStats<bigint>;
31
+ lstatSync(path: PathLike, options: {
32
+ throwIfNoEntry: false;
33
+ }): misc.IStats<number> | undefined;
34
+ lstatSync(path: PathLike, options: {
35
+ bigint: false;
36
+ throwIfNoEntry: false;
37
+ }): misc.IStats<number> | undefined;
38
+ lstatSync(path: PathLike, options: {
39
+ bigint: true;
40
+ throwIfNoEntry: false;
41
+ }): misc.IStats<bigint> | undefined;
42
+ statSync(path: PathLike): misc.IStats<number>;
43
+ statSync(path: PathLike, options: {
44
+ throwIfNoEntry?: true;
45
+ }): misc.IStats<number>;
46
+ statSync(path: PathLike, options: {
47
+ throwIfNoEntry: false;
48
+ }): misc.IStats<number> | undefined;
49
+ statSync(path: PathLike, options: {
50
+ bigint: false;
51
+ throwIfNoEntry?: true;
52
+ }): misc.IStats<number>;
53
+ statSync(path: PathLike, options: {
54
+ bigint: true;
55
+ throwIfNoEntry?: true;
56
+ }): misc.IStats<bigint>;
57
+ statSync(path: PathLike, options: {
58
+ bigint: false;
59
+ throwIfNoEntry: false;
60
+ }): misc.IStats<number> | undefined;
61
+ statSync(path: PathLike, options: {
62
+ bigint: true;
63
+ throwIfNoEntry: false;
64
+ }): misc.IStats<bigint> | undefined;
65
+ fstatSync(fd: number): misc.IStats<number>;
66
+ fstatSync(fd: number, options: {
67
+ bigint: false;
68
+ }): misc.IStats<number>;
69
+ fstatSync(fd: number, options: {
70
+ bigint: true;
71
+ }): misc.IStats<bigint>;
72
+ renameSync(oldPath: PathLike, newPath: PathLike): void;
73
+ existsSync(path: PathLike): boolean;
74
+ accessSync(path: PathLike, mode?: number): void;
75
+ appendFileSync(id: misc.TFileId, data: misc.TData, options?: opts.IAppendFileOptions | string): void;
76
+ readdirSync(path: PathLike, options?: opts.IReaddirOptions | string): misc.TDataOut[] | misc.IDirent[];
77
+ readlinkSync(path: PathLike, options?: opts.IOptions): misc.TDataOut;
78
+ fdatasyncSync(fd: number): void;
79
+ ftruncateSync(fd: number, len?: number): void;
80
+ truncateSync(id: misc.TFileId, len?: number): void;
81
+ futimesSync(fd: number, atime: misc.TTime, mtime: misc.TTime): void;
82
+ utimesSync(path: PathLike, atime: misc.TTime, mtime: misc.TTime): void;
83
+ mkdirSync(path: PathLike, options: opts.IMkdirOptions & {
84
+ recursive: true;
85
+ }): string | undefined;
86
+ mkdirSync(path: PathLike, options?: misc.TMode | (opts.IMkdirOptions & {
87
+ recursive?: false;
88
+ })): void;
89
+ mkdirSync(path: PathLike, options?: misc.TMode | opts.IMkdirOptions): string | undefined;
90
+ mkdirpSync(path: PathLike, mode?: misc.TMode): void;
91
+ mkdtempSync(prefix: string, options?: opts.IOptions): misc.TDataOut;
92
+ rmdirSync(path: PathLike, options?: opts.IRmdirOptions): void;
93
+ rmSync(path: PathLike, options?: opts.IRmOptions): void;
94
+ fchmodSync(fd: number, mode: misc.TMode): void;
95
+ chmodSync(path: PathLike, mode: misc.TMode): void;
96
+ lchmodSync(path: PathLike, mode: misc.TMode): void;
97
+ fchownSync(fd: number, uid: number, gid: number): void;
98
+ chownSync(path: PathLike, uid: number, gid: number): void;
99
+ lchownSync(path: PathLike, uid: number, gid: number): void;
100
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ import type { FsCallbackApi } from './types';
2
+ export declare function promisify(fs: FsCallbackApi, fn: string, getResult?: (result: any) => any): (...args: any[]) => Promise<any>;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.promisify = void 0;
4
+ function promisify(fs, fn, getResult = input => input) {
5
+ return (...args) => new Promise((resolve, reject) => {
6
+ fs[fn].bind(fs)(...args, (error, result) => {
7
+ if (error)
8
+ return reject(error);
9
+ return resolve(getResult(result));
10
+ });
11
+ });
12
+ }
13
+ exports.promisify = promisify;
package/lib/node.d.ts CHANGED
@@ -48,7 +48,7 @@ export declare class Node extends EventEmitter {
48
48
  isSymlink(): boolean;
49
49
  makeSymlink(steps: string[]): void;
50
50
  write(buf: Buffer, off?: number, len?: number, pos?: number): number;
51
- read(buf: Buffer | Uint8Array, off?: number, len?: number, pos?: number): number;
51
+ read(buf: Buffer | ArrayBufferView | DataView, off?: number, len?: number, pos?: number): number;
52
52
  truncate(len?: number): void;
53
53
  chmod(perm: number): void;
54
54
  chown(uid: number, gid: number): void;
@@ -150,7 +150,7 @@ export declare class File {
150
150
  seekTo(position: number): void;
151
151
  stats(): Stats<number>;
152
152
  write(buf: Buffer, offset?: number, length?: number, position?: number): number;
153
- read(buf: Buffer | Uint8Array, offset?: number, length?: number, position?: number): number;
153
+ read(buf: Buffer | ArrayBufferView | DataView, offset?: number, length?: number, position?: number): number;
154
154
  chmod(perm: number): void;
155
155
  chown(uid: number, gid: number): void;
156
156
  }