-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVirtualFile.js
More file actions
83 lines (67 loc) · 2.26 KB
/
Copy pathVirtualFile.js
File metadata and controls
83 lines (67 loc) · 2.26 KB
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
JSIL.MakeClass($jsilcore.System.Object, "VirtualFile", true, [], function ($) {
$.RawMethod(false, ".ctor", function (parent, inode) {
if (inode.type !== "file")
throw new Error("Inode is not a file");
this.parent = parent;
this.inode = inode;
Object.defineProperty(
this, "name", {
configurable: false,
get: function () {
return inode.name;
}
}
);
Object.defineProperty(
this, "type", {
get: function () {
return inode.type;
}
}
);
JSIL.SetValueProperty(
this, "path", parent.path + this.name
);
Object.defineProperty(
this.inode, "object", {
value: this,
enumerable: false,
configurable: false,
writable: false
}
);
Object.defineProperty(
this, "volume", {
get: function () {
return this.parent.volume;
},
enumerable: false,
configurable: false
}
);
if (!this.inode.metadata.created)
this.inode.metadata.created = JSIL.Host.getFileTime();
parent.files[this.name.toLowerCase()] = this;
});
$.RawMethod(false, "unlink", function () {
delete this.parent.files[this.name.toLowerCase()];
this.volume.unlinkInode(this.inode);
this.volume.deleteFileBytes(this.path);
this.volume.flush();
});
$.RawMethod(false, "readAllBytes", function () {
var bytes = this.volume.getFileBytes(this.path);
this.inode.metadata.lastRead = JSIL.Host.getFileTime();
if (!bytes)
return JSIL.Array.New(System.Byte, this.inode.metadata.length || 0);
return bytes;
});
$.RawMethod(false, "writeAllBytes", function (bytes) {
this.volume.setFileBytes(this.path, bytes);
this.inode.metadata.lastWritten = JSIL.Host.getFileTime();
this.inode.metadata.length = bytes.length;
});
$.RawMethod(false, "toString", function () {
return "<Virtual File '" + this.path + "' in volume '" + this.volume.name + "'>";
});
});