-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.js
117 lines (95 loc) · 2.73 KB
/
util.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
class EventEmitter {
constructor() {
this._events = {};
}
on(name, listener) {
if (!this._events[name]) {
this._events[name] = [];
}
this._events[name].push(listener);
}
removeListener(name, listenerToRemove) {
if (!this._events[name]) {
throw new Error(`Can't remove a listener. Event "${name}" doesn't exits.`);
}
const filterListeners = (listener) => listener !== listenerToRemove;
this._events[name] = this._events[name].filter(filterListeners);
}
emit(name, data) {
if (!this._events[name]) {
throw new Error(`Can't emit an event. Event "${name}" doesn't exits.`);
}
const fireCallbacks = (callback) => {
callback(data);
};
this._events[name].forEach(fireCallbacks);
}
}
const S_IFDIR = 0o040000; // # directory
const S_IFCHR = 0o020000; // # character device
const S_IFBLK = 0o060000; // # block device
const S_IFREG = 0o100000; // # regular file
const S_IFIFO = 0o010000; // # fifo (named pipe)
const S_IFLNK = 0o120000; // # symbolic link
const S_IFSOCK = 0o140000; // # socket file
class FileHandle {
constructor(sysfile, pos, flags, isDir) {
this.sysfile = sysfile;
this.pos = pos;
this.flags = flags;
this.isDir = isDir;
}
}
class FileStats {
constructor(jsfile) {
this.dev = 0;
this.ino = 0;
this.nlink = 0;
this.rdev = 0;
this.mode = 0o755 | S_IFREG;
this.uid = 1000;
this.gid = 1000;
this.blksize = 512;
this.size = jsfile.size;
this.blocks = Math.ceil(jsfile.size / this.blksize);
this.mtimeMs = jsfile.lastModified;
this.atimeMs = 0;
this.ctimeMs = 0;
}
isDirectory() {
return false
}
}
class DirStats {
constructor() {
this.dev = 0;
this.ino = 0;
this.mode = 0o755 | S_IFDIR;
this.nlink = 0;
this.uid = 1000;
this.gid = 1000;
this.rdev = 0;
this.size = 0;
this.blksize = 512;
this.blocks = 0;
this.mtimeMs = 0;
this.atimeMs = 0;
this.ctimeMs = 0;
}
isDirectory() {
return true
}
}
function getDirectoryEntry(expectedName) {
let db;
var request = indexedDB.open("WritableFilesDemo");
request.onerror = function(e) { console.log(e); }
request.onsuccess = function(e) { db = e.target.result; }
let file_id = "root";
let transaction = db.transaction(["filerefs"], "readwrite");
request = transaction.objectStore("filerefs").get(file_id);
request.onsuccess = function(e) {
console.orig.log(e);
// let ref = e.result;
}
}