-
Notifications
You must be signed in to change notification settings - Fork 344
/
Copy pathbox-diff.js
56 lines (52 loc) · 1.93 KB
/
box-diff.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
BoxParser.DIFF_BOXES_PROP_NAMES = [ "boxes", "entries", "references", "subsamples",
"items", "item_infos", "extents", "associations",
"subsegments", "ranges", "seekLists", "seekPoints",
"esd", "levels"];
BoxParser.DIFF_PRIMITIVE_ARRAY_PROP_NAMES = [ "compatible_brands", "matrix", "opcolor", "sample_counts", "sample_deltas",
"first_chunk", "samples_per_chunk", "sample_sizes", "chunk_offsets", "sample_offsets", "sample_description_index", "sample_duration" ];
BoxParser.boxEqualFields = function(box_a, box_b) {
if (box_a && !box_b) return false;
var prop;
for (prop in box_a) {
if (BoxParser.DIFF_BOXES_PROP_NAMES.indexOf(prop) > -1) {
continue;
// } else if (excluded_fields && excluded_fields.indexOf(prop) > -1) {
// continue;
} else if (box_a[prop] instanceof BoxParser.Box || box_b[prop] instanceof BoxParser.Box) {
continue;
} else if (typeof box_a[prop] === "undefined" || typeof box_b[prop] === "undefined") {
continue;
} else if (typeof box_a[prop] === "function" || typeof box_b[prop] === "function") {
continue;
} else if (
(box_a.subBoxNames && box_a.subBoxNames.indexOf(prop.slice(0,4)) > -1) ||
(box_b.subBoxNames && box_b.subBoxNames.indexOf(prop.slice(0,4)) > -1)) {
continue;
} else {
if (prop === "data" || prop === "start" || prop === "size" || prop === "creation_time" || prop === "modification_time") {
continue;
} else if (BoxParser.DIFF_PRIMITIVE_ARRAY_PROP_NAMES.indexOf(prop) > -1) {
continue;
} else {
if (box_a[prop] !== box_b[prop]) {
return false;
}
}
}
}
return true;
}
BoxParser.boxEqual = function(box_a, box_b) {
if (!BoxParser.boxEqualFields(box_a, box_b)) {
return false;
}
for (var j = 0; j < BoxParser.DIFF_BOXES_PROP_NAMES.length; j++) {
var name = BoxParser.DIFF_BOXES_PROP_NAMES[j];
if (box_a[name] && box_b[name]) {
if (!BoxParser.boxEqual(box_a[name], box_b[name])) {
return false;
}
}
}
return true;
}