-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.file.js
More file actions
24 lines (23 loc) · 854 Bytes
/
util.file.js
File metadata and controls
24 lines (23 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
S.util.file = {
size: {
ofBytes: function (bytes, isMacOS) {
var thresh = isMacOS !== false ? 1000 : 1024;
if (Math.abs(bytes) < thresh) {
return bytes + ' B';
}
var units = isMacOS !== false
? ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
: ['KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
var u = -1;
do {
bytes /= thresh;
++u;
} while (Math.abs(bytes) >= thresh && u < units.length - 1);
return bytes.toFixed(1) + ' ' + units[u];
},
ofString: function (str, isMacOS) {
var m = encodeURIComponent(str).match(/%[89ABab]/g);
return S.util.file.size.ofBytes(str.length + (m ? m.length : 0), isMacOS);
}
}
};