-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathblack.js
102 lines (77 loc) · 2.11 KB
/
black.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
93
94
95
96
97
98
99
100
101
102
import BinaryReader from './binary-reader.js'
import { object } from './black-readers.js'
export { idSymbol } from './black-readers.js'
export const typeSymbol = Symbol('type')
export class Context {
constructor(constructors = new Map(), defaultConstructor = Map) {
this.constructors = constructors
this.defaultConstructor = defaultConstructor
this.pathHandler = null
}
constructType(type) {
if (this.constructors.has(type)) {
return new this.constructors.get(type)()
} else {
let result = new this.defaultConstructor()
result[typeSymbol] = type
return result
}
}
}
export class DebugContext {
constructor(io) {
this.console = io
}
group(message) {
this.console.group(message)
}
groupEnd() {
this.console.groupEnd()
}
log(value) { }
property(name, value) {
this.console.log("%s: %s", name, value)
}
}
export class VerboseDebugContext extends DebugContext {
log(value, ...args) {
this.console.log.call(this.console, value, ...args)
}
}
function nop() {}
const nullDebugContext = {
group: nop,
groupEnd: nop,
log: nop,
property: nop
}
export function read(view, context, debugContext = nullDebugContext) {
let reader = new BinaryReader(view, context)
reader.debugContext = debugContext
reader.fileStart = view.byteOffset
reader.references = new Map()
reader.expectU32(0xB1ACF11E, "wrong FOURCC")
reader.expectU32(1, "wrong version")
let stringsReader = reader.readBinaryReader(reader.readU32())
let stringsCount = stringsReader.readU16()
let strings = []
for (let i = 0; i < stringsCount; i++) {
strings[i] = stringsReader.readCString()
}
stringsReader.expectEnd()
reader.strings = strings
for (let i = 0; i < stringsCount; i++) {
debugContext.log(`${i}: ${strings[i]}`)
}
let commentReader = reader.readBinaryReader(reader.readU32())
let commentCount = commentReader.readU16()
let comments = []
for (let i = 0; i < commentCount; i++) {
comments[i] = commentReader.readCWString()
}
commentReader.expectEnd()
return {
comments: comments,
object: object(reader)
}
}