ebml-stream
Version:
Ebml parser and encoder
42 lines (41 loc) • 1.21 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const EbmlTagId_1 = require("./enums/EbmlTagId");
const tools_1 = require("../tools");
class EbmlTag {
constructor(id, type, position) {
this.id = id;
this.type = type;
this.position = position;
}
getTagDeclaration() {
let tagHex = this.id.toString(16);
if (tagHex.length % 2 !== 0) {
tagHex = `0${tagHex}`;
}
return Buffer.from(tagHex, 'hex');
}
encode() {
let vintSize = null;
let content = this.encodeContent();
if (this.size === -1) {
vintSize = Buffer.from('01ffffffffffffff', 'hex');
}
else {
let specialLength = undefined;
if ([
EbmlTagId_1.EbmlTagId.Segment,
EbmlTagId_1.EbmlTagId.Cluster
].some(i => i === this.id)) {
specialLength = 8;
}
vintSize = tools_1.Tools.writeVint(content.length, specialLength);
}
return Buffer.concat([
this.getTagDeclaration(),
vintSize,
content
]);
}
}
exports.EbmlTag = EbmlTag;
;