ebml-stream
Version:
Ebml parser and encoder
38 lines (37 loc) • 1.56 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const EbmlTag_1 = require("../EbmlTag");
const EbmlElementType_1 = require("../enums/EbmlElementType");
const EbmlTagPosition_1 = require("../enums/EbmlTagPosition");
const tools_1 = require("../../tools");
const EbmlTagFactory_1 = require("../EbmlTagFactory");
class EbmlMasterTag extends EbmlTag_1.EbmlTag {
constructor(id, position = EbmlTagPosition_1.EbmlTagPosition.Content) {
super(id, EbmlElementType_1.EbmlElementType.Master, position);
this._children = [];
}
get Children() {
return this._children;
}
set Children(value) {
this._children = value;
}
encodeContent() {
return Buffer.concat(this._children.map(child => child.encode()));
}
parseContent(content) {
while (content.length > 0) {
const tag = tools_1.Tools.readVint(content);
const size = tools_1.Tools.readVint(content, tag.length);
const tagIdHex = tools_1.Tools.readHexString(content, 0, tag.length);
const tagId = Number.parseInt(tagIdHex, 16);
let tagObject = EbmlTagFactory_1.EbmlTagFactory.create(tagId);
tagObject.size = size.value;
let totalTagLength = tag.length + size.length + size.value;
tagObject.parseContent(content.slice(tag.length + size.length, totalTagLength));
this._children.push(tagObject);
content = content.slice(totalTagLength);
}
}
}
exports.EbmlMasterTag = EbmlMasterTag;
;