@zenfs/dom 0.0.1 → 0.0.2
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/HTTPRequest.js +6 -6
- package/dist/browser.min.js +2 -2
- package/dist/browser.min.js.map +4 -4
- package/package.json +2 -2
- package/readme.md +3 -3
- package/dist/file_index.d.ts +0 -154
- package/dist/file_index.js +0 -342
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zenfs/dom",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "DOM backends for ZenFS",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist",
|
|
@@ -55,6 +55,6 @@
|
|
|
55
55
|
"typescript": "5.2.2"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@zenfs/core": "^0.0.
|
|
58
|
+
"@zenfs/core": "^0.0.6"
|
|
59
59
|
}
|
|
60
60
|
}
|
package/readme.md
CHANGED
|
@@ -33,11 +33,11 @@ npm install @zenfs/fs-dom
|
|
|
33
33
|
You can use DOM backends, though you must register them if you plan on using `configure`:
|
|
34
34
|
|
|
35
35
|
```js
|
|
36
|
-
import { configure, fs } from '@zenfs/core';
|
|
36
|
+
import { configure, fs, registerBackend } from '@zenfs/core';
|
|
37
37
|
import { Storage } '@zenfs/fs-dom';
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
await configure({ fs: 'Storage' });
|
|
39
|
+
registerBackend(Storage);
|
|
40
|
+
await configure({ fs: 'Storage', options: { storage: localStorage } });
|
|
41
41
|
|
|
42
42
|
if (!fs.existsSync('/test.txt')) {
|
|
43
43
|
fs.writeFileSync('/test.txt', 'This will persist across reloads!');
|
package/dist/file_index.d.ts
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import { Stats } from '@zenfs/core/stats.js';
|
|
2
|
-
/**
|
|
3
|
-
* A simple class for storing a filesystem index. Assumes that all paths passed
|
|
4
|
-
* to it are *absolute* paths.
|
|
5
|
-
*
|
|
6
|
-
* Can be used as a partial or a full index, although care must be taken if used
|
|
7
|
-
* for the former purpose, especially when directories are concerned.
|
|
8
|
-
*/
|
|
9
|
-
export declare class FileIndex<T> {
|
|
10
|
-
/**
|
|
11
|
-
* Static method for constructing indices from a JSON listing.
|
|
12
|
-
* @param listing Directory listing generated by tools/XHRIndexer.coffee
|
|
13
|
-
* @return A new FileIndex object.
|
|
14
|
-
*/
|
|
15
|
-
static fromListing<T>(listing: any): FileIndex<T>;
|
|
16
|
-
private _index;
|
|
17
|
-
/**
|
|
18
|
-
* Constructs a new FileIndex.
|
|
19
|
-
*/
|
|
20
|
-
constructor();
|
|
21
|
-
/**
|
|
22
|
-
* Runs the given function over all files in the index.
|
|
23
|
-
*/
|
|
24
|
-
fileIterator<T>(cb: (file: T | null) => void): void;
|
|
25
|
-
/**
|
|
26
|
-
* Adds the given absolute path to the index if it is not already in the index.
|
|
27
|
-
* Creates any needed parent directories.
|
|
28
|
-
* @param path The path to add to the index.
|
|
29
|
-
* @param inode The inode for the
|
|
30
|
-
* path to add.
|
|
31
|
-
* @return 'True' if it was added or already exists, 'false' if there
|
|
32
|
-
* was an issue adding it (e.g. item in path is a file, item exists but is
|
|
33
|
-
* different).
|
|
34
|
-
* @todo If adding fails and implicitly creates directories, we do not clean up
|
|
35
|
-
* the new empty directories.
|
|
36
|
-
*/
|
|
37
|
-
addPath(path: string, inode: Inode): boolean;
|
|
38
|
-
/**
|
|
39
|
-
* Adds the given absolute path to the index if it is not already in the index.
|
|
40
|
-
* The path is added without special treatment (no joining of adjacent separators, etc).
|
|
41
|
-
* Creates any needed parent directories.
|
|
42
|
-
* @param path The path to add to the index.
|
|
43
|
-
* @param inode The inode for the
|
|
44
|
-
* path to add.
|
|
45
|
-
* @return 'True' if it was added or already exists, 'false' if there
|
|
46
|
-
* was an issue adding it (e.g. item in path is a file, item exists but is
|
|
47
|
-
* different).
|
|
48
|
-
* @todo If adding fails and implicitly creates directories, we do not clean up
|
|
49
|
-
* the new empty directories.
|
|
50
|
-
*/
|
|
51
|
-
addPathFast(path: string, inode: Inode): boolean;
|
|
52
|
-
/**
|
|
53
|
-
* Removes the given path. Can be a file or a directory.
|
|
54
|
-
* @return The removed item,
|
|
55
|
-
* or null if it did not exist.
|
|
56
|
-
*/
|
|
57
|
-
removePath(path: string): Inode | null;
|
|
58
|
-
/**
|
|
59
|
-
* Retrieves the directory listing of the given path.
|
|
60
|
-
* @return An array of files in the given path, or 'null' if it does not exist.
|
|
61
|
-
*/
|
|
62
|
-
ls(path: string): string[] | null;
|
|
63
|
-
/**
|
|
64
|
-
* Returns the inode of the given item.
|
|
65
|
-
* @return Returns null if the item does not exist.
|
|
66
|
-
*/
|
|
67
|
-
getInode(path: string): Inode | null;
|
|
68
|
-
/**
|
|
69
|
-
* Split into a (directory path, item name) pair
|
|
70
|
-
*/
|
|
71
|
-
private _split_path;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Generic interface for file/directory inodes.
|
|
75
|
-
* Note that Stats objects are what we use for file inodes.
|
|
76
|
-
*/
|
|
77
|
-
export interface Inode {
|
|
78
|
-
isFile(): boolean;
|
|
79
|
-
isDir(): boolean;
|
|
80
|
-
toStats(): Stats;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Inode for a file. Stores an arbitrary (filesystem-specific) data payload.
|
|
84
|
-
*/
|
|
85
|
-
export declare class FileInode<T> implements Inode {
|
|
86
|
-
private data;
|
|
87
|
-
constructor(data: T);
|
|
88
|
-
isFile(): boolean;
|
|
89
|
-
isDir(): boolean;
|
|
90
|
-
getData(): T;
|
|
91
|
-
setData(data: T): void;
|
|
92
|
-
toStats(): Stats;
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Inode for a directory. Currently only contains the directory listing.
|
|
96
|
-
*/
|
|
97
|
-
export declare class DirInode<T> implements Inode {
|
|
98
|
-
private data;
|
|
99
|
-
private _ls;
|
|
100
|
-
/**
|
|
101
|
-
* Constructs an inode for a directory.
|
|
102
|
-
*/
|
|
103
|
-
constructor(data?: T | null);
|
|
104
|
-
isFile(): boolean;
|
|
105
|
-
isDir(): boolean;
|
|
106
|
-
getData(): T | null;
|
|
107
|
-
/**
|
|
108
|
-
* Return a Stats object for this inode.
|
|
109
|
-
* @todo Should probably remove this at some point. This isn't the
|
|
110
|
-
* responsibility of the FileIndex.
|
|
111
|
-
*/
|
|
112
|
-
getStats(): Stats;
|
|
113
|
-
/**
|
|
114
|
-
* Alias of getStats()
|
|
115
|
-
* @todo Remove this at some point. This isn't the
|
|
116
|
-
* responsibility of the FileIndex.
|
|
117
|
-
*/
|
|
118
|
-
toStats(): Stats;
|
|
119
|
-
/**
|
|
120
|
-
* Returns the directory listing for this directory. Paths in the directory are
|
|
121
|
-
* relative to the directory's path.
|
|
122
|
-
* @return The directory listing for this directory.
|
|
123
|
-
*/
|
|
124
|
-
getListing(): string[];
|
|
125
|
-
/**
|
|
126
|
-
* Returns the inode for the indicated item, or null if it does not exist.
|
|
127
|
-
* @param p Name of item in this directory.
|
|
128
|
-
*/
|
|
129
|
-
getItem(p: string): Inode | null;
|
|
130
|
-
/**
|
|
131
|
-
* Add the given item to the directory listing. Note that the given inode is
|
|
132
|
-
* not copied, and will be mutated by the DirInode if it is a DirInode.
|
|
133
|
-
* @param p Item name to add to the directory listing.
|
|
134
|
-
* @param inode The inode for the
|
|
135
|
-
* item to add to the directory inode.
|
|
136
|
-
* @return True if it was added, false if it already existed.
|
|
137
|
-
*/
|
|
138
|
-
addItem(p: string, inode: Inode): boolean;
|
|
139
|
-
/**
|
|
140
|
-
* Removes the given item from the directory listing.
|
|
141
|
-
* @param p Name of item to remove from the directory listing.
|
|
142
|
-
* @return Returns the item
|
|
143
|
-
* removed, or null if the item did not exist.
|
|
144
|
-
*/
|
|
145
|
-
remItem(p: string): Inode | null;
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* @hidden
|
|
149
|
-
*/
|
|
150
|
-
export declare function isFileInode<T>(inode: Inode | null): inode is FileInode<T>;
|
|
151
|
-
/**
|
|
152
|
-
* @hidden
|
|
153
|
-
*/
|
|
154
|
-
export declare function isDirInode<T>(inode: Inode | null): inode is DirInode<T>;
|
package/dist/file_index.js
DELETED
|
@@ -1,342 +0,0 @@
|
|
|
1
|
-
import { Stats, FileType } from '@zenfs/core/stats.js';
|
|
2
|
-
import * as path from 'path';
|
|
3
|
-
/**
|
|
4
|
-
* A simple class for storing a filesystem index. Assumes that all paths passed
|
|
5
|
-
* to it are *absolute* paths.
|
|
6
|
-
*
|
|
7
|
-
* Can be used as a partial or a full index, although care must be taken if used
|
|
8
|
-
* for the former purpose, especially when directories are concerned.
|
|
9
|
-
*/
|
|
10
|
-
export class FileIndex {
|
|
11
|
-
/**
|
|
12
|
-
* Static method for constructing indices from a JSON listing.
|
|
13
|
-
* @param listing Directory listing generated by tools/XHRIndexer.coffee
|
|
14
|
-
* @return A new FileIndex object.
|
|
15
|
-
*/
|
|
16
|
-
static fromListing(listing) {
|
|
17
|
-
const idx = new FileIndex();
|
|
18
|
-
// Add a root DirNode.
|
|
19
|
-
const rootInode = new DirInode();
|
|
20
|
-
idx._index['/'] = rootInode;
|
|
21
|
-
const queue = [['', listing, rootInode]];
|
|
22
|
-
while (queue.length > 0) {
|
|
23
|
-
let inode;
|
|
24
|
-
const next = queue.pop();
|
|
25
|
-
const pwd = next[0];
|
|
26
|
-
const tree = next[1];
|
|
27
|
-
const parent = next[2];
|
|
28
|
-
for (const node in tree) {
|
|
29
|
-
if (Object.prototype.hasOwnProperty.call(tree, node)) {
|
|
30
|
-
const children = tree[node];
|
|
31
|
-
const name = `${pwd}/${node}`;
|
|
32
|
-
if (children) {
|
|
33
|
-
idx._index[name] = inode = new DirInode();
|
|
34
|
-
queue.push([name, children, inode]);
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
// This inode doesn't have correct size information, noted with -1.
|
|
38
|
-
inode = new FileInode(new Stats(FileType.FILE, -1, 0x16d));
|
|
39
|
-
}
|
|
40
|
-
if (parent) {
|
|
41
|
-
parent._ls[node] = inode;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return idx;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Constructs a new FileIndex.
|
|
50
|
-
*/
|
|
51
|
-
constructor() {
|
|
52
|
-
// _index is a single-level key,value store that maps *directory* paths to
|
|
53
|
-
// DirInodes. File information is only contained in DirInodes themselves.
|
|
54
|
-
this._index = {};
|
|
55
|
-
// Create the root directory.
|
|
56
|
-
this.addPath('/', new DirInode());
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Runs the given function over all files in the index.
|
|
60
|
-
*/
|
|
61
|
-
fileIterator(cb) {
|
|
62
|
-
for (const path in this._index) {
|
|
63
|
-
if (Object.prototype.hasOwnProperty.call(this._index, path)) {
|
|
64
|
-
const dir = this._index[path];
|
|
65
|
-
const files = dir.getListing();
|
|
66
|
-
for (const file of files) {
|
|
67
|
-
const item = dir.getItem(file);
|
|
68
|
-
if (isFileInode(item)) {
|
|
69
|
-
cb(item.getData());
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Adds the given absolute path to the index if it is not already in the index.
|
|
77
|
-
* Creates any needed parent directories.
|
|
78
|
-
* @param path The path to add to the index.
|
|
79
|
-
* @param inode The inode for the
|
|
80
|
-
* path to add.
|
|
81
|
-
* @return 'True' if it was added or already exists, 'false' if there
|
|
82
|
-
* was an issue adding it (e.g. item in path is a file, item exists but is
|
|
83
|
-
* different).
|
|
84
|
-
* @todo If adding fails and implicitly creates directories, we do not clean up
|
|
85
|
-
* the new empty directories.
|
|
86
|
-
*/
|
|
87
|
-
addPath(path, inode) {
|
|
88
|
-
if (!inode) {
|
|
89
|
-
throw new Error('Inode must be specified');
|
|
90
|
-
}
|
|
91
|
-
if (path[0] !== '/') {
|
|
92
|
-
throw new Error('Path must be absolute, got: ' + path);
|
|
93
|
-
}
|
|
94
|
-
// Check if it already exists.
|
|
95
|
-
if (Object.prototype.hasOwnProperty.call(this._index, path)) {
|
|
96
|
-
return this._index[path] === inode;
|
|
97
|
-
}
|
|
98
|
-
const splitPath = this._split_path(path);
|
|
99
|
-
const dirpath = splitPath[0];
|
|
100
|
-
const itemname = splitPath[1];
|
|
101
|
-
// Try to add to its parent directory first.
|
|
102
|
-
let parent = this._index[dirpath];
|
|
103
|
-
if (parent === undefined && path !== '/') {
|
|
104
|
-
// Create parent.
|
|
105
|
-
parent = new DirInode();
|
|
106
|
-
if (!this.addPath(dirpath, parent)) {
|
|
107
|
-
return false;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
// Add myself to my parent.
|
|
111
|
-
if (path !== '/') {
|
|
112
|
-
if (!parent.addItem(itemname, inode)) {
|
|
113
|
-
return false;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
// If I'm a directory, add myself to the index.
|
|
117
|
-
if (isDirInode(inode)) {
|
|
118
|
-
this._index[path] = inode;
|
|
119
|
-
}
|
|
120
|
-
return true;
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Adds the given absolute path to the index if it is not already in the index.
|
|
124
|
-
* The path is added without special treatment (no joining of adjacent separators, etc).
|
|
125
|
-
* Creates any needed parent directories.
|
|
126
|
-
* @param path The path to add to the index.
|
|
127
|
-
* @param inode The inode for the
|
|
128
|
-
* path to add.
|
|
129
|
-
* @return 'True' if it was added or already exists, 'false' if there
|
|
130
|
-
* was an issue adding it (e.g. item in path is a file, item exists but is
|
|
131
|
-
* different).
|
|
132
|
-
* @todo If adding fails and implicitly creates directories, we do not clean up
|
|
133
|
-
* the new empty directories.
|
|
134
|
-
*/
|
|
135
|
-
addPathFast(path, inode) {
|
|
136
|
-
const itemNameMark = path.lastIndexOf('/');
|
|
137
|
-
const parentPath = itemNameMark === 0 ? '/' : path.substring(0, itemNameMark);
|
|
138
|
-
const itemName = path.substring(itemNameMark + 1);
|
|
139
|
-
// Try to add to its parent directory first.
|
|
140
|
-
let parent = this._index[parentPath];
|
|
141
|
-
if (parent === undefined) {
|
|
142
|
-
// Create parent.
|
|
143
|
-
parent = new DirInode();
|
|
144
|
-
this.addPathFast(parentPath, parent);
|
|
145
|
-
}
|
|
146
|
-
if (!parent.addItem(itemName, inode)) {
|
|
147
|
-
return false;
|
|
148
|
-
}
|
|
149
|
-
// If adding a directory, add to the index as well.
|
|
150
|
-
if (inode.isDir()) {
|
|
151
|
-
this._index[path] = inode;
|
|
152
|
-
}
|
|
153
|
-
return true;
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Removes the given path. Can be a file or a directory.
|
|
157
|
-
* @return The removed item,
|
|
158
|
-
* or null if it did not exist.
|
|
159
|
-
*/
|
|
160
|
-
removePath(path) {
|
|
161
|
-
const splitPath = this._split_path(path);
|
|
162
|
-
const dirpath = splitPath[0];
|
|
163
|
-
const itemname = splitPath[1];
|
|
164
|
-
// Try to remove it from its parent directory first.
|
|
165
|
-
const parent = this._index[dirpath];
|
|
166
|
-
if (parent === undefined) {
|
|
167
|
-
return null;
|
|
168
|
-
}
|
|
169
|
-
// Remove myself from my parent.
|
|
170
|
-
const inode = parent.remItem(itemname);
|
|
171
|
-
if (inode === null) {
|
|
172
|
-
return null;
|
|
173
|
-
}
|
|
174
|
-
// If I'm a directory, remove myself from the index, and remove my children.
|
|
175
|
-
if (isDirInode(inode)) {
|
|
176
|
-
const children = inode.getListing();
|
|
177
|
-
for (const child of children) {
|
|
178
|
-
this.removePath(path + '/' + child);
|
|
179
|
-
}
|
|
180
|
-
// Remove the directory from the index, unless it's the root.
|
|
181
|
-
if (path !== '/') {
|
|
182
|
-
delete this._index[path];
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
return inode;
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Retrieves the directory listing of the given path.
|
|
189
|
-
* @return An array of files in the given path, or 'null' if it does not exist.
|
|
190
|
-
*/
|
|
191
|
-
ls(path) {
|
|
192
|
-
const item = this._index[path];
|
|
193
|
-
if (item === undefined) {
|
|
194
|
-
return null;
|
|
195
|
-
}
|
|
196
|
-
return item.getListing();
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Returns the inode of the given item.
|
|
200
|
-
* @return Returns null if the item does not exist.
|
|
201
|
-
*/
|
|
202
|
-
getInode(path) {
|
|
203
|
-
const splitPath = this._split_path(path);
|
|
204
|
-
const dirpath = splitPath[0];
|
|
205
|
-
const itemname = splitPath[1];
|
|
206
|
-
// Retrieve from its parent directory.
|
|
207
|
-
const parent = this._index[dirpath];
|
|
208
|
-
if (parent === undefined) {
|
|
209
|
-
return null;
|
|
210
|
-
}
|
|
211
|
-
// Root case
|
|
212
|
-
if (dirpath === path) {
|
|
213
|
-
return parent;
|
|
214
|
-
}
|
|
215
|
-
return parent.getItem(itemname);
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Split into a (directory path, item name) pair
|
|
219
|
-
*/
|
|
220
|
-
_split_path(p) {
|
|
221
|
-
const dirpath = path.dirname(p);
|
|
222
|
-
const itemname = p.substr(dirpath.length + (dirpath === '/' ? 0 : 1));
|
|
223
|
-
return [dirpath, itemname];
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* Inode for a file. Stores an arbitrary (filesystem-specific) data payload.
|
|
228
|
-
*/
|
|
229
|
-
export class FileInode {
|
|
230
|
-
constructor(data) {
|
|
231
|
-
this.data = data;
|
|
232
|
-
}
|
|
233
|
-
isFile() {
|
|
234
|
-
return true;
|
|
235
|
-
}
|
|
236
|
-
isDir() {
|
|
237
|
-
return false;
|
|
238
|
-
}
|
|
239
|
-
getData() {
|
|
240
|
-
return this.data;
|
|
241
|
-
}
|
|
242
|
-
setData(data) {
|
|
243
|
-
this.data = data;
|
|
244
|
-
}
|
|
245
|
-
toStats() {
|
|
246
|
-
return new Stats(FileType.FILE, 4096, 0o666);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
/**
|
|
250
|
-
* Inode for a directory. Currently only contains the directory listing.
|
|
251
|
-
*/
|
|
252
|
-
export class DirInode {
|
|
253
|
-
/**
|
|
254
|
-
* Constructs an inode for a directory.
|
|
255
|
-
*/
|
|
256
|
-
constructor(data = null) {
|
|
257
|
-
this.data = data;
|
|
258
|
-
this._ls = {};
|
|
259
|
-
}
|
|
260
|
-
isFile() {
|
|
261
|
-
return false;
|
|
262
|
-
}
|
|
263
|
-
isDir() {
|
|
264
|
-
return true;
|
|
265
|
-
}
|
|
266
|
-
getData() {
|
|
267
|
-
return this.data;
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* Return a Stats object for this inode.
|
|
271
|
-
* @todo Should probably remove this at some point. This isn't the
|
|
272
|
-
* responsibility of the FileIndex.
|
|
273
|
-
*/
|
|
274
|
-
getStats() {
|
|
275
|
-
return new Stats(FileType.DIRECTORY, 4096, 0o555);
|
|
276
|
-
}
|
|
277
|
-
/**
|
|
278
|
-
* Alias of getStats()
|
|
279
|
-
* @todo Remove this at some point. This isn't the
|
|
280
|
-
* responsibility of the FileIndex.
|
|
281
|
-
*/
|
|
282
|
-
toStats() {
|
|
283
|
-
return this.getStats();
|
|
284
|
-
}
|
|
285
|
-
/**
|
|
286
|
-
* Returns the directory listing for this directory. Paths in the directory are
|
|
287
|
-
* relative to the directory's path.
|
|
288
|
-
* @return The directory listing for this directory.
|
|
289
|
-
*/
|
|
290
|
-
getListing() {
|
|
291
|
-
return Object.keys(this._ls);
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* Returns the inode for the indicated item, or null if it does not exist.
|
|
295
|
-
* @param p Name of item in this directory.
|
|
296
|
-
*/
|
|
297
|
-
getItem(p) {
|
|
298
|
-
const item = this._ls[p];
|
|
299
|
-
return item ? item : null;
|
|
300
|
-
}
|
|
301
|
-
/**
|
|
302
|
-
* Add the given item to the directory listing. Note that the given inode is
|
|
303
|
-
* not copied, and will be mutated by the DirInode if it is a DirInode.
|
|
304
|
-
* @param p Item name to add to the directory listing.
|
|
305
|
-
* @param inode The inode for the
|
|
306
|
-
* item to add to the directory inode.
|
|
307
|
-
* @return True if it was added, false if it already existed.
|
|
308
|
-
*/
|
|
309
|
-
addItem(p, inode) {
|
|
310
|
-
if (p in this._ls) {
|
|
311
|
-
return false;
|
|
312
|
-
}
|
|
313
|
-
this._ls[p] = inode;
|
|
314
|
-
return true;
|
|
315
|
-
}
|
|
316
|
-
/**
|
|
317
|
-
* Removes the given item from the directory listing.
|
|
318
|
-
* @param p Name of item to remove from the directory listing.
|
|
319
|
-
* @return Returns the item
|
|
320
|
-
* removed, or null if the item did not exist.
|
|
321
|
-
*/
|
|
322
|
-
remItem(p) {
|
|
323
|
-
const item = this._ls[p];
|
|
324
|
-
if (item === undefined) {
|
|
325
|
-
return null;
|
|
326
|
-
}
|
|
327
|
-
delete this._ls[p];
|
|
328
|
-
return item;
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
/**
|
|
332
|
-
* @hidden
|
|
333
|
-
*/
|
|
334
|
-
export function isFileInode(inode) {
|
|
335
|
-
return !!inode && inode.isFile();
|
|
336
|
-
}
|
|
337
|
-
/**
|
|
338
|
-
* @hidden
|
|
339
|
-
*/
|
|
340
|
-
export function isDirInode(inode) {
|
|
341
|
-
return !!inode && inode.isDir();
|
|
342
|
-
}
|