-
Notifications
You must be signed in to change notification settings - Fork 0
/
Section.ts
38 lines (29 loc) · 1.09 KB
/
Section.ts
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
import { BiniDataView } from "../BiniDataView";
import { BiniStringBlock } from "../BiniStringBlock";
import { Entry } from "./Entry";
import { IniComment } from "./types";
export class Section {
public filePath: string = "";
public entries: Entry[] = [];
public comments: IniComment[] = [];
constructor(
public name: string
) { }
public static fromBini(
filePath: string,
reader: BiniDataView,
stringBlock: BiniStringBlock
): Section {
const nameOffset = reader.getReverseInt16();
const section = new Section(stringBlock.get(nameOffset));
section.filePath = filePath;
const entriesCount = reader.getReverseInt16();
for (let i = 0; i < entriesCount; i++) {
section.entries.push(Entry.fromBini(filePath, reader, stringBlock, section.name));
}
return section;
}
public toString() {
return `[${this.name}]\n${this.entries.join("\n")}${this.comments.length > 0 ? "\n" : ""}${this.comments.map(c => c.content).join("\n")}`;
}
}