UNPKG

node-peercast

Version:
80 lines (79 loc) 2.65 kB
var Atom = (function () { function Atom(_name, _content, _children) { this._name = _name; this._content = _content; this._children = _children; } Atom.createContent = function (name, content) { return new Atom(name, content, null); }; Atom.createIntContent = function (name, content) { var buffer = new Buffer(4); buffer.writeUInt32LE(content, 0); return Atom.createContent(name, buffer); }; Atom.createContainer = function (name, children) { if (children === void 0) { children = []; } return new Atom(name, null, children); }; Object.defineProperty(Atom.prototype, "name", { get: function () { return this._name; }, enumerable: true, configurable: true }); Object.defineProperty(Atom.prototype, "content", { get: function () { if (this._content == null) { throw new Error('It\'s not content.'); } return this._content; }, enumerable: true, configurable: true }); Object.defineProperty(Atom.prototype, "children", { get: function () { if (this._children == null) { throw new Error('It\'s not container.'); } return this._children; }, enumerable: true, configurable: true }); Atom.prototype.isContent = function () { return this._content != null; }; Atom.prototype.isContainer = function () { return this._children != null; }; Atom.prototype.push = function (atom) { this._children.push(atom); }; Atom.prototype.pushContent = function (name, content) { this.push(Atom.createContent(name, content)); }; Atom.prototype.pushByteContent = function (name, content) { var buffer = new Buffer(1); buffer.writeUInt8(content, 0); this.push(Atom.createContent(name, buffer)); }; Atom.prototype.pushShortContent = function (name, content) { var buffer = new Buffer(2); buffer.writeUInt16LE(content, 0); this.push(Atom.createContent(name, buffer)); }; Atom.prototype.pushIntContent = function (name, content) { this.push(Atom.createIntContent(name, content)); }; Atom.prototype.pushStringContent = function (name, content) { this.push(Atom.createContent(name, new Buffer(content))); }; Atom.prototype.pushGuidContent = function (name, content) { this.push(Atom.createContent(name, content)); }; return Atom; })(); module.exports = Atom;