UNPKG

ebml-stream

Version:
52 lines (51 loc) 2.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const EbmlTag_1 = require("../EbmlTag"); const EbmlElementType_1 = require("../enums/EbmlElementType"); const tools_1 = require("../../tools"); const EbmlTagPosition_1 = require("../enums/EbmlTagPosition"); class EbmlDataTag extends EbmlTag_1.EbmlTag { constructor(id, type) { super(id, type, EbmlTagPosition_1.EbmlTagPosition.Content); } parseContent(data) { switch (this.type) { case EbmlElementType_1.EbmlElementType.UnsignedInt: this.data = tools_1.Tools.readUnsigned(data); break; case EbmlElementType_1.EbmlElementType.Float: this.data = tools_1.Tools.readFloat(data); break; case EbmlElementType_1.EbmlElementType.Integer: this.data = tools_1.Tools.readSigned(data); break; case EbmlElementType_1.EbmlElementType.String: this.data = String.fromCharCode(...data); break; case EbmlElementType_1.EbmlElementType.UTF8: this.data = tools_1.Tools.readUtf8(data); break; default: this.data = data; break; } } encodeContent() { switch (this.type) { case EbmlElementType_1.EbmlElementType.UnsignedInt: return tools_1.Tools.writeUnsigned(this.data); case EbmlElementType_1.EbmlElementType.Float: return tools_1.Tools.writeFloat(this.data); case EbmlElementType_1.EbmlElementType.Integer: return tools_1.Tools.writeSigned(this.data); case EbmlElementType_1.EbmlElementType.String: return Buffer.from(this.data, "ascii"); case EbmlElementType_1.EbmlElementType.UTF8: return Buffer.from(this.data, "utf8"); case EbmlElementType_1.EbmlElementType.Binary: default: return this.data; } } } exports.EbmlDataTag = EbmlDataTag;