-
-
Notifications
You must be signed in to change notification settings - Fork 205
Expand file tree
/
Copy pathFileSystemStats.js
More file actions
158 lines (140 loc) · 4.48 KB
/
Copy pathFileSystemStats.js
File metadata and controls
158 lines (140 loc) · 4.48 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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
* GNU AGPL-3.0 License
*
* Copyright (c) 2021 - present core.ai . All rights reserved.
* Original work Copyright (c) 2013 - 2021 Adobe Systems Incorporated. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
* for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://opensource.org/licenses/AGPL-3.0.
*
*/
// @INCLUDE_IN_API_DOCS
define(function (require, exports, module) {
/**
* The FileSystemStats represents a particular FileSystemEntry's stats.
* @constructor
* @param {{isFile: boolean, mtime: Date, size: Number, realPath: ?string, hash: object}} options
*/
function FileSystemStats(options) {
var isFile = options.isFile;
this._isFile = isFile;
this._isDirectory = !isFile;
// in case of stats transferred over a node-domain,
// mtime will have JSON-ified value which needs to be restored
this._mtime = options.mtime instanceof Date ? options.mtime : new Date(options.mtime);
this._size = options.size;
// hash is a property introduced by brackets and it's calculated
// as a valueOf modification time -> calculate here if it's not present
this._hash = options.hash || this._mtime.valueOf();
var realPath = options.realPath;
if (realPath) {
if (!isFile && realPath[realPath.length - 1] !== "/") {
realPath += "/";
}
this._realPath = realPath;
}
}
// Add "isFile", "isDirectory", "mtime" and "size" getters
Object.defineProperties(FileSystemStats.prototype, {
/**
* Whether or not this is a stats object for a file
*
* @type {boolean}
*/
"isFile": {
get: function () { return this._isFile; },
set: function () { throw new Error("Cannot set isFile"); }
},
/**
* Whether or not this is a stats object for a directory
*
* @type {boolean}
*/
"isDirectory": {
get: function () { return this._isDirectory; },
set: function () { throw new Error("Cannot set isDirectory"); }
},
/**
* Modification time for a file
*
* @type {Date}
*/
"mtime": {
get: function () { return this._mtime; },
set: function () { throw new Error("Cannot set mtime"); }
},
/**
* Size in bytes of a file
*
* @type {Number}
*/
"size": {
get: function () { return this._size; },
set: function () { throw new Error("Cannot set size"); }
},
/**
* The canonical path of this file or directory ONLY if it is a symbolic link,
* and null otherwise.
*
* @type {?string}
*/
"realPath": {
get: function () { return this._realPath; },
set: function () { throw new Error("Cannot set realPath"); }
}
});
/**
* Whether or not this is a stats object for a file
*
* @private
* @type {boolean}
*/
FileSystemStats.prototype._isFile = false;
/**
* Whether or not this is a stats object for a directory
*
* @private
* @type {boolean}
*/
FileSystemStats.prototype._isDirectory = false;
/**
* Modification time for a file
*
* @private
* @type {Date}
*/
FileSystemStats.prototype._mtime = null;
/**
* Size in bytes of a file
*
* @private
* @type {Number}
*/
FileSystemStats.prototype._size = null;
/**
* Consistency hash for a file
*
* @private
* @type {object}
*/
FileSystemStats.prototype._hash = null;
/**
* The canonical path of this file or directory ONLY if it is a symbolic link,
* and null otherwise.
*
* @private
* @type {?string}
*/
FileSystemStats.prototype._realPath = null;
module.exports = FileSystemStats;
});