UNPKG

4.51 kBTypeScriptView Raw
1/// <reference types="node" />
2/// <reference types="node" />
3import { Volume } from './volume';
4import { EventEmitter } from 'events';
5import Stats from './Stats';
6export declare const SEP = "/";
7/**
8 * Node in a file system (like i-node, v-node).
9 */
10export declare class Node extends EventEmitter {
11 ino: number;
12 private _uid;
13 private _gid;
14 private _atime;
15 private _mtime;
16 private _ctime;
17 buf: Buffer;
18 private _perm;
19 mode: number;
20 private _nlink;
21 symlink: string[];
22 constructor(ino: number, perm?: number);
23 set ctime(ctime: Date);
24 get ctime(): Date;
25 set uid(uid: number);
26 get uid(): number;
27 set gid(gid: number);
28 get gid(): number;
29 set atime(atime: Date);
30 get atime(): Date;
31 set mtime(mtime: Date);
32 get mtime(): Date;
33 set perm(perm: number);
34 get perm(): number;
35 set nlink(nlink: number);
36 get nlink(): number;
37 getString(encoding?: string): string;
38 setString(str: string): void;
39 getBuffer(): Buffer;
40 setBuffer(buf: Buffer): void;
41 getSize(): number;
42 setModeProperty(property: number): void;
43 setIsFile(): void;
44 setIsDirectory(): void;
45 setIsSymlink(): void;
46 isFile(): boolean;
47 isDirectory(): boolean;
48 isSymlink(): boolean;
49 makeSymlink(steps: string[]): void;
50 write(buf: Buffer, off?: number, len?: number, pos?: number): number;
51 read(buf: Buffer | ArrayBufferView | DataView, off?: number, len?: number, pos?: number): number;
52 truncate(len?: number): void;
53 chmod(perm: number): void;
54 chown(uid: number, gid: number): void;
55 touch(): void;
56 canRead(uid?: number, gid?: number): boolean;
57 canWrite(uid?: number, gid?: number): boolean;
58 del(): void;
59 toJSON(): {
60 ino: number;
61 uid: number;
62 gid: number;
63 atime: number;
64 mtime: number;
65 ctime: number;
66 perm: number;
67 mode: number;
68 nlink: number;
69 symlink: string[];
70 data: string;
71 };
72}
73/**
74 * Represents a hard link that points to an i-node `node`.
75 */
76export declare class Link extends EventEmitter {
77 vol: Volume;
78 parent: Link;
79 children: Map<string, Link | undefined>;
80 private _steps;
81 node: Node;
82 ino: number;
83 length: number;
84 name: string;
85 get steps(): string[];
86 set steps(val: string[]);
87 constructor(vol: Volume, parent: Link, name: string);
88 setNode(node: Node): void;
89 getNode(): Node;
90 createChild(name: string, node?: Node): Link;
91 setChild(name: string, link?: Link): Link;
92 deleteChild(link: Link): void;
93 getChild(name: string): Link | undefined;
94 getPath(): string;
95 getName(): string;
96 /**
97 * Walk the tree path and return the `Link` at that location, if any.
98 * @param steps {string[]} Desired location.
99 * @param stop {number} Max steps to go into.
100 * @param i {number} Current step in the `steps` array.
101 *
102 * @return {Link|null}
103 */
104 walk(steps: string[], stop?: number, i?: number): Link | null;
105 toJSON(): {
106 steps: string[];
107 ino: number;
108 children: string[];
109 };
110 syncSteps(): void;
111}
112/**
113 * Represents an open file (file descriptor) that points to a `Link` (Hard-link) and a `Node`.
114 */
115export declare class File {
116 fd: number;
117 /**
118 * Hard link that this file opened.
119 * @type {any}
120 */
121 link: Link;
122 /**
123 * Reference to a `Node`.
124 * @type {Node}
125 */
126 node: Node;
127 /**
128 * A cursor/offset position in a file, where data will be written on write.
129 * User can "seek" this position.
130 */
131 position: number;
132 flags: number;
133 /**
134 * Open a Link-Node pair. `node` is provided separately as that might be a different node
135 * rather the one `link` points to, because it might be a symlink.
136 * @param link
137 * @param node
138 * @param flags
139 * @param fd
140 */
141 constructor(link: Link, node: Node, flags: number, fd: number);
142 getString(encoding?: string): string;
143 setString(str: string): void;
144 getBuffer(): Buffer;
145 setBuffer(buf: Buffer): void;
146 getSize(): number;
147 truncate(len?: number): void;
148 seekTo(position: number): void;
149 stats(): Stats<number>;
150 write(buf: Buffer, offset?: number, length?: number, position?: number | null): number;
151 read(buf: Buffer | ArrayBufferView | DataView, offset?: number, length?: number, position?: number): number;
152 chmod(perm: number): void;
153 chown(uid: number, gid: number): void;
154}