-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshared.js
92 lines (80 loc) · 2.81 KB
/
shared.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
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @ts-check
'use strict';
/**
* @fileoverview
* Constants used by both the UI and Web Worker scripts.
*/
/**
* @typedef {object} TreeNode Node object used to represent the file tree. Can
* represent either a container or a symbol.
* @prop {TreeNode[] | null} children Child tree nodes. Null values indicate
* that there are children, but that they haven't been loaded in yet. Empty
* arrays indicate this is a leaf node.
* @prop {TreeNode | null} parent Parent tree node. null if this is a root node.
* @prop {string} idPath Full path to this node.
* @prop {number} shortNameIndex The name of the node is include in the idPath.
* This index indicates where to start to slice the idPath to read the name.
* @prop {number} size Byte size of this node and its children.
* @prop {string} type Type of this node. If this node has children, the string
* may have a second character to denote the most common child.
* @prop {{[type: string]: number}} childSizes The sizes of the children
* of this node, split by the types of the children.
*/
/**
* @typedef {object} TreeProgress
* @prop {TreeNode} root Root node and its direct children.
* @prop {number} percent Number from (0-1] to represent percentage.
* @prop {string} sizeHeader String to display as the header for the
* Size column.
* @prop {string} [error] Error message, if an error occured in the worker.
* If unset, then there was no error.
*/
/**
* @typedef {(size: number,unit:string) => {title:string,element:Node}} GetSize
*/
/** Abberivated keys used by FileEntrys in the JSON data file. */
const _KEYS = {
SOURCE_PATH: 'p',
COMPONENT_INDEX: 'c',
FILE_SYMBOLS: 's',
SYMBOL_NAME: 'n',
SIZE: 'b',
TYPE: 't',
};
/**
* @enum {number} Various byte units and the corresponding amount of bytes
* that one unit represents.
*/
const _BYTE_UNITS = Object.freeze({
GiB: 1024 ** 3,
MiB: 1024 ** 2,
KiB: 1024 ** 1,
B: 1024 ** 0,
});
/** Set of all byte units */
const _BYTE_UNITS_SET = new Set(Object.keys(_BYTE_UNITS));
/**
* Special types used by containers, such as folders and files.
*/
const _CONTAINER_TYPES = {
DIRECTORY: 'D',
COMPONENT: 'C',
FILE: 'F',
};
const _CONTAINER_TYPE_SET = new Set(Object.values(_CONTAINER_TYPES));
/** Type for an 'other' symbol */
const _OTHER_SYMBOL_TYPE = 'o';
/** Set of all known symbol types. Container types are not included. */
const _SYMBOL_TYPE_SET = new Set('bdrtv*xmpP' + _OTHER_SYMBOL_TYPE);
/** Name used by a directory created to hold symbols with no name. */
const _NO_NAME = '(No path)';
/**
* Returns shortName for a tree node.
* @param {TreeNode} node
*/
function shortName(node) {
return node.idPath.slice(node.shortNameIndex);
}