github.com/0chain/gosdk@v1.17.11/wasmsdk/demo/EBML.js (about) 1 (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.EBML = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ 2 "use strict"; 3 Object.defineProperty(exports, "__esModule", { value: true }); 4 var tools_1 = require("./tools"); 5 var int64_buffer_1 = require("int64-buffer"); 6 var tools = require("./tools"); 7 var schema = require("matroska/lib/schema"); 8 var byEbmlID = schema.byEbmlID; 9 // https://www.matroska.org/technical/specs/index.html 10 var State; 11 (function (State) { 12 State[State["STATE_TAG"] = 1] = "STATE_TAG"; 13 State[State["STATE_SIZE"] = 2] = "STATE_SIZE"; 14 State[State["STATE_CONTENT"] = 3] = "STATE_CONTENT"; 15 })(State || (State = {})); 16 var EBMLDecoder = (function () { 17 function EBMLDecoder() { 18 this._buffer = new tools_1.Buffer(0); 19 this._tag_stack = []; 20 this._state = State.STATE_TAG; 21 this._cursor = 0; 22 this._total = 0; 23 this._schema = byEbmlID; 24 this._result = []; 25 } 26 EBMLDecoder.prototype.decode = function (chunk) { 27 this.readChunk(chunk); 28 var diff = this._result; 29 this._result = []; 30 return diff; 31 }; 32 EBMLDecoder.prototype.readChunk = function (chunk) { 33 // 読みかけの(読めなかった) this._buffer と 新しい chunk を合わせて読み直す 34 this._buffer = tools.concat([this._buffer, new tools_1.Buffer(chunk)]); 35 while (this._cursor < this._buffer.length) { 36 // console.log(this._cursor, this._total, this._tag_stack); 37 if (this._state === State.STATE_TAG && !this.readTag()) { 38 break; 39 } 40 if (this._state === State.STATE_SIZE && !this.readSize()) { 41 break; 42 } 43 if (this._state === State.STATE_CONTENT && !this.readContent()) { 44 break; 45 } 46 } 47 }; 48 EBMLDecoder.prototype.getSchemaInfo = function (tagNum) { 49 return this._schema[tagNum] || { 50 name: "unknown", 51 level: -1, 52 type: "unknown", 53 description: "unknown" 54 }; 55 }; 56 /** 57 * vint された parsing tag 58 * @return - return false when waiting for more data 59 */ 60 EBMLDecoder.prototype.readTag = function () { 61 // tag.length が buffer の外にある 62 if (this._cursor >= this._buffer.length) { 63 return false; 64 } 65 // read ebml id vint without first byte 66 var tag = tools_1.readVint(this._buffer, this._cursor); 67 // tag が読めなかった 68 if (tag == null) { 69 return false; 70 } 71 // >>>>>>>>> 72 // tag 識別子 73 //const tagStr = this._buffer.toString("hex", this._cursor, this._cursor + tag.length); 74 //const tagNum = parseInt(tagStr, 16); 75 // 上と等価 76 var buf = this._buffer.slice(this._cursor, this._cursor + tag.length); 77 var tagNum = buf.reduce(function (o, v, i, arr) { return o + v * Math.pow(16, 2 * (arr.length - 1 - i)); }, 0); 78 var schema = this.getSchemaInfo(tagNum); 79 var tagObj = { 80 EBML_ID: tagNum.toString(16), 81 schema: schema, 82 type: schema.type, 83 name: schema.name, 84 level: schema.level, 85 tagStart: this._total, 86 tagEnd: this._total + tag.length, 87 sizeStart: this._total + tag.length, 88 sizeEnd: null, 89 dataStart: null, 90 dataEnd: null, 91 dataSize: null, 92 data: null 93 }; 94 // | tag: vint | size: vint | data: Buffer(size) | 95 this._tag_stack.push(tagObj); 96 // <<<<<<<< 97 // ポインタを進める 98 this._cursor += tag.length; 99 this._total += tag.length; 100 // 読み込み状態変更 101 this._state = State.STATE_SIZE; 102 return true; 103 }; 104 /** 105 * vint された現在のタグの内容の大きさを読み込む 106 * @return - return false when waiting for more data 107 */ 108 EBMLDecoder.prototype.readSize = function () { 109 // tag.length が buffer の外にある 110 if (this._cursor >= this._buffer.length) { 111 return false; 112 } 113 // read ebml datasize vint without first byte 114 var size = tools_1.readVint(this._buffer, this._cursor); 115 // まだ読めない 116 if (size == null) { 117 return false; 118 } 119 // >>>>>>>>> 120 // current tag の data size 決定 121 var tagObj = this._tag_stack[this._tag_stack.length - 1]; 122 tagObj.sizeEnd = tagObj.sizeStart + size.length; 123 tagObj.dataStart = tagObj.sizeEnd; 124 tagObj.dataSize = size.value; 125 if (size.value === -1) { 126 // unknown size 127 tagObj.dataEnd = -1; 128 if (tagObj.type === "m") { 129 tagObj.unknownSize = true; 130 } 131 } 132 else { 133 tagObj.dataEnd = tagObj.sizeEnd + size.value; 134 } 135 // <<<<<<<< 136 // ポインタを進める 137 this._cursor += size.length; 138 this._total += size.length; 139 this._state = State.STATE_CONTENT; 140 return true; 141 }; 142 /** 143 * データ読み込み 144 */ 145 EBMLDecoder.prototype.readContent = function () { 146 var tagObj = this._tag_stack[this._tag_stack.length - 1]; 147 // master element は子要素を持つので生データはない 148 if (tagObj.type === 'm') { 149 // console.log('content should be tags'); 150 tagObj.isEnd = false; 151 this._result.push(tagObj); 152 this._state = State.STATE_TAG; 153 // この Mastert Element は空要素か 154 if (tagObj.dataSize === 0) { 155 // 即座に終了タグを追加 156 var elm = Object.assign({}, tagObj, { isEnd: true }); 157 this._result.push(elm); 158 this._tag_stack.pop(); // スタックからこのタグを捨てる 159 } 160 return true; 161 } 162 // waiting for more data 163 if (this._buffer.length < this._cursor + tagObj.dataSize) { 164 return false; 165 } 166 // タグの中身の生データ 167 var data = this._buffer.slice(this._cursor, this._cursor + tagObj.dataSize); 168 // 読み終わったバッファを捨てて読み込んでいる部分のバッファのみ残す 169 this._buffer = this._buffer.slice(this._cursor + tagObj.dataSize); 170 tagObj.data = data; 171 // >>>>>>>>> 172 switch (tagObj.type) { 173 //case "m": break; 174 // Master-Element - contains other EBML sub-elements of the next lower level 175 case "u": 176 tagObj.value = data.readUIntBE(0, data.length); 177 break; 178 // Unsigned Integer - Big-endian, any size from 1 to 8 octets 179 case "i": 180 tagObj.value = data.readIntBE(0, data.length); 181 break; 182 // Signed Integer - Big-endian, any size from 1 to 8 octets 183 case "f": 184 tagObj.value = tagObj.dataSize === 4 ? data.readFloatBE(0) : 185 tagObj.dataSize === 8 ? data.readDoubleBE(0) : 186 (console.warn("cannot read " + tagObj.dataSize + " octets float. failback to 0"), 0); 187 break; 188 // Float - Big-endian, defined for 4 and 8 octets (32, 64 bits) 189 case "s": 190 tagObj.value = data.toString("ascii"); 191 break; // ascii 192 // Printable ASCII (0x20 to 0x7E), zero-padded when needed 193 case "8": 194 tagObj.value = data.toString("utf8"); 195 break; 196 // Unicode string, zero padded when needed (RFC 2279) 197 case "b": 198 tagObj.value = data; 199 break; 200 // Binary - not interpreted by the parser 201 case "d": 202 tagObj.value = tools_1.convertEBMLDateToJSDate(new int64_buffer_1.Int64BE(data).toNumber()); 203 break; 204 } 205 if (tagObj.value === null) { 206 throw new Error("unknown tag type:" + tagObj.type); 207 } 208 this._result.push(tagObj); 209 // <<<<<<<< 210 // ポインタを進める 211 this._total += tagObj.dataSize; 212 // タグ待ちモードに変更 213 this._state = State.STATE_TAG; 214 this._cursor = 0; 215 this._tag_stack.pop(); // remove the object from the stack 216 while (this._tag_stack.length > 0) { 217 var topEle = this._tag_stack[this._tag_stack.length - 1]; 218 // 親が不定長サイズなので閉じタグは期待できない 219 if (topEle.dataEnd < 0) { 220 this._tag_stack.pop(); // 親タグを捨てる 221 return true; 222 } 223 // 閉じタグの来るべき場所まで来たかどうか 224 if (this._total < topEle.dataEnd) { 225 break; 226 } 227 // 閉じタグを挿入すべきタイミングが来た 228 if (topEle.type !== "m") { 229 throw new Error("parent element is not master element"); 230 } 231 var elm = Object.assign({}, topEle, { isEnd: true }); 232 this._result.push(elm); 233 this._tag_stack.pop(); 234 } 235 return true; 236 }; 237 return EBMLDecoder; 238 }()); 239 exports.default = EBMLDecoder; 240 241 },{"./tools":5,"int64-buffer":15,"matroska/lib/schema":17}],2:[function(require,module,exports){ 242 "use strict"; 243 Object.defineProperty(exports, "__esModule", { value: true }); 244 var tools = require("./tools"); 245 var tools_1 = require("./tools"); 246 var schema = require("matroska/lib/schema"); 247 var byEbmlID = schema.byEbmlID; 248 var EBMLEncoder = (function () { 249 function EBMLEncoder() { 250 this._schema = byEbmlID; 251 this._buffers = []; 252 this._stack = []; 253 } 254 EBMLEncoder.prototype.encode = function (elms) { 255 var _this = this; 256 return tools.concat(elms.reduce(function (lst, elm) { 257 return lst.concat(_this.encodeChunk(elm)); 258 }, [])).buffer; 259 }; 260 EBMLEncoder.prototype.encodeChunk = function (elm) { 261 if (elm.type === "m") { 262 if (!elm.isEnd) { 263 this.startTag(elm); 264 } 265 else { 266 this.endTag(elm); 267 } 268 } 269 else { 270 this.writeTag(elm); 271 } 272 return this.flush(); 273 }; 274 EBMLEncoder.prototype.flush = function () { 275 var ret = this._buffers; 276 this._buffers = []; 277 return ret; 278 }; 279 EBMLEncoder.prototype.getSchemaInfo = function (tagName) { 280 var tagNums = Object.keys(this._schema).map(Number); 281 for (var i = 0; i < tagNums.length; i++) { 282 var tagNum = tagNums[i]; 283 if (this._schema[tagNum].name === tagName) { 284 return new tools_1.Buffer(tagNum.toString(16), 'hex'); 285 } 286 } 287 return null; 288 }; 289 EBMLEncoder.prototype.writeTag = function (elm) { 290 var tagName = elm.name; 291 var tagId = this.getSchemaInfo(tagName); 292 var tagData = elm.data; 293 if (tagId == null) { 294 throw new Error('No schema entry found for ' + tagName); 295 } 296 var data = tools.encodeTag(tagId, tagData); 297 /** 298 * 親要素が閉じタグあり(isEnd)なら閉じタグが来るまで待つ(children queに入る) 299 */ 300 if (this._stack.length > 0) { 301 var last = this._stack[this._stack.length - 1]; 302 last.children.push({ 303 tagId: tagId, 304 elm: elm, 305 children: [], 306 data: data 307 }); 308 return; 309 } 310 this._buffers = this._buffers.concat(data); 311 return; 312 }; 313 EBMLEncoder.prototype.startTag = function (elm) { 314 var tagName = elm.name; 315 var tagId = this.getSchemaInfo(tagName); 316 if (tagId == null) { 317 throw new Error('No schema entry found for ' + tagName); 318 } 319 /** 320 * 閉じタグ不定長の場合はスタックに積まずに即時バッファに書き込む 321 */ 322 if (elm.unknownSize) { 323 var data = tools.encodeTag(tagId, new tools_1.Buffer(0), elm.unknownSize); 324 this._buffers = this._buffers.concat(data); 325 return; 326 } 327 var tag = { 328 tagId: tagId, 329 elm: elm, 330 children: [], 331 data: null 332 }; 333 if (this._stack.length > 0) { 334 this._stack[this._stack.length - 1].children.push(tag); 335 } 336 this._stack.push(tag); 337 }; 338 EBMLEncoder.prototype.endTag = function (elm) { 339 var tagName = elm.name; 340 var tag = this._stack.pop(); 341 if (tag == null) { 342 throw new Error("EBML structure is broken"); 343 } 344 if (tag.elm.name !== elm.name) { 345 throw new Error("EBML structure is broken"); 346 } 347 var childTagDataBuffers = tag.children.reduce(function (lst, child) { 348 if (child.data === null) { 349 throw new Error("EBML structure is broken"); 350 } 351 return lst.concat(child.data); 352 }, []); 353 var childTagDataBuffer = tools.concat(childTagDataBuffers); 354 if (tag.elm.type === "m") { 355 tag.data = tools.encodeTag(tag.tagId, childTagDataBuffer, tag.elm.unknownSize); 356 } 357 else { 358 tag.data = tools.encodeTag(tag.tagId, childTagDataBuffer); 359 } 360 if (this._stack.length < 1) { 361 this._buffers = this._buffers.concat(tag.data); 362 } 363 }; 364 return EBMLEncoder; 365 }()); 366 exports.default = EBMLEncoder; 367 368 },{"./tools":5,"matroska/lib/schema":17}],3:[function(require,module,exports){ 369 "use strict"; 370 var __extends = (this && this.__extends) || (function () { 371 var extendStatics = Object.setPrototypeOf || 372 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || 373 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; 374 return function (d, b) { 375 extendStatics(d, b); 376 function __() { this.constructor = d; } 377 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); 378 }; 379 })(); 380 Object.defineProperty(exports, "__esModule", { value: true }); 381 var events_1 = require("events"); 382 var tools = require("./tools"); 383 /** 384 * This is an informal code for reference. 385 * EBMLReader is a class for getting information to enable seeking Webm recorded by MediaRecorder. 386 * So please do not use for regular WebM files. 387 */ 388 var EBMLReader = (function (_super) { 389 __extends(EBMLReader, _super); 390 function EBMLReader() { 391 var _this = _super.call(this) || this; 392 _this.logGroup = ""; 393 _this.hasLoggingStarted = false; 394 _this.metadataloaded = false; 395 _this.chunks = []; 396 _this.stack = []; 397 _this.segmentOffset = 0; 398 _this.last2SimpleBlockVideoTrackTimecode = [0, 0]; 399 _this.last2SimpleBlockAudioTrackTimecode = [0, 0]; 400 _this.lastClusterTimecode = 0; 401 _this.lastClusterPosition = 0; 402 _this.timecodeScale = 1000000; // webm default TimecodeScale is 1ms 403 _this.metadataSize = 0; 404 _this.metadatas = []; 405 _this.cues = []; 406 _this.firstVideoBlockRead = false; 407 _this.firstAudioBlockRead = false; 408 _this.currentTrack = { TrackNumber: -1, TrackType: -1, DefaultDuration: null, CodecDelay: null }; 409 _this.trackTypes = []; 410 _this.trackDefaultDuration = []; 411 _this.trackCodecDelay = []; 412 _this.trackInfo = { type: "nothing" }; 413 _this.ended = false; 414 _this.logging = false; 415 _this.use_duration_every_simpleblock = false; 416 _this.use_webp = false; 417 _this.use_segment_info = true; 418 _this.drop_default_duration = true; 419 return _this; 420 } 421 /** 422 * emit final state. 423 */ 424 EBMLReader.prototype.stop = function () { 425 this.ended = true; 426 this.emit_segment_info(); 427 // clean up any unclosed Master Elements at the end of the stream. 428 while (this.stack.length) { 429 this.stack.pop(); 430 if (this.logging) { 431 console.groupEnd(); 432 } 433 } 434 // close main group if set, logging is enabled, and has actually logged anything. 435 if (this.logging && this.hasLoggingStarted && this.logGroup) { 436 console.groupEnd(); 437 } 438 }; 439 /** 440 * emit chunk info 441 */ 442 EBMLReader.prototype.emit_segment_info = function () { 443 var data = this.chunks; 444 this.chunks = []; 445 if (!this.metadataloaded) { 446 this.metadataloaded = true; 447 this.metadatas = data; 448 var videoTrackNum = this.trackTypes.indexOf(1); // find first video track 449 var audioTrackNum = this.trackTypes.indexOf(2); // find first audio track 450 this.trackInfo = videoTrackNum >= 0 && audioTrackNum >= 0 ? { type: "both", trackNumber: videoTrackNum } 451 : videoTrackNum >= 0 ? { type: "video", trackNumber: videoTrackNum } 452 : audioTrackNum >= 0 ? { type: "audio", trackNumber: audioTrackNum } 453 : { type: "nothing" }; 454 if (!this.use_segment_info) { 455 return; 456 } 457 this.emit("metadata", { data: data, metadataSize: this.metadataSize }); 458 } 459 else { 460 if (!this.use_segment_info) { 461 return; 462 } 463 var timecode = this.lastClusterTimecode; 464 var duration = this.duration; 465 var timecodeScale = this.timecodeScale; 466 this.emit("cluster", { timecode: timecode, data: data }); 467 this.emit("duration", { timecodeScale: timecodeScale, duration: duration }); 468 } 469 }; 470 EBMLReader.prototype.read = function (elm) { 471 var _this = this; 472 var drop = false; 473 if (this.ended) { 474 // reader is finished 475 return; 476 } 477 if (elm.type === "m") { 478 // 閉じタグの自動挿入 479 if (elm.isEnd) { 480 this.stack.pop(); 481 } 482 else { 483 var parent_1 = this.stack[this.stack.length - 1]; 484 if (parent_1 != null && parent_1.level >= elm.level) { 485 // 閉じタグなしでレベルが下がったら閉じタグを挿入 486 this.stack.pop(); 487 // From http://w3c.github.io/media-source/webm-byte-stream-format.html#webm-media-segments 488 // This fixes logging for webm streams with Cluster of unknown length and no Cluster closing elements. 489 if (this.logging) { 490 console.groupEnd(); 491 } 492 parent_1.dataEnd = elm.dataEnd; 493 parent_1.dataSize = elm.dataEnd - parent_1.dataStart; 494 parent_1.unknownSize = false; 495 var o = Object.assign({}, parent_1, { name: parent_1.name, type: parent_1.type, isEnd: true }); 496 this.chunks.push(o); 497 } 498 this.stack.push(elm); 499 } 500 } 501 if (elm.type === "m" && elm.name == "Segment") { 502 if (this.segmentOffset != 0) { 503 console.warn("Multiple segments detected!"); 504 } 505 this.segmentOffset = elm.dataStart; 506 this.emit("segment_offset", this.segmentOffset); 507 } 508 else if (elm.type === "b" && elm.name === "SimpleBlock") { 509 var _a = tools.ebmlBlock(elm.data), timecode = _a.timecode, trackNumber = _a.trackNumber, frames_1 = _a.frames; 510 if (this.trackTypes[trackNumber] === 1) { 511 if (!this.firstVideoBlockRead) { 512 this.firstVideoBlockRead = true; 513 if (this.trackInfo.type === "both" || this.trackInfo.type === "video") { 514 var CueTime = this.lastClusterTimecode + timecode; 515 this.cues.push({ CueTrack: trackNumber, CueClusterPosition: this.lastClusterPosition, CueTime: CueTime }); 516 this.emit("cue_info", { CueTrack: trackNumber, CueClusterPosition: this.lastClusterPosition, CueTime: this.lastClusterTimecode }); 517 this.emit("cue", { CueTrack: trackNumber, CueClusterPosition: this.lastClusterPosition, CueTime: CueTime }); 518 } 519 } 520 this.last2SimpleBlockVideoTrackTimecode = [this.last2SimpleBlockVideoTrackTimecode[1], timecode]; 521 } 522 else if (this.trackTypes[trackNumber] === 2) { 523 if (!this.firstAudioBlockRead) { 524 this.firstAudioBlockRead = true; 525 if (this.trackInfo.type === "audio") { 526 var CueTime = this.lastClusterTimecode + timecode; 527 this.cues.push({ CueTrack: trackNumber, CueClusterPosition: this.lastClusterPosition, CueTime: CueTime }); 528 this.emit("cue_info", { CueTrack: trackNumber, CueClusterPosition: this.lastClusterPosition, CueTime: this.lastClusterTimecode }); 529 this.emit("cue", { CueTrack: trackNumber, CueClusterPosition: this.lastClusterPosition, CueTime: CueTime }); 530 } 531 } 532 this.last2SimpleBlockAudioTrackTimecode = [this.last2SimpleBlockAudioTrackTimecode[1], timecode]; 533 } 534 if (this.use_duration_every_simpleblock) { 535 this.emit("duration", { timecodeScale: this.timecodeScale, duration: this.duration }); 536 } 537 if (this.use_webp) { 538 frames_1.forEach(function (frame) { 539 var startcode = frame.slice(3, 6).toString("hex"); 540 if (startcode !== "9d012a") { 541 return; 542 } 543 ; // VP8 の場合 544 var webpBuf = tools.VP8BitStreamToRiffWebPBuffer(frame); 545 var webp = new Blob([webpBuf], { type: "image/webp" }); 546 var currentTime = _this.duration; 547 _this.emit("webp", { currentTime: currentTime, webp: webp }); 548 }); 549 } 550 } 551 else if (elm.type === "m" && elm.name === "Cluster" && elm.isEnd === false) { 552 this.firstVideoBlockRead = false; 553 this.firstAudioBlockRead = false; 554 this.emit_segment_info(); 555 this.emit("cluster_ptr", elm.tagStart); 556 this.lastClusterPosition = elm.tagStart; 557 } 558 else if (elm.type === "u" && elm.name === "Timecode") { 559 this.lastClusterTimecode = elm.value; 560 } 561 else if (elm.type === "u" && elm.name === "TimecodeScale") { 562 this.timecodeScale = elm.value; 563 } 564 else if (elm.type === "m" && elm.name === "TrackEntry") { 565 if (elm.isEnd) { 566 this.trackTypes[this.currentTrack.TrackNumber] = this.currentTrack.TrackType; 567 this.trackDefaultDuration[this.currentTrack.TrackNumber] = this.currentTrack.DefaultDuration; 568 this.trackCodecDelay[this.currentTrack.TrackNumber] = this.currentTrack.CodecDelay; 569 } 570 else { 571 this.currentTrack = { TrackNumber: -1, TrackType: -1, DefaultDuration: null, CodecDelay: null }; 572 } 573 } 574 else if (elm.type === "u" && elm.name === "TrackType") { 575 this.currentTrack.TrackType = elm.value; 576 } 577 else if (elm.type === "u" && elm.name === "TrackNumber") { 578 this.currentTrack.TrackNumber = elm.value; 579 } 580 else if (elm.type === "u" && elm.name === "CodecDelay") { 581 this.currentTrack.CodecDelay = elm.value; 582 } 583 else if (elm.type === "u" && elm.name === "DefaultDuration") { 584 // media source api は DefaultDuration を計算するとバグる。 585 // https://bugs.chromium.org/p/chromium/issues/detail?id=606000#c22 586 // chrome 58 ではこれを回避するために DefaultDuration 要素を抜き取った。 587 // chrome 58 以前でもこのタグを抜き取ることで回避できる 588 if (this.drop_default_duration) { 589 console.warn("DefaultDuration detected!, remove it"); 590 drop = true; 591 } 592 else { 593 this.currentTrack.DefaultDuration = elm.value; 594 } 595 } 596 else if (elm.name === "unknown") { 597 console.warn(elm); 598 } 599 if (!this.metadataloaded && elm.dataEnd > 0) { 600 this.metadataSize = elm.dataEnd; 601 } 602 if (!drop) { 603 this.chunks.push(elm); 604 } 605 if (this.logging) { 606 this.put(elm); 607 } 608 }; 609 Object.defineProperty(EBMLReader.prototype, "duration", { 610 /** 611 * DefaultDuration が定義されている場合は最後のフレームのdurationも考慮する 612 * 単位 timecodeScale 613 * 614 * !!! if you need duration with seconds !!! 615 * ```js 616 * const nanosec = reader.duration * reader.timecodeScale; 617 * const sec = nanosec / 1000 / 1000 / 1000; 618 * ``` 619 */ 620 get: function () { 621 if (this.trackInfo.type === "nothing") { 622 console.warn("no video, no audio track"); 623 return 0; 624 } 625 // defaultDuration は 生の nano sec 626 var defaultDuration = 0; 627 // nanoseconds 628 var codecDelay = 0; 629 var lastTimecode = 0; 630 var _defaultDuration = this.trackDefaultDuration[this.trackInfo.trackNumber]; 631 if (typeof _defaultDuration === "number") { 632 defaultDuration = _defaultDuration; 633 } 634 else { 635 // https://bugs.chromium.org/p/chromium/issues/detail?id=606000#c22 636 // default duration がないときに使う delta 637 if (this.trackInfo.type === "both") { 638 if (this.last2SimpleBlockAudioTrackTimecode[1] > this.last2SimpleBlockVideoTrackTimecode[1]) { 639 // audio diff 640 defaultDuration = (this.last2SimpleBlockAudioTrackTimecode[1] - this.last2SimpleBlockAudioTrackTimecode[0]) * this.timecodeScale; 641 // audio delay 642 var delay = this.trackCodecDelay[this.trackTypes.indexOf(2)]; // 2 => audio 643 if (typeof delay === "number") { 644 codecDelay = delay; 645 } 646 // audio timecode 647 lastTimecode = this.last2SimpleBlockAudioTrackTimecode[1]; 648 } 649 else { 650 // video diff 651 defaultDuration = (this.last2SimpleBlockVideoTrackTimecode[1] - this.last2SimpleBlockVideoTrackTimecode[0]) * this.timecodeScale; 652 // video delay 653 var delay = this.trackCodecDelay[this.trackTypes.indexOf(1)]; // 1 => video 654 if (typeof delay === "number") { 655 codecDelay = delay; 656 } 657 // video timecode 658 lastTimecode = this.last2SimpleBlockVideoTrackTimecode[1]; 659 } 660 } 661 else if (this.trackInfo.type === "video") { 662 defaultDuration = (this.last2SimpleBlockVideoTrackTimecode[1] - this.last2SimpleBlockVideoTrackTimecode[0]) * this.timecodeScale; 663 var delay = this.trackCodecDelay[this.trackInfo.trackNumber]; // 2 => audio 664 if (typeof delay === "number") { 665 codecDelay = delay; 666 } 667 lastTimecode = this.last2SimpleBlockVideoTrackTimecode[1]; 668 } 669 else if (this.trackInfo.type === "audio") { 670 defaultDuration = (this.last2SimpleBlockAudioTrackTimecode[1] - this.last2SimpleBlockAudioTrackTimecode[0]) * this.timecodeScale; 671 var delay = this.trackCodecDelay[this.trackInfo.trackNumber]; // 1 => video 672 if (typeof delay === "number") { 673 codecDelay = delay; 674 } 675 lastTimecode = this.last2SimpleBlockAudioTrackTimecode[1]; 676 } // else { not reached } 677 } 678 // convert to timecodescale 679 var duration_nanosec = ((this.lastClusterTimecode + lastTimecode) * this.timecodeScale) + defaultDuration - codecDelay; 680 var duration = duration_nanosec / this.timecodeScale; 681 return Math.floor(duration); 682 }, 683 enumerable: true, 684 configurable: true 685 }); 686 EBMLReader.prototype.addListener = function (event, listener) { 687 return _super.prototype.addListener.call(this, event, listener); 688 }; 689 EBMLReader.prototype.put = function (elm) { 690 if (!this.hasLoggingStarted) { 691 this.hasLoggingStarted = true; 692 if (this.logging && this.logGroup) { 693 console.groupCollapsed(this.logGroup); 694 } 695 } 696 if (elm.type === "m") { 697 if (elm.isEnd) { 698 console.groupEnd(); 699 } 700 else { 701 console.group(elm.name + ":" + elm.tagStart); 702 } 703 } 704 else if (elm.type === "b") { 705 // for debug 706 //if(elm.name === "SimpleBlock"){ 707 //const o = EBML.tools.ebmlBlock(elm.value); 708 //console.log(elm.name, elm.type, o.trackNumber, o.timecode); 709 //}else{ 710 console.log(elm.name, elm.type); 711 //} 712 } 713 else { 714 console.log(elm.name, elm.tagStart, elm.type, elm.value); 715 } 716 }; 717 return EBMLReader; 718 }(events_1.EventEmitter)); 719 exports.default = EBMLReader; 720 ; 721 ; 722 ; 723 ; 724 725 },{"./tools":5,"events":13}],4:[function(require,module,exports){ 726 "use strict"; 727 Object.defineProperty(exports, "__esModule", { value: true }); 728 var EBMLDecoder_1 = require("./EBMLDecoder"); 729 exports.Decoder = EBMLDecoder_1.default; 730 var EBMLEncoder_1 = require("./EBMLEncoder"); 731 exports.Encoder = EBMLEncoder_1.default; 732 var EBMLReader_1 = require("./EBMLReader"); 733 exports.Reader = EBMLReader_1.default; 734 var tools = require("./tools"); 735 exports.tools = tools; 736 var version = require("../package.json").version; 737 exports.version = version; 738 739 },{"../package.json":18,"./EBMLDecoder":1,"./EBMLEncoder":2,"./EBMLReader":3,"./tools":5}],5:[function(require,module,exports){ 740 "use strict"; 741 Object.defineProperty(exports, "__esModule", { value: true }); 742 /// <reference types="node"/> 743 var int64_buffer_1 = require("int64-buffer"); 744 var EBMLEncoder_1 = require("./EBMLEncoder"); 745 var _Buffer = require("buffer/"); 746 var _tools = require("ebml/lib/ebml/tools"); 747 var _block = require("ebml-block"); 748 exports.Buffer = _Buffer.Buffer; 749 exports.readVint = _tools.readVint; 750 exports.writeVint = _tools.writeVint; 751 exports.ebmlBlock = _block; 752 function readBlock(buf) { 753 return exports.ebmlBlock(new exports.Buffer(buf)); 754 } 755 exports.readBlock = readBlock; 756 /** 757 * @param end - if end === false then length is unknown 758 */ 759 function encodeTag(tagId, tagData, unknownSize) { 760 if (unknownSize === void 0) { unknownSize = false; } 761 return concat([ 762 tagId, 763 unknownSize ? 764 new exports.Buffer('01ffffffffffffff', 'hex') : 765 exports.writeVint(tagData.length), 766 tagData 767 ]); 768 } 769 exports.encodeTag = encodeTag; 770 /** 771 * @return - SimpleBlock to WebP Filter 772 */ 773 function WebPFrameFilter(elms) { 774 return WebPBlockFilter(elms).reduce(function (lst, elm) { 775 var o = exports.ebmlBlock(elm.data); 776 return o.frames.reduce(function (lst, frame) { 777 // https://developers.Blob.com/speed/webp/docs/riff_container 778 var webpBuf = VP8BitStreamToRiffWebPBuffer(frame); 779 var webp = new Blob([webpBuf], { type: "image/webp" }); 780 return lst.concat(webp); 781 }, lst); 782 }, []); 783 } 784 exports.WebPFrameFilter = WebPFrameFilter; 785 /** 786 * WebP ファイルにできる SimpleBlock の パスフィルタ 787 */ 788 function WebPBlockFilter(elms) { 789 return elms.reduce(function (lst, elm) { 790 if (elm.type !== "b") { 791 return lst; 792 } 793 if (elm.name !== "SimpleBlock") { 794 return lst; 795 } 796 var o = exports.ebmlBlock(elm.data); 797 var hasWebP = o.frames.some(function (frame) { 798 // https://tools.ietf.org/html/rfc6386#section-19.1 799 var startcode = frame.slice(3, 6).toString("hex"); 800 return startcode === "9d012a"; 801 }); 802 if (!hasWebP) { 803 return lst; 804 } 805 return lst.concat(elm); 806 }, []); 807 } 808 exports.WebPBlockFilter = WebPBlockFilter; 809 /** 810 * @param frame - VP8 BitStream のうち startcode をもつ frame 811 * @return - WebP ファイルの ArrayBuffer 812 */ 813 function VP8BitStreamToRiffWebPBuffer(frame) { 814 var VP8Chunk = createRIFFChunk("VP8 ", frame); 815 var WebPChunk = concat([ 816 new exports.Buffer("WEBP", "ascii"), 817 VP8Chunk 818 ]); 819 return createRIFFChunk("RIFF", WebPChunk); 820 } 821 exports.VP8BitStreamToRiffWebPBuffer = VP8BitStreamToRiffWebPBuffer; 822 /** 823 * RIFF データチャンクを作る 824 */ 825 function createRIFFChunk(FourCC, chunk) { 826 var chunkSize = new exports.Buffer(4); 827 chunkSize.writeUInt32LE(chunk.byteLength, 0); 828 return concat([ 829 new exports.Buffer(FourCC.substr(0, 4), "ascii"), 830 chunkSize, 831 chunk, 832 new exports.Buffer(chunk.byteLength % 2 === 0 ? 0 : 1) // padding 833 ]); 834 } 835 exports.createRIFFChunk = createRIFFChunk; 836 /* Original Metadata 837 838 m 0 EBML 839 u 1 EBMLVersion 1 840 u 1 EBMLReadVersion 1 841 u 1 EBMLMaxIDLength 4 842 u 1 EBMLMaxSizeLength 8 843 s 1 DocType webm 844 u 1 DocTypeVersion 4 845 u 1 DocTypeReadVersion 2 846 m 0 Segment 847 m 1 Info segmentContentStartPos, all CueClusterPositions provided in info.cues will be relative to here and will need adjusted 848 u 2 TimecodeScale 1000000 849 8 2 MuxingApp Chrome 850 8 2 WritingApp Chrome 851 m 1 Tracks tracksStartPos 852 m 2 TrackEntry 853 u 3 TrackNumber 1 854 u 3 TrackUID 31790271978391090 855 u 3 TrackType 2 856 s 3 CodecID A_OPUS 857 b 3 CodecPrivate <Buffer 19> 858 m 3 Audio 859 f 4 SamplingFrequency 48000 860 u 4 Channels 1 861 m 2 TrackEntry 862 u 3 TrackNumber 2 863 u 3 TrackUID 24051277436254136 864 u 3 TrackType 1 865 s 3 CodecID V_VP8 866 m 3 Video 867 u 4 PixelWidth 1024 868 u 4 PixelHeight 576 869 m 1 Cluster clusterStartPos 870 u 2 Timecode 0 871 b 2 SimpleBlock track:2 timecode:0 keyframe:true invisible:false discardable:false lacing:1 872 */ 873 /* Desired Metadata 874 875 m 0 EBML 876 u 1 EBMLVersion 1 877 u 1 EBMLReadVersion 1 878 u 1 EBMLMaxIDLength 4 879 u 1 EBMLMaxSizeLength 8 880 s 1 DocType webm 881 u 1 DocTypeVersion 4 882 u 1 DocTypeReadVersion 2 883 m 0 Segment 884 m 1 SeekHead -> This is SeekPosition 0, so all SeekPositions can be calculated as (bytePos - segmentContentStartPos), which is 44 in this case 885 m 2 Seek 886 b 3 SeekID -> Buffer([0x15, 0x49, 0xA9, 0x66]) Info 887 u 3 SeekPosition -> infoStartPos = 888 m 2 Seek 889 b 3 SeekID -> Buffer([0x16, 0x54, 0xAE, 0x6B]) Tracks 890 u 3 SeekPosition { tracksStartPos } 891 m 2 Seek 892 b 3 SeekID -> Buffer([0x1C, 0x53, 0xBB, 0x6B]) Cues 893 u 3 SeekPosition { cuesStartPos } 894 m 1 Info 895 f 2 Duration 32480 -> overwrite, or insert if it doesn't exist 896 u 2 TimecodeScale 1000000 897 8 2 MuxingApp Chrome 898 8 2 WritingApp Chrome 899 m 1 Tracks 900 m 2 TrackEntry 901 u 3 TrackNumber 1 902 u 3 TrackUID 31790271978391090 903 u 3 TrackType 2 904 s 3 CodecID A_OPUS 905 b 3 CodecPrivate <Buffer 19> 906 m 3 Audio 907 f 4 SamplingFrequency 48000 908 u 4 Channels 1 909 m 2 TrackEntry 910 u 3 TrackNumber 2 911 u 3 TrackUID 24051277436254136 912 u 3 TrackType 1 913 s 3 CodecID V_VP8 914 m 3 Video 915 u 4 PixelWidth 1024 916 u 4 PixelHeight 576 917 m 1 Cues -> cuesStartPos 918 m 2 CuePoint 919 u 3 CueTime 0 920 m 3 CueTrackPositions 921 u 4 CueTrack 1 922 u 4 CueClusterPosition 3911 923 m 2 CuePoint 924 u 3 CueTime 600 925 m 3 CueTrackPositions 926 u 4 CueTrack 1 927 u 4 CueClusterPosition 3911 928 m 1 Cluster 929 u 2 Timecode 0 930 b 2 SimpleBlock track:2 timecode:0 keyframe:true invisible:false discardable:false lacing:1 931 */ 932 /** 933 * convert the metadata from a streaming webm bytestream to a seekable file by inserting Duration, Seekhead and Cues 934 * @param originalMetadata - orginal metadata (everything before the clusters start) from media recorder 935 * @param duration - Duration (TimecodeScale) 936 * @param cues - cue points for clusters 937 */ 938 function makeMetadataSeekable(originalMetadata, duration, cuesInfo) { 939 // extract the header, we can reuse this as-is 940 var header = extractElement("EBML", originalMetadata); 941 var headerSize = encodedSizeOfEbml(header); 942 //console.error("Header size: " + headerSize); 943 //printElementIds(header); 944 // After the header comes the Segment open tag, which in this implementation is always 12 bytes (4 byte id, 8 byte 'unknown length') 945 // After that the segment content starts. All SeekPositions and CueClusterPosition must be relative to segmentContentStartPos 946 var segmentContentStartPos = headerSize + 12; 947 //console.error("segmentContentStartPos: " + segmentContentStartPos); 948 // find the original metadata size, and adjust it for header size and Segment start element so we can keep all positions relative to segmentContentStartPos 949 var originalMetadataSize = originalMetadata[originalMetadata.length - 1].dataEnd - segmentContentStartPos; 950 //console.error("Original Metadata size: " + originalMetadataSize); 951 //printElementIds(originalMetadata); 952 // extract the segment info, remove the potentially existing Duration element, and add our own one. 953 var info = extractElement("Info", originalMetadata); 954 removeElement("Duration", info); 955 info.splice(1, 0, { name: "Duration", type: "f", data: createFloatBuffer(duration, 8) }); 956 var infoSize = encodedSizeOfEbml(info); 957 //console.error("Info size: " + infoSize); 958 //printElementIds(info); 959 // extract the track info, we can re-use this as is 960 var tracks = extractElement("Tracks", originalMetadata); 961 var tracksSize = encodedSizeOfEbml(tracks); 962 //console.error("Tracks size: " + tracksSize); 963 //printElementIds(tracks); 964 var seekHeadSize = 47; // Initial best guess, but could be slightly larger if the Cues element is huge. 965 var seekHead = []; 966 var cuesSize = 5 + cuesInfo.length * 15; // very rough initial approximation, depends a lot on file size and number of CuePoints 967 var cues = []; 968 var lastSizeDifference = -1; // 969 // The size of SeekHead and Cues elements depends on how many bytes the offsets values can be encoded in. 970 // The actual offsets in CueClusterPosition depend on the final size of the SeekHead and Cues elements 971 // We need to iteratively converge to a stable solution. 972 var maxIterations = 10; 973 var _loop_1 = function (i) { 974 // SeekHead starts at 0 975 var infoStart = seekHeadSize; // Info comes directly after SeekHead 976 var tracksStart = infoStart + infoSize; // Tracks comes directly after Info 977 var cuesStart = tracksStart + tracksSize; // Cues starts directly after 978 var newMetadataSize = cuesStart + cuesSize; // total size of metadata 979 // This is the offset all CueClusterPositions should be adjusted by due to the metadata size changing. 980 var sizeDifference = newMetadataSize - originalMetadataSize; 981 // console.error(`infoStart: ${infoStart}, infoSize: ${infoSize}`); 982 // console.error(`tracksStart: ${tracksStart}, tracksSize: ${tracksSize}`); 983 // console.error(`cuesStart: ${cuesStart}, cuesSize: ${cuesSize}`); 984 // console.error(`originalMetadataSize: ${originalMetadataSize}, newMetadataSize: ${newMetadataSize}, sizeDifference: ${sizeDifference}`); 985 // create the SeekHead element 986 seekHead = []; 987 seekHead.push({ name: "SeekHead", type: "m", isEnd: false }); 988 seekHead.push({ name: "Seek", type: "m", isEnd: false }); 989 seekHead.push({ name: "SeekID", type: "b", data: new exports.Buffer([0x15, 0x49, 0xA9, 0x66]) }); // Info 990 seekHead.push({ name: "SeekPosition", type: "u", data: createUIntBuffer(infoStart) }); 991 seekHead.push({ name: "Seek", type: "m", isEnd: true }); 992 seekHead.push({ name: "Seek", type: "m", isEnd: false }); 993 seekHead.push({ name: "SeekID", type: "b", data: new exports.Buffer([0x16, 0x54, 0xAE, 0x6B]) }); // Tracks 994 seekHead.push({ name: "SeekPosition", type: "u", data: createUIntBuffer(tracksStart) }); 995 seekHead.push({ name: "Seek", type: "m", isEnd: true }); 996 seekHead.push({ name: "Seek", type: "m", isEnd: false }); 997 seekHead.push({ name: "SeekID", type: "b", data: new exports.Buffer([0x1C, 0x53, 0xBB, 0x6B]) }); // Cues 998 seekHead.push({ name: "SeekPosition", type: "u", data: createUIntBuffer(cuesStart) }); 999 seekHead.push({ name: "Seek", type: "m", isEnd: true }); 1000 seekHead.push({ name: "SeekHead", type: "m", isEnd: true }); 1001 seekHeadSize = encodedSizeOfEbml(seekHead); 1002 //console.error("SeekHead size: " + seekHeadSize); 1003 //printElementIds(seekHead); 1004 // create the Cues element 1005 cues = []; 1006 cues.push({ name: "Cues", type: "m", isEnd: false }); 1007 cuesInfo.forEach(function (_a) { 1008 var CueTrack = _a.CueTrack, CueClusterPosition = _a.CueClusterPosition, CueTime = _a.CueTime; 1009 cues.push({ name: "CuePoint", type: "m", isEnd: false }); 1010 cues.push({ name: "CueTime", type: "u", data: createUIntBuffer(CueTime) }); 1011 cues.push({ name: "CueTrackPositions", type: "m", isEnd: false }); 1012 cues.push({ name: "CueTrack", type: "u", data: createUIntBuffer(CueTrack) }); 1013 //console.error(`CueClusterPosition: ${CueClusterPosition}, Corrected to: ${CueClusterPosition - segmentContentStartPos} , offset by ${sizeDifference} to become ${(CueClusterPosition - segmentContentStartPos) + sizeDifference - segmentContentStartPos}`); 1014 // EBMLReader returns CueClusterPosition with absolute byte offsets. The Cues section expects them as offsets from the first level 1 element of the Segment, so we need to adjust it. 1015 CueClusterPosition -= segmentContentStartPos; 1016 // We also need to adjust to take into account the change in metadata size from when EBMLReader read the original metadata. 1017 CueClusterPosition += sizeDifference; 1018 cues.push({ name: "CueClusterPosition", type: "u", data: createUIntBuffer(CueClusterPosition) }); 1019 cues.push({ name: "CueTrackPositions", type: "m", isEnd: true }); 1020 cues.push({ name: "CuePoint", type: "m", isEnd: true }); 1021 }); 1022 cues.push({ name: "Cues", type: "m", isEnd: true }); 1023 cuesSize = encodedSizeOfEbml(cues); 1024 //console.error("Cues size: " + cuesSize); 1025 //console.error("Cue count: " + cuesInfo.length); 1026 //printElementIds(cues); 1027 // If the new MetadataSize is not the same as the previous iteration, we need to run once more. 1028 if (lastSizeDifference !== sizeDifference) { 1029 lastSizeDifference = sizeDifference; 1030 if (i === maxIterations - 1) { 1031 throw new Error("Failed to converge to a stable metadata size"); 1032 } 1033 } 1034 else { 1035 return "break"; 1036 } 1037 }; 1038 for (var i = 0; i < maxIterations; i++) { 1039 var state_1 = _loop_1(i); 1040 if (state_1 === "break") 1041 break; 1042 } 1043 var finalMetadata = [].concat.apply([], [ 1044 header, 1045 { name: "Segment", type: "m", isEnd: false, unknownSize: true }, 1046 seekHead, 1047 info, 1048 tracks, 1049 cues 1050 ]); 1051 var result = new EBMLEncoder_1.default().encode(finalMetadata); 1052 //printElementIds(finalMetadata); 1053 //console.error(`Final metadata buffer size: ${result.byteLength}`); 1054 //console.error(`Final metadata buffer size without header and segment: ${result.byteLength-segmentContentStartPos}`); 1055 return result; 1056 } 1057 exports.makeMetadataSeekable = makeMetadataSeekable; 1058 /** 1059 * print all element id names in a list 1060 1061 * @param metadata - array of EBML elements to print 1062 * 1063 export function printElementIds(metadata: EBML.EBMLElementBuffer[]) { 1064 1065 let result: EBML.EBMLElementBuffer[] = []; 1066 let start: number = -1; 1067 1068 for (let i = 0; i < metadata.length; i++) { 1069 console.error("\t id: " + metadata[i].name); 1070 } 1071 } 1072 */ 1073 /** 1074 * remove all occurances of an EBML element from an array of elements 1075 * If it's a MasterElement you will also remove the content. (everything between start and end) 1076 * @param idName - name of the EBML Element to remove. 1077 * @param metadata - array of EBML elements to search 1078 */ 1079 function removeElement(idName, metadata) { 1080 var result = []; 1081 var start = -1; 1082 for (var i = 0; i < metadata.length; i++) { 1083 var element = metadata[i]; 1084 if (element.name === idName) { 1085 // if it's a Master element, extract the start and end element, and everything in between 1086 if (element.type === "m") { 1087 if (!element.isEnd) { 1088 start = i; 1089 } 1090 else { 1091 // we've reached the end, extract the whole thing 1092 if (start == -1) 1093 throw new Error("Detected " + idName + " closing element before finding the start"); 1094 metadata.splice(start, i - start + 1); 1095 return; 1096 } 1097 } 1098 else { 1099 // not a Master element, so we've found what we're looking for. 1100 metadata.splice(i, 1); 1101 return; 1102 } 1103 } 1104 } 1105 } 1106 exports.removeElement = removeElement; 1107 /** 1108 * extract the first occurance of an EBML tag from a flattened array of EBML data. 1109 * If it's a MasterElement you will also get the content. (everything between start and end) 1110 * @param idName - name of the EBML Element to extract. 1111 * @param metadata - array of EBML elements to search 1112 */ 1113 function extractElement(idName, metadata) { 1114 var result = []; 1115 var start = -1; 1116 for (var i = 0; i < metadata.length; i++) { 1117 var element = metadata[i]; 1118 if (element.name === idName) { 1119 // if it's a Master element, extract the start and end element, and everything in between 1120 if (element.type === "m") { 1121 if (!element.isEnd) { 1122 start = i; 1123 } 1124 else { 1125 // we've reached the end, extract the whole thing 1126 if (start == -1) 1127 throw new Error("Detected " + idName + " closing element before finding the start"); 1128 result = metadata.slice(start, i + 1); 1129 break; 1130 } 1131 } 1132 else { 1133 // not a Master element, so we've found what we're looking for. 1134 result.push(metadata[i]); 1135 break; 1136 } 1137 } 1138 } 1139 return result; 1140 } 1141 exports.extractElement = extractElement; 1142 /** 1143 * @deprecated 1144 * metadata に対して duration と seekhead を追加した metadata を返す 1145 * @param metadata - 変更前の webm における ファイル先頭から 最初の Cluster 要素までの 要素 1146 * @param duration - Duration (TimecodeScale) 1147 * @param cues - cue points for clusters 1148 * @deprecated @param clusterPtrs - 変更前の webm における SeekHead に追加する Cluster 要素 への start pointer 1149 * @deprecated @param cueInfos - please use cues. 1150 */ 1151 function putRefinedMetaData(metadata, info) { 1152 if (Array.isArray(info.cueInfos) && !Array.isArray(info.cues)) { 1153 console.warn("putRefinedMetaData: info.cueInfos property is deprecated. please use info.cues"); 1154 info.cues = info.cueInfos; 1155 } 1156 var ebml = []; 1157 var payload = []; 1158 for (var i_1 = 0; i_1 < metadata.length; i_1++) { 1159 var elm = metadata[i_1]; 1160 if (elm.type === "m" && elm.name === "Segment") { 1161 ebml = metadata.slice(0, i_1); 1162 payload = metadata.slice(i_1); 1163 if (elm.unknownSize) { 1164 payload.shift(); // remove segment tag 1165 break; 1166 } 1167 throw new Error("this metadata is not streaming webm file"); 1168 } 1169 } 1170 // *0 *4 *5 *36 *40 *48=segmentOffset *185=originalPayloadOffsetEnd 1171 // | | | | | | | 1172 // [EBML][size]....[Segment][size][Info][size][Duration][size]...[Cluster] 1173 // | | |^inf | | 1174 // | +segmentSiz(12)+ | 1175 // +-ebmlSize(36)--+ | +-payloadSize(137)-------------+offsetEndDiff+ 1176 // | | +-newPayloadSize(??)-------------------------+ 1177 // | | | | 1178 // [Segment][size][Info][size][Duration][size]....[size][value][Cluster] 1179 // ^ | 1180 // | *??=newPayloadOffsetEnd 1181 // inf 1182 if (!(payload[payload.length - 1].dataEnd > 0)) { 1183 throw new Error("metadata dataEnd has wrong number"); 1184 } 1185 var originalPayloadOffsetEnd = payload[payload.length - 1].dataEnd; // = first cluster ptr 1186 var ebmlSize = ebml[ebml.length - 1].dataEnd; // = first segment ptr 1187 var refinedEBMLSize = new EBMLEncoder_1.default().encode(ebml).byteLength; 1188 var offsetDiff = refinedEBMLSize - ebmlSize; 1189 var payloadSize = originalPayloadOffsetEnd - payload[0].tagStart; 1190 var segmentSize = payload[0].tagStart - ebmlSize; 1191 var segmentOffset = payload[0].tagStart; 1192 var segmentTagBuf = new exports.Buffer([0x18, 0x53, 0x80, 0x67]); // Segment 1193 var segmentSizeBuf = new exports.Buffer('01ffffffffffffff', 'hex'); // Segmentの最後の位置は無数の Cluster 依存なので。 writeVint(newPayloadSize).byteLength ではなく、 infinity. 1194 var _segmentSize = segmentTagBuf.byteLength + segmentSizeBuf.byteLength; // == segmentSize 1195 var newPayloadSize = payloadSize; 1196 // We need the size to be stable between two refinements in order for our offsets to be correct 1197 // Bound the number of possible refinements so we can't go infinate if something goes wrong 1198 var i; 1199 for (i = 1; i < 20; i++) { 1200 var newPayloadOffsetEnd = ebmlSize + _segmentSize + newPayloadSize; 1201 var offsetEndDiff = newPayloadOffsetEnd - originalPayloadOffsetEnd; 1202 var sizeDiff = offsetDiff + offsetEndDiff; 1203 var refined = refineMetadata(payload, sizeDiff, info); 1204 var newNewRefinedSize = new EBMLEncoder_1.default().encode(refined).byteLength; // 一旦 seekhead を作って自身のサイズを調べる 1205 if (newNewRefinedSize === newPayloadSize) { 1206 // Size is stable 1207 return new EBMLEncoder_1.default().encode([].concat(ebml, [{ type: "m", name: "Segment", isEnd: false, unknownSize: true }], refined)); 1208 } 1209 newPayloadSize = newNewRefinedSize; 1210 } 1211 throw new Error("unable to refine metadata, stable size could not be found in " + i + " iterations!"); 1212 } 1213 exports.putRefinedMetaData = putRefinedMetaData; 1214 // Given a list of EBMLElementBuffers, returns their encoded size in bytes 1215 function encodedSizeOfEbml(refinedMetaData) { 1216 var encorder = new EBMLEncoder_1.default(); 1217 return refinedMetaData.reduce(function (lst, elm) { return lst.concat(encorder.encode([elm])); }, []).reduce(function (o, buf) { return o + buf.byteLength; }, 0); 1218 } 1219 function refineMetadata(mesetadata, sizeDiff, info) { 1220 var duration = info.duration, clusterPtrs = info.clusterPtrs, cues = info.cues; 1221 var _metadata = mesetadata.slice(0); 1222 if (typeof duration === "number") { 1223 // duration を追加する 1224 var overwrited_1 = false; 1225 _metadata.forEach(function (elm) { 1226 if (elm.type === "f" && elm.name === "Duration") { 1227 overwrited_1 = true; 1228 elm.data = createFloatBuffer(duration, 8); 1229 } 1230 }); 1231 if (!overwrited_1) { 1232 insertTag(_metadata, "Info", [{ name: "Duration", type: "f", data: createFloatBuffer(duration, 8) }]); 1233 } 1234 } 1235 if (Array.isArray(cues)) { 1236 insertTag(_metadata, "Cues", create_cue(cues, sizeDiff)); 1237 } 1238 var seekhead_children = []; 1239 if (Array.isArray(clusterPtrs)) { 1240 console.warn("append cluster pointers to seekhead is deprecated. please use cues"); 1241 seekhead_children = create_seek_from_clusters(clusterPtrs, sizeDiff); 1242 } 1243 // remove seek info 1244 /* 1245 _metadata = _metadata.filter((elm)=> !( 1246 elm.name === "Seek" || 1247 elm.name === "SeekID" || 1248 elm.name === "SeekPosition") ); 1249 */ 1250 // working on progress 1251 //seekhead_children = seekhead_children.concat(create_seekhead(_metadata)); 1252 insertTag(_metadata, "SeekHead", seekhead_children, true); 1253 return _metadata; 1254 } 1255 function create_seekhead(metadata, sizeDiff) { 1256 var seeks = []; 1257 ["Info", "Tracks", "Cues"].forEach(function (tagName) { 1258 var tagStarts = metadata.filter(function (elm) { return elm.type === "m" && elm.name === tagName && elm.isEnd === false; }).map(function (elm) { return elm["tagStart"]; }); 1259 var tagStart = tagStarts[0]; 1260 if (typeof tagStart !== "number") { 1261 return; 1262 } 1263 seeks.push({ name: "Seek", type: "m", isEnd: false }); 1264 switch (tagName) { 1265 case "Info": 1266 seeks.push({ name: "SeekID", type: "b", data: new exports.Buffer([0x15, 0x49, 0xA9, 0x66]) }); 1267 break; 1268 case "Tracks": 1269 seeks.push({ name: "SeekID", type: "b", data: new exports.Buffer([0x16, 0x54, 0xAE, 0x6B]) }); 1270 break; 1271 case "Cues": 1272 seeks.push({ name: "SeekID", type: "b", data: new exports.Buffer([0x1C, 0x53, 0xBB, 0x6B]) }); 1273 break; 1274 } 1275 seeks.push({ name: "SeekPosition", type: "u", data: createUIntBuffer(tagStart + sizeDiff) }); 1276 seeks.push({ name: "Seek", type: "m", isEnd: true }); 1277 }); 1278 return seeks; 1279 } 1280 function create_seek_from_clusters(clusterPtrs, sizeDiff) { 1281 var seeks = []; 1282 clusterPtrs.forEach(function (start) { 1283 seeks.push({ name: "Seek", type: "m", isEnd: false }); 1284 // [0x1F, 0x43, 0xB6, 0x75] で Cluster 意 1285 seeks.push({ name: "SeekID", type: "b", data: new exports.Buffer([0x1F, 0x43, 0xB6, 0x75]) }); 1286 seeks.push({ name: "SeekPosition", type: "u", data: createUIntBuffer(start + sizeDiff) }); 1287 seeks.push({ name: "Seek", type: "m", isEnd: true }); 1288 }); 1289 return seeks; 1290 } 1291 function create_cue(cueInfos, sizeDiff) { 1292 var cues = []; 1293 cueInfos.forEach(function (_a) { 1294 var CueTrack = _a.CueTrack, CueClusterPosition = _a.CueClusterPosition, CueTime = _a.CueTime; 1295 cues.push({ name: "CuePoint", type: "m", isEnd: false }); 1296 cues.push({ name: "CueTime", type: "u", data: createUIntBuffer(CueTime) }); 1297 cues.push({ name: "CueTrackPositions", type: "m", isEnd: false }); 1298 cues.push({ name: "CueTrack", type: "u", data: createUIntBuffer(CueTrack) }); // video track 1299 cues.push({ name: "CueClusterPosition", type: "u", data: createUIntBuffer(CueClusterPosition + sizeDiff) }); 1300 cues.push({ name: "CueTrackPositions", type: "m", isEnd: true }); 1301 cues.push({ name: "CuePoint", type: "m", isEnd: true }); 1302 }); 1303 return cues; 1304 } 1305 function insertTag(_metadata, tagName, children, insertHead) { 1306 if (insertHead === void 0) { insertHead = false; } 1307 // find the tagname from _metadata 1308 var idx = -1; 1309 for (var i = 0; i < _metadata.length; i++) { 1310 var elm = _metadata[i]; 1311 if (elm.type === "m" && elm.name === tagName && elm.isEnd === false) { 1312 idx = i; 1313 break; 1314 } 1315 } 1316 if (idx >= 0) { 1317 // insert [<CuePoint />] to <Cues /> 1318 Array.prototype.splice.apply(_metadata, [idx + 1, 0].concat(children)); 1319 } 1320 else if (insertHead) { 1321 [].concat([{ name: tagName, type: "m", isEnd: false }], children, [{ name: tagName, type: "m", isEnd: true }]).reverse().forEach(function (elm) { _metadata.unshift(elm); }); 1322 } 1323 else { 1324 // metadata 末尾に <Cues /> を追加 1325 // insert <Cues /> 1326 _metadata.push({ name: tagName, type: "m", isEnd: false }); 1327 children.forEach(function (elm) { _metadata.push(elm); }); 1328 _metadata.push({ name: tagName, type: "m", isEnd: true }); 1329 } 1330 } 1331 // alter Buffer.concat - https://github.com/feross/buffer/issues/154 1332 function concat(list) { 1333 //return Buffer.concat.apply(Buffer, list); 1334 var i = 0; 1335 var length = 0; 1336 for (; i < list.length; ++i) { 1337 length += list[i].length; 1338 } 1339 var buffer = exports.Buffer.allocUnsafe(length); 1340 var pos = 0; 1341 for (i = 0; i < list.length; ++i) { 1342 var buf = list[i]; 1343 buf.copy(buffer, pos); 1344 pos += buf.length; 1345 } 1346 return buffer; 1347 } 1348 exports.concat = concat; 1349 function encodeValueToBuffer(elm) { 1350 var data = new exports.Buffer(0); 1351 if (elm.type === "m") { 1352 return elm; 1353 } 1354 switch (elm.type) { 1355 case "u": 1356 data = createUIntBuffer(elm.value); 1357 break; 1358 case "i": 1359 data = createIntBuffer(elm.value); 1360 break; 1361 case "f": 1362 data = createFloatBuffer(elm.value); 1363 break; 1364 case "s": 1365 data = new exports.Buffer(elm.value, 'ascii'); 1366 break; 1367 case "8": 1368 data = new exports.Buffer(elm.value, 'utf8'); 1369 break; 1370 case "b": 1371 data = elm.value; 1372 break; 1373 case "d": 1374 data = new int64_buffer_1.Int64BE(elm.value.getTime().toString()).toBuffer(); 1375 break; 1376 } 1377 return Object.assign({}, elm, { data: data }); 1378 } 1379 exports.encodeValueToBuffer = encodeValueToBuffer; 1380 function createUIntBuffer(value) { 1381 // Big-endian, any size from 1 to 8 1382 // but js number is float64, so max 6 bit octets 1383 var bytes = 1; 1384 for (; value >= Math.pow(2, 8 * bytes); bytes++) { } 1385 if (bytes >= 7) { 1386 console.warn("7bit or more bigger uint not supported."); 1387 return new int64_buffer_1.Uint64BE(value).toBuffer(); 1388 } 1389 var data = new exports.Buffer(bytes); 1390 data.writeUIntBE(value, 0, bytes); 1391 return data; 1392 } 1393 exports.createUIntBuffer = createUIntBuffer; 1394 function createIntBuffer(value) { 1395 // Big-endian, any size from 1 to 8 octets 1396 // but js number is float64, so max 6 bit 1397 var bytes = 1; 1398 for (; value >= Math.pow(2, 8 * bytes); bytes++) { } 1399 if (bytes >= 7) { 1400 console.warn("7bit or more bigger uint not supported."); 1401 return new int64_buffer_1.Int64BE(value).toBuffer(); 1402 } 1403 var data = new exports.Buffer(bytes); 1404 data.writeIntBE(value, 0, bytes); 1405 return data; 1406 } 1407 exports.createIntBuffer = createIntBuffer; 1408 function createFloatBuffer(value, bytes) { 1409 if (bytes === void 0) { bytes = 8; } 1410 // Big-endian, defined for 4 and 8 octets (32, 64 bits) 1411 // js number is float64 so 8 bytes. 1412 if (bytes === 8) { 1413 // 64bit 1414 var data = new exports.Buffer(8); 1415 data.writeDoubleBE(value, 0); 1416 return data; 1417 } 1418 else if (bytes === 4) { 1419 // 32bit 1420 var data = new exports.Buffer(4); 1421 data.writeFloatBE(value, 0); 1422 return data; 1423 } 1424 else { 1425 throw new Error("float type bits must 4bytes or 8bytes"); 1426 } 1427 } 1428 exports.createFloatBuffer = createFloatBuffer; 1429 function convertEBMLDateToJSDate(int64str) { 1430 if (int64str instanceof Date) { 1431 return int64str; 1432 } 1433 return new Date(new Date("2001-01-01T00:00:00.000Z").getTime() + (Number(int64str) / 1000 / 1000)); 1434 } 1435 exports.convertEBMLDateToJSDate = convertEBMLDateToJSDate; 1436 1437 },{"./EBMLEncoder":2,"buffer/":8,"ebml-block":9,"ebml/lib/ebml/tools":12,"int64-buffer":15}],6:[function(require,module,exports){ 1438 'use strict' 1439 1440 exports.byteLength = byteLength 1441 exports.toByteArray = toByteArray 1442 exports.fromByteArray = fromByteArray 1443 1444 var lookup = [] 1445 var revLookup = [] 1446 var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array 1447 1448 var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' 1449 for (var i = 0, len = code.length; i < len; ++i) { 1450 lookup[i] = code[i] 1451 revLookup[code.charCodeAt(i)] = i 1452 } 1453 1454 // Support decoding URL-safe base64 strings, as Node.js does. 1455 // See: https://en.wikipedia.org/wiki/Base64#URL_applications 1456 revLookup['-'.charCodeAt(0)] = 62 1457 revLookup['_'.charCodeAt(0)] = 63 1458 1459 function getLens (b64) { 1460 var len = b64.length 1461 1462 if (len % 4 > 0) { 1463 throw new Error('Invalid string. Length must be a multiple of 4') 1464 } 1465 1466 // Trim off extra bytes after placeholder bytes are found 1467 // See: https://github.com/beatgammit/base64-js/issues/42 1468 var validLen = b64.indexOf('=') 1469 if (validLen === -1) validLen = len 1470 1471 var placeHoldersLen = validLen === len 1472 ? 0 1473 : 4 - (validLen % 4) 1474 1475 return [validLen, placeHoldersLen] 1476 } 1477 1478 // base64 is 4/3 + up to two characters of the original data 1479 function byteLength (b64) { 1480 var lens = getLens(b64) 1481 var validLen = lens[0] 1482 var placeHoldersLen = lens[1] 1483 return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen 1484 } 1485 1486 function _byteLength (b64, validLen, placeHoldersLen) { 1487 return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen 1488 } 1489 1490 function toByteArray (b64) { 1491 var tmp 1492 var lens = getLens(b64) 1493 var validLen = lens[0] 1494 var placeHoldersLen = lens[1] 1495 1496 var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen)) 1497 1498 var curByte = 0 1499 1500 // if there are placeholders, only get up to the last complete 4 chars 1501 var len = placeHoldersLen > 0 1502 ? validLen - 4 1503 : validLen 1504 1505 var i 1506 for (i = 0; i < len; i += 4) { 1507 tmp = 1508 (revLookup[b64.charCodeAt(i)] << 18) | 1509 (revLookup[b64.charCodeAt(i + 1)] << 12) | 1510 (revLookup[b64.charCodeAt(i + 2)] << 6) | 1511 revLookup[b64.charCodeAt(i + 3)] 1512 arr[curByte++] = (tmp >> 16) & 0xFF 1513 arr[curByte++] = (tmp >> 8) & 0xFF 1514 arr[curByte++] = tmp & 0xFF 1515 } 1516 1517 if (placeHoldersLen === 2) { 1518 tmp = 1519 (revLookup[b64.charCodeAt(i)] << 2) | 1520 (revLookup[b64.charCodeAt(i + 1)] >> 4) 1521 arr[curByte++] = tmp & 0xFF 1522 } 1523 1524 if (placeHoldersLen === 1) { 1525 tmp = 1526 (revLookup[b64.charCodeAt(i)] << 10) | 1527 (revLookup[b64.charCodeAt(i + 1)] << 4) | 1528 (revLookup[b64.charCodeAt(i + 2)] >> 2) 1529 arr[curByte++] = (tmp >> 8) & 0xFF 1530 arr[curByte++] = tmp & 0xFF 1531 } 1532 1533 return arr 1534 } 1535 1536 function tripletToBase64 (num) { 1537 return lookup[num >> 18 & 0x3F] + 1538 lookup[num >> 12 & 0x3F] + 1539 lookup[num >> 6 & 0x3F] + 1540 lookup[num & 0x3F] 1541 } 1542 1543 function encodeChunk (uint8, start, end) { 1544 var tmp 1545 var output = [] 1546 for (var i = start; i < end; i += 3) { 1547 tmp = 1548 ((uint8[i] << 16) & 0xFF0000) + 1549 ((uint8[i + 1] << 8) & 0xFF00) + 1550 (uint8[i + 2] & 0xFF) 1551 output.push(tripletToBase64(tmp)) 1552 } 1553 return output.join('') 1554 } 1555 1556 function fromByteArray (uint8) { 1557 var tmp 1558 var len = uint8.length 1559 var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes 1560 var parts = [] 1561 var maxChunkLength = 16383 // must be multiple of 3 1562 1563 // go through the array every three bytes, we'll deal with trailing stuff later 1564 for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) { 1565 parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength))) 1566 } 1567 1568 // pad the end with zeros, but make sure to not forget the extra bytes 1569 if (extraBytes === 1) { 1570 tmp = uint8[len - 1] 1571 parts.push( 1572 lookup[tmp >> 2] + 1573 lookup[(tmp << 4) & 0x3F] + 1574 '==' 1575 ) 1576 } else if (extraBytes === 2) { 1577 tmp = (uint8[len - 2] << 8) + uint8[len - 1] 1578 parts.push( 1579 lookup[tmp >> 10] + 1580 lookup[(tmp >> 4) & 0x3F] + 1581 lookup[(tmp << 2) & 0x3F] + 1582 '=' 1583 ) 1584 } 1585 1586 return parts.join('') 1587 } 1588 1589 },{}],7:[function(require,module,exports){ 1590 (function (global,Buffer){(function (){ 1591 /*! 1592 * The buffer module from node.js, for the browser. 1593 * 1594 * @author Feross Aboukhadijeh <http://feross.org> 1595 * @license MIT 1596 */ 1597 /* eslint-disable no-proto */ 1598 1599 'use strict' 1600 1601 var base64 = require('base64-js') 1602 var ieee754 = require('ieee754') 1603 var isArray = require('isarray') 1604 1605 exports.Buffer = Buffer 1606 exports.SlowBuffer = SlowBuffer 1607 exports.INSPECT_MAX_BYTES = 50 1608 1609 /** 1610 * If `Buffer.TYPED_ARRAY_SUPPORT`: 1611 * === true Use Uint8Array implementation (fastest) 1612 * === false Use Object implementation (most compatible, even IE6) 1613 * 1614 * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, 1615 * Opera 11.6+, iOS 4.2+. 1616 * 1617 * Due to various browser bugs, sometimes the Object implementation will be used even 1618 * when the browser supports typed arrays. 1619 * 1620 * Note: 1621 * 1622 * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances, 1623 * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438. 1624 * 1625 * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function. 1626 * 1627 * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of 1628 * incorrect length in some situations. 1629 1630 * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they 1631 * get the Object implementation, which is slower but behaves correctly. 1632 */ 1633 Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined 1634 ? global.TYPED_ARRAY_SUPPORT 1635 : typedArraySupport() 1636 1637 /* 1638 * Export kMaxLength after typed array support is determined. 1639 */ 1640 exports.kMaxLength = kMaxLength() 1641 1642 function typedArraySupport () { 1643 try { 1644 var arr = new Uint8Array(1) 1645 arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }} 1646 return arr.foo() === 42 && // typed array instances can be augmented 1647 typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray` 1648 arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray` 1649 } catch (e) { 1650 return false 1651 } 1652 } 1653 1654 function kMaxLength () { 1655 return Buffer.TYPED_ARRAY_SUPPORT 1656 ? 0x7fffffff 1657 : 0x3fffffff 1658 } 1659 1660 function createBuffer (that, length) { 1661 if (kMaxLength() < length) { 1662 throw new RangeError('Invalid typed array length') 1663 } 1664 if (Buffer.TYPED_ARRAY_SUPPORT) { 1665 // Return an augmented `Uint8Array` instance, for best performance 1666 that = new Uint8Array(length) 1667 that.__proto__ = Buffer.prototype 1668 } else { 1669 // Fallback: Return an object instance of the Buffer class 1670 if (that === null) { 1671 that = new Buffer(length) 1672 } 1673 that.length = length 1674 } 1675 1676 return that 1677 } 1678 1679 /** 1680 * The Buffer constructor returns instances of `Uint8Array` that have their 1681 * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of 1682 * `Uint8Array`, so the returned instances will have all the node `Buffer` methods 1683 * and the `Uint8Array` methods. Square bracket notation works as expected -- it 1684 * returns a single octet. 1685 * 1686 * The `Uint8Array` prototype remains unmodified. 1687 */ 1688 1689 function Buffer (arg, encodingOrOffset, length) { 1690 if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) { 1691 return new Buffer(arg, encodingOrOffset, length) 1692 } 1693 1694 // Common case. 1695 if (typeof arg === 'number') { 1696 if (typeof encodingOrOffset === 'string') { 1697 throw new Error( 1698 'If encoding is specified then the first argument must be a string' 1699 ) 1700 } 1701 return allocUnsafe(this, arg) 1702 } 1703 return from(this, arg, encodingOrOffset, length) 1704 } 1705 1706 Buffer.poolSize = 8192 // not used by this implementation 1707 1708 // TODO: Legacy, not needed anymore. Remove in next major version. 1709 Buffer._augment = function (arr) { 1710 arr.__proto__ = Buffer.prototype 1711 return arr 1712 } 1713 1714 function from (that, value, encodingOrOffset, length) { 1715 if (typeof value === 'number') { 1716 throw new TypeError('"value" argument must not be a number') 1717 } 1718 1719 if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) { 1720 return fromArrayBuffer(that, value, encodingOrOffset, length) 1721 } 1722 1723 if (typeof value === 'string') { 1724 return fromString(that, value, encodingOrOffset) 1725 } 1726 1727 return fromObject(that, value) 1728 } 1729 1730 /** 1731 * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError 1732 * if value is a number. 1733 * Buffer.from(str[, encoding]) 1734 * Buffer.from(array) 1735 * Buffer.from(buffer) 1736 * Buffer.from(arrayBuffer[, byteOffset[, length]]) 1737 **/ 1738 Buffer.from = function (value, encodingOrOffset, length) { 1739 return from(null, value, encodingOrOffset, length) 1740 } 1741 1742 if (Buffer.TYPED_ARRAY_SUPPORT) { 1743 Buffer.prototype.__proto__ = Uint8Array.prototype 1744 Buffer.__proto__ = Uint8Array 1745 if (typeof Symbol !== 'undefined' && Symbol.species && 1746 Buffer[Symbol.species] === Buffer) { 1747 // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97 1748 Object.defineProperty(Buffer, Symbol.species, { 1749 value: null, 1750 configurable: true 1751 }) 1752 } 1753 } 1754 1755 function assertSize (size) { 1756 if (typeof size !== 'number') { 1757 throw new TypeError('"size" argument must be a number') 1758 } else if (size < 0) { 1759 throw new RangeError('"size" argument must not be negative') 1760 } 1761 } 1762 1763 function alloc (that, size, fill, encoding) { 1764 assertSize(size) 1765 if (size <= 0) { 1766 return createBuffer(that, size) 1767 } 1768 if (fill !== undefined) { 1769 // Only pay attention to encoding if it's a string. This 1770 // prevents accidentally sending in a number that would 1771 // be interpretted as a start offset. 1772 return typeof encoding === 'string' 1773 ? createBuffer(that, size).fill(fill, encoding) 1774 : createBuffer(that, size).fill(fill) 1775 } 1776 return createBuffer(that, size) 1777 } 1778 1779 /** 1780 * Creates a new filled Buffer instance. 1781 * alloc(size[, fill[, encoding]]) 1782 **/ 1783 Buffer.alloc = function (size, fill, encoding) { 1784 return alloc(null, size, fill, encoding) 1785 } 1786 1787 function allocUnsafe (that, size) { 1788 assertSize(size) 1789 that = createBuffer(that, size < 0 ? 0 : checked(size) | 0) 1790 if (!Buffer.TYPED_ARRAY_SUPPORT) { 1791 for (var i = 0; i < size; ++i) { 1792 that[i] = 0 1793 } 1794 } 1795 return that 1796 } 1797 1798 /** 1799 * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance. 1800 * */ 1801 Buffer.allocUnsafe = function (size) { 1802 return allocUnsafe(null, size) 1803 } 1804 /** 1805 * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. 1806 */ 1807 Buffer.allocUnsafeSlow = function (size) { 1808 return allocUnsafe(null, size) 1809 } 1810 1811 function fromString (that, string, encoding) { 1812 if (typeof encoding !== 'string' || encoding === '') { 1813 encoding = 'utf8' 1814 } 1815 1816 if (!Buffer.isEncoding(encoding)) { 1817 throw new TypeError('"encoding" must be a valid string encoding') 1818 } 1819 1820 var length = byteLength(string, encoding) | 0 1821 that = createBuffer(that, length) 1822 1823 var actual = that.write(string, encoding) 1824 1825 if (actual !== length) { 1826 // Writing a hex string, for example, that contains invalid characters will 1827 // cause everything after the first invalid character to be ignored. (e.g. 1828 // 'abxxcd' will be treated as 'ab') 1829 that = that.slice(0, actual) 1830 } 1831 1832 return that 1833 } 1834 1835 function fromArrayLike (that, array) { 1836 var length = array.length < 0 ? 0 : checked(array.length) | 0 1837 that = createBuffer(that, length) 1838 for (var i = 0; i < length; i += 1) { 1839 that[i] = array[i] & 255 1840 } 1841 return that 1842 } 1843 1844 function fromArrayBuffer (that, array, byteOffset, length) { 1845 array.byteLength // this throws if `array` is not a valid ArrayBuffer 1846 1847 if (byteOffset < 0 || array.byteLength < byteOffset) { 1848 throw new RangeError('\'offset\' is out of bounds') 1849 } 1850 1851 if (array.byteLength < byteOffset + (length || 0)) { 1852 throw new RangeError('\'length\' is out of bounds') 1853 } 1854 1855 if (byteOffset === undefined && length === undefined) { 1856 array = new Uint8Array(array) 1857 } else if (length === undefined) { 1858 array = new Uint8Array(array, byteOffset) 1859 } else { 1860 array = new Uint8Array(array, byteOffset, length) 1861 } 1862 1863 if (Buffer.TYPED_ARRAY_SUPPORT) { 1864 // Return an augmented `Uint8Array` instance, for best performance 1865 that = array 1866 that.__proto__ = Buffer.prototype 1867 } else { 1868 // Fallback: Return an object instance of the Buffer class 1869 that = fromArrayLike(that, array) 1870 } 1871 return that 1872 } 1873 1874 function fromObject (that, obj) { 1875 if (Buffer.isBuffer(obj)) { 1876 var len = checked(obj.length) | 0 1877 that = createBuffer(that, len) 1878 1879 if (that.length === 0) { 1880 return that 1881 } 1882 1883 obj.copy(that, 0, 0, len) 1884 return that 1885 } 1886 1887 if (obj) { 1888 if ((typeof ArrayBuffer !== 'undefined' && 1889 obj.buffer instanceof ArrayBuffer) || 'length' in obj) { 1890 if (typeof obj.length !== 'number' || isnan(obj.length)) { 1891 return createBuffer(that, 0) 1892 } 1893 return fromArrayLike(that, obj) 1894 } 1895 1896 if (obj.type === 'Buffer' && isArray(obj.data)) { 1897 return fromArrayLike(that, obj.data) 1898 } 1899 } 1900 1901 throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.') 1902 } 1903 1904 function checked (length) { 1905 // Note: cannot use `length < kMaxLength()` here because that fails when 1906 // length is NaN (which is otherwise coerced to zero.) 1907 if (length >= kMaxLength()) { 1908 throw new RangeError('Attempt to allocate Buffer larger than maximum ' + 1909 'size: 0x' + kMaxLength().toString(16) + ' bytes') 1910 } 1911 return length | 0 1912 } 1913 1914 function SlowBuffer (length) { 1915 if (+length != length) { // eslint-disable-line eqeqeq 1916 length = 0 1917 } 1918 return Buffer.alloc(+length) 1919 } 1920 1921 Buffer.isBuffer = function isBuffer (b) { 1922 return !!(b != null && b._isBuffer) 1923 } 1924 1925 Buffer.compare = function compare (a, b) { 1926 if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) { 1927 throw new TypeError('Arguments must be Buffers') 1928 } 1929 1930 if (a === b) return 0 1931 1932 var x = a.length 1933 var y = b.length 1934 1935 for (var i = 0, len = Math.min(x, y); i < len; ++i) { 1936 if (a[i] !== b[i]) { 1937 x = a[i] 1938 y = b[i] 1939 break 1940 } 1941 } 1942 1943 if (x < y) return -1 1944 if (y < x) return 1 1945 return 0 1946 } 1947 1948 Buffer.isEncoding = function isEncoding (encoding) { 1949 switch (String(encoding).toLowerCase()) { 1950 case 'hex': 1951 case 'utf8': 1952 case 'utf-8': 1953 case 'ascii': 1954 case 'latin1': 1955 case 'binary': 1956 case 'base64': 1957 case 'ucs2': 1958 case 'ucs-2': 1959 case 'utf16le': 1960 case 'utf-16le': 1961 return true 1962 default: 1963 return false 1964 } 1965 } 1966 1967 Buffer.concat = function concat (list, length) { 1968 if (!isArray(list)) { 1969 throw new TypeError('"list" argument must be an Array of Buffers') 1970 } 1971 1972 if (list.length === 0) { 1973 return Buffer.alloc(0) 1974 } 1975 1976 var i 1977 if (length === undefined) { 1978 length = 0 1979 for (i = 0; i < list.length; ++i) { 1980 length += list[i].length 1981 } 1982 } 1983 1984 var buffer = Buffer.allocUnsafe(length) 1985 var pos = 0 1986 for (i = 0; i < list.length; ++i) { 1987 var buf = list[i] 1988 if (!Buffer.isBuffer(buf)) { 1989 throw new TypeError('"list" argument must be an Array of Buffers') 1990 } 1991 buf.copy(buffer, pos) 1992 pos += buf.length 1993 } 1994 return buffer 1995 } 1996 1997 function byteLength (string, encoding) { 1998 if (Buffer.isBuffer(string)) { 1999 return string.length 2000 } 2001 if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' && 2002 (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) { 2003 return string.byteLength 2004 } 2005 if (typeof string !== 'string') { 2006 string = '' + string 2007 } 2008 2009 var len = string.length 2010 if (len === 0) return 0 2011 2012 // Use a for loop to avoid recursion 2013 var loweredCase = false 2014 for (;;) { 2015 switch (encoding) { 2016 case 'ascii': 2017 case 'latin1': 2018 case 'binary': 2019 return len 2020 case 'utf8': 2021 case 'utf-8': 2022 case undefined: 2023 return utf8ToBytes(string).length 2024 case 'ucs2': 2025 case 'ucs-2': 2026 case 'utf16le': 2027 case 'utf-16le': 2028 return len * 2 2029 case 'hex': 2030 return len >>> 1 2031 case 'base64': 2032 return base64ToBytes(string).length 2033 default: 2034 if (loweredCase) return utf8ToBytes(string).length // assume utf8 2035 encoding = ('' + encoding).toLowerCase() 2036 loweredCase = true 2037 } 2038 } 2039 } 2040 Buffer.byteLength = byteLength 2041 2042 function slowToString (encoding, start, end) { 2043 var loweredCase = false 2044 2045 // No need to verify that "this.length <= MAX_UINT32" since it's a read-only 2046 // property of a typed array. 2047 2048 // This behaves neither like String nor Uint8Array in that we set start/end 2049 // to their upper/lower bounds if the value passed is out of range. 2050 // undefined is handled specially as per ECMA-262 6th Edition, 2051 // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization. 2052 if (start === undefined || start < 0) { 2053 start = 0 2054 } 2055 // Return early if start > this.length. Done here to prevent potential uint32 2056 // coercion fail below. 2057 if (start > this.length) { 2058 return '' 2059 } 2060 2061 if (end === undefined || end > this.length) { 2062 end = this.length 2063 } 2064 2065 if (end <= 0) { 2066 return '' 2067 } 2068 2069 // Force coersion to uint32. This will also coerce falsey/NaN values to 0. 2070 end >>>= 0 2071 start >>>= 0 2072 2073 if (end <= start) { 2074 return '' 2075 } 2076 2077 if (!encoding) encoding = 'utf8' 2078 2079 while (true) { 2080 switch (encoding) { 2081 case 'hex': 2082 return hexSlice(this, start, end) 2083 2084 case 'utf8': 2085 case 'utf-8': 2086 return utf8Slice(this, start, end) 2087 2088 case 'ascii': 2089 return asciiSlice(this, start, end) 2090 2091 case 'latin1': 2092 case 'binary': 2093 return latin1Slice(this, start, end) 2094 2095 case 'base64': 2096 return base64Slice(this, start, end) 2097 2098 case 'ucs2': 2099 case 'ucs-2': 2100 case 'utf16le': 2101 case 'utf-16le': 2102 return utf16leSlice(this, start, end) 2103 2104 default: 2105 if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) 2106 encoding = (encoding + '').toLowerCase() 2107 loweredCase = true 2108 } 2109 } 2110 } 2111 2112 // The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect 2113 // Buffer instances. 2114 Buffer.prototype._isBuffer = true 2115 2116 function swap (b, n, m) { 2117 var i = b[n] 2118 b[n] = b[m] 2119 b[m] = i 2120 } 2121 2122 Buffer.prototype.swap16 = function swap16 () { 2123 var len = this.length 2124 if (len % 2 !== 0) { 2125 throw new RangeError('Buffer size must be a multiple of 16-bits') 2126 } 2127 for (var i = 0; i < len; i += 2) { 2128 swap(this, i, i + 1) 2129 } 2130 return this 2131 } 2132 2133 Buffer.prototype.swap32 = function swap32 () { 2134 var len = this.length 2135 if (len % 4 !== 0) { 2136 throw new RangeError('Buffer size must be a multiple of 32-bits') 2137 } 2138 for (var i = 0; i < len; i += 4) { 2139 swap(this, i, i + 3) 2140 swap(this, i + 1, i + 2) 2141 } 2142 return this 2143 } 2144 2145 Buffer.prototype.swap64 = function swap64 () { 2146 var len = this.length 2147 if (len % 8 !== 0) { 2148 throw new RangeError('Buffer size must be a multiple of 64-bits') 2149 } 2150 for (var i = 0; i < len; i += 8) { 2151 swap(this, i, i + 7) 2152 swap(this, i + 1, i + 6) 2153 swap(this, i + 2, i + 5) 2154 swap(this, i + 3, i + 4) 2155 } 2156 return this 2157 } 2158 2159 Buffer.prototype.toString = function toString () { 2160 var length = this.length | 0 2161 if (length === 0) return '' 2162 if (arguments.length === 0) return utf8Slice(this, 0, length) 2163 return slowToString.apply(this, arguments) 2164 } 2165 2166 Buffer.prototype.equals = function equals (b) { 2167 if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') 2168 if (this === b) return true 2169 return Buffer.compare(this, b) === 0 2170 } 2171 2172 Buffer.prototype.inspect = function inspect () { 2173 var str = '' 2174 var max = exports.INSPECT_MAX_BYTES 2175 if (this.length > 0) { 2176 str = this.toString('hex', 0, max).match(/.{2}/g).join(' ') 2177 if (this.length > max) str += ' ... ' 2178 } 2179 return '<Buffer ' + str + '>' 2180 } 2181 2182 Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) { 2183 if (!Buffer.isBuffer(target)) { 2184 throw new TypeError('Argument must be a Buffer') 2185 } 2186 2187 if (start === undefined) { 2188 start = 0 2189 } 2190 if (end === undefined) { 2191 end = target ? target.length : 0 2192 } 2193 if (thisStart === undefined) { 2194 thisStart = 0 2195 } 2196 if (thisEnd === undefined) { 2197 thisEnd = this.length 2198 } 2199 2200 if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) { 2201 throw new RangeError('out of range index') 2202 } 2203 2204 if (thisStart >= thisEnd && start >= end) { 2205 return 0 2206 } 2207 if (thisStart >= thisEnd) { 2208 return -1 2209 } 2210 if (start >= end) { 2211 return 1 2212 } 2213 2214 start >>>= 0 2215 end >>>= 0 2216 thisStart >>>= 0 2217 thisEnd >>>= 0 2218 2219 if (this === target) return 0 2220 2221 var x = thisEnd - thisStart 2222 var y = end - start 2223 var len = Math.min(x, y) 2224 2225 var thisCopy = this.slice(thisStart, thisEnd) 2226 var targetCopy = target.slice(start, end) 2227 2228 for (var i = 0; i < len; ++i) { 2229 if (thisCopy[i] !== targetCopy[i]) { 2230 x = thisCopy[i] 2231 y = targetCopy[i] 2232 break 2233 } 2234 } 2235 2236 if (x < y) return -1 2237 if (y < x) return 1 2238 return 0 2239 } 2240 2241 // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`, 2242 // OR the last index of `val` in `buffer` at offset <= `byteOffset`. 2243 // 2244 // Arguments: 2245 // - buffer - a Buffer to search 2246 // - val - a string, Buffer, or number 2247 // - byteOffset - an index into `buffer`; will be clamped to an int32 2248 // - encoding - an optional encoding, relevant is val is a string 2249 // - dir - true for indexOf, false for lastIndexOf 2250 function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) { 2251 // Empty buffer means no match 2252 if (buffer.length === 0) return -1 2253 2254 // Normalize byteOffset 2255 if (typeof byteOffset === 'string') { 2256 encoding = byteOffset 2257 byteOffset = 0 2258 } else if (byteOffset > 0x7fffffff) { 2259 byteOffset = 0x7fffffff 2260 } else if (byteOffset < -0x80000000) { 2261 byteOffset = -0x80000000 2262 } 2263 byteOffset = +byteOffset // Coerce to Number. 2264 if (isNaN(byteOffset)) { 2265 // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer 2266 byteOffset = dir ? 0 : (buffer.length - 1) 2267 } 2268 2269 // Normalize byteOffset: negative offsets start from the end of the buffer 2270 if (byteOffset < 0) byteOffset = buffer.length + byteOffset 2271 if (byteOffset >= buffer.length) { 2272 if (dir) return -1 2273 else byteOffset = buffer.length - 1 2274 } else if (byteOffset < 0) { 2275 if (dir) byteOffset = 0 2276 else return -1 2277 } 2278 2279 // Normalize val 2280 if (typeof val === 'string') { 2281 val = Buffer.from(val, encoding) 2282 } 2283 2284 // Finally, search either indexOf (if dir is true) or lastIndexOf 2285 if (Buffer.isBuffer(val)) { 2286 // Special case: looking for empty string/buffer always fails 2287 if (val.length === 0) { 2288 return -1 2289 } 2290 return arrayIndexOf(buffer, val, byteOffset, encoding, dir) 2291 } else if (typeof val === 'number') { 2292 val = val & 0xFF // Search for a byte value [0-255] 2293 if (Buffer.TYPED_ARRAY_SUPPORT && 2294 typeof Uint8Array.prototype.indexOf === 'function') { 2295 if (dir) { 2296 return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset) 2297 } else { 2298 return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset) 2299 } 2300 } 2301 return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir) 2302 } 2303 2304 throw new TypeError('val must be string, number or Buffer') 2305 } 2306 2307 function arrayIndexOf (arr, val, byteOffset, encoding, dir) { 2308 var indexSize = 1 2309 var arrLength = arr.length 2310 var valLength = val.length 2311 2312 if (encoding !== undefined) { 2313 encoding = String(encoding).toLowerCase() 2314 if (encoding === 'ucs2' || encoding === 'ucs-2' || 2315 encoding === 'utf16le' || encoding === 'utf-16le') { 2316 if (arr.length < 2 || val.length < 2) { 2317 return -1 2318 } 2319 indexSize = 2 2320 arrLength /= 2 2321 valLength /= 2 2322 byteOffset /= 2 2323 } 2324 } 2325 2326 function read (buf, i) { 2327 if (indexSize === 1) { 2328 return buf[i] 2329 } else { 2330 return buf.readUInt16BE(i * indexSize) 2331 } 2332 } 2333 2334 var i 2335 if (dir) { 2336 var foundIndex = -1 2337 for (i = byteOffset; i < arrLength; i++) { 2338 if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) { 2339 if (foundIndex === -1) foundIndex = i 2340 if (i - foundIndex + 1 === valLength) return foundIndex * indexSize 2341 } else { 2342 if (foundIndex !== -1) i -= i - foundIndex 2343 foundIndex = -1 2344 } 2345 } 2346 } else { 2347 if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength 2348 for (i = byteOffset; i >= 0; i--) { 2349 var found = true 2350 for (var j = 0; j < valLength; j++) { 2351 if (read(arr, i + j) !== read(val, j)) { 2352 found = false 2353 break 2354 } 2355 } 2356 if (found) return i 2357 } 2358 } 2359 2360 return -1 2361 } 2362 2363 Buffer.prototype.includes = function includes (val, byteOffset, encoding) { 2364 return this.indexOf(val, byteOffset, encoding) !== -1 2365 } 2366 2367 Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) { 2368 return bidirectionalIndexOf(this, val, byteOffset, encoding, true) 2369 } 2370 2371 Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) { 2372 return bidirectionalIndexOf(this, val, byteOffset, encoding, false) 2373 } 2374 2375 function hexWrite (buf, string, offset, length) { 2376 offset = Number(offset) || 0 2377 var remaining = buf.length - offset 2378 if (!length) { 2379 length = remaining 2380 } else { 2381 length = Number(length) 2382 if (length > remaining) { 2383 length = remaining 2384 } 2385 } 2386 2387 // must be an even number of digits 2388 var strLen = string.length 2389 if (strLen % 2 !== 0) throw new TypeError('Invalid hex string') 2390 2391 if (length > strLen / 2) { 2392 length = strLen / 2 2393 } 2394 for (var i = 0; i < length; ++i) { 2395 var parsed = parseInt(string.substr(i * 2, 2), 16) 2396 if (isNaN(parsed)) return i 2397 buf[offset + i] = parsed 2398 } 2399 return i 2400 } 2401 2402 function utf8Write (buf, string, offset, length) { 2403 return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length) 2404 } 2405 2406 function asciiWrite (buf, string, offset, length) { 2407 return blitBuffer(asciiToBytes(string), buf, offset, length) 2408 } 2409 2410 function latin1Write (buf, string, offset, length) { 2411 return asciiWrite(buf, string, offset, length) 2412 } 2413 2414 function base64Write (buf, string, offset, length) { 2415 return blitBuffer(base64ToBytes(string), buf, offset, length) 2416 } 2417 2418 function ucs2Write (buf, string, offset, length) { 2419 return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length) 2420 } 2421 2422 Buffer.prototype.write = function write (string, offset, length, encoding) { 2423 // Buffer#write(string) 2424 if (offset === undefined) { 2425 encoding = 'utf8' 2426 length = this.length 2427 offset = 0 2428 // Buffer#write(string, encoding) 2429 } else if (length === undefined && typeof offset === 'string') { 2430 encoding = offset 2431 length = this.length 2432 offset = 0 2433 // Buffer#write(string, offset[, length][, encoding]) 2434 } else if (isFinite(offset)) { 2435 offset = offset | 0 2436 if (isFinite(length)) { 2437 length = length | 0 2438 if (encoding === undefined) encoding = 'utf8' 2439 } else { 2440 encoding = length 2441 length = undefined 2442 } 2443 // legacy write(string, encoding, offset, length) - remove in v0.13 2444 } else { 2445 throw new Error( 2446 'Buffer.write(string, encoding, offset[, length]) is no longer supported' 2447 ) 2448 } 2449 2450 var remaining = this.length - offset 2451 if (length === undefined || length > remaining) length = remaining 2452 2453 if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) { 2454 throw new RangeError('Attempt to write outside buffer bounds') 2455 } 2456 2457 if (!encoding) encoding = 'utf8' 2458 2459 var loweredCase = false 2460 for (;;) { 2461 switch (encoding) { 2462 case 'hex': 2463 return hexWrite(this, string, offset, length) 2464 2465 case 'utf8': 2466 case 'utf-8': 2467 return utf8Write(this, string, offset, length) 2468 2469 case 'ascii': 2470 return asciiWrite(this, string, offset, length) 2471 2472 case 'latin1': 2473 case 'binary': 2474 return latin1Write(this, string, offset, length) 2475 2476 case 'base64': 2477 // Warning: maxLength not taken into account in base64Write 2478 return base64Write(this, string, offset, length) 2479 2480 case 'ucs2': 2481 case 'ucs-2': 2482 case 'utf16le': 2483 case 'utf-16le': 2484 return ucs2Write(this, string, offset, length) 2485 2486 default: 2487 if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) 2488 encoding = ('' + encoding).toLowerCase() 2489 loweredCase = true 2490 } 2491 } 2492 } 2493 2494 Buffer.prototype.toJSON = function toJSON () { 2495 return { 2496 type: 'Buffer', 2497 data: Array.prototype.slice.call(this._arr || this, 0) 2498 } 2499 } 2500 2501 function base64Slice (buf, start, end) { 2502 if (start === 0 && end === buf.length) { 2503 return base64.fromByteArray(buf) 2504 } else { 2505 return base64.fromByteArray(buf.slice(start, end)) 2506 } 2507 } 2508 2509 function utf8Slice (buf, start, end) { 2510 end = Math.min(buf.length, end) 2511 var res = [] 2512 2513 var i = start 2514 while (i < end) { 2515 var firstByte = buf[i] 2516 var codePoint = null 2517 var bytesPerSequence = (firstByte > 0xEF) ? 4 2518 : (firstByte > 0xDF) ? 3 2519 : (firstByte > 0xBF) ? 2 2520 : 1 2521 2522 if (i + bytesPerSequence <= end) { 2523 var secondByte, thirdByte, fourthByte, tempCodePoint 2524 2525 switch (bytesPerSequence) { 2526 case 1: 2527 if (firstByte < 0x80) { 2528 codePoint = firstByte 2529 } 2530 break 2531 case 2: 2532 secondByte = buf[i + 1] 2533 if ((secondByte & 0xC0) === 0x80) { 2534 tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F) 2535 if (tempCodePoint > 0x7F) { 2536 codePoint = tempCodePoint 2537 } 2538 } 2539 break 2540 case 3: 2541 secondByte = buf[i + 1] 2542 thirdByte = buf[i + 2] 2543 if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) { 2544 tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F) 2545 if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) { 2546 codePoint = tempCodePoint 2547 } 2548 } 2549 break 2550 case 4: 2551 secondByte = buf[i + 1] 2552 thirdByte = buf[i + 2] 2553 fourthByte = buf[i + 3] 2554 if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) { 2555 tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F) 2556 if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) { 2557 codePoint = tempCodePoint 2558 } 2559 } 2560 } 2561 } 2562 2563 if (codePoint === null) { 2564 // we did not generate a valid codePoint so insert a 2565 // replacement char (U+FFFD) and advance only 1 byte 2566 codePoint = 0xFFFD 2567 bytesPerSequence = 1 2568 } else if (codePoint > 0xFFFF) { 2569 // encode to utf16 (surrogate pair dance) 2570 codePoint -= 0x10000 2571 res.push(codePoint >>> 10 & 0x3FF | 0xD800) 2572 codePoint = 0xDC00 | codePoint & 0x3FF 2573 } 2574 2575 res.push(codePoint) 2576 i += bytesPerSequence 2577 } 2578 2579 return decodeCodePointsArray(res) 2580 } 2581 2582 // Based on http://stackoverflow.com/a/22747272/680742, the browser with 2583 // the lowest limit is Chrome, with 0x10000 args. 2584 // We go 1 magnitude less, for safety 2585 var MAX_ARGUMENTS_LENGTH = 0x1000 2586 2587 function decodeCodePointsArray (codePoints) { 2588 var len = codePoints.length 2589 if (len <= MAX_ARGUMENTS_LENGTH) { 2590 return String.fromCharCode.apply(String, codePoints) // avoid extra slice() 2591 } 2592 2593 // Decode in chunks to avoid "call stack size exceeded". 2594 var res = '' 2595 var i = 0 2596 while (i < len) { 2597 res += String.fromCharCode.apply( 2598 String, 2599 codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH) 2600 ) 2601 } 2602 return res 2603 } 2604 2605 function asciiSlice (buf, start, end) { 2606 var ret = '' 2607 end = Math.min(buf.length, end) 2608 2609 for (var i = start; i < end; ++i) { 2610 ret += String.fromCharCode(buf[i] & 0x7F) 2611 } 2612 return ret 2613 } 2614 2615 function latin1Slice (buf, start, end) { 2616 var ret = '' 2617 end = Math.min(buf.length, end) 2618 2619 for (var i = start; i < end; ++i) { 2620 ret += String.fromCharCode(buf[i]) 2621 } 2622 return ret 2623 } 2624 2625 function hexSlice (buf, start, end) { 2626 var len = buf.length 2627 2628 if (!start || start < 0) start = 0 2629 if (!end || end < 0 || end > len) end = len 2630 2631 var out = '' 2632 for (var i = start; i < end; ++i) { 2633 out += toHex(buf[i]) 2634 } 2635 return out 2636 } 2637 2638 function utf16leSlice (buf, start, end) { 2639 var bytes = buf.slice(start, end) 2640 var res = '' 2641 for (var i = 0; i < bytes.length; i += 2) { 2642 res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256) 2643 } 2644 return res 2645 } 2646 2647 Buffer.prototype.slice = function slice (start, end) { 2648 var len = this.length 2649 start = ~~start 2650 end = end === undefined ? len : ~~end 2651 2652 if (start < 0) { 2653 start += len 2654 if (start < 0) start = 0 2655 } else if (start > len) { 2656 start = len 2657 } 2658 2659 if (end < 0) { 2660 end += len 2661 if (end < 0) end = 0 2662 } else if (end > len) { 2663 end = len 2664 } 2665 2666 if (end < start) end = start 2667 2668 var newBuf 2669 if (Buffer.TYPED_ARRAY_SUPPORT) { 2670 newBuf = this.subarray(start, end) 2671 newBuf.__proto__ = Buffer.prototype 2672 } else { 2673 var sliceLen = end - start 2674 newBuf = new Buffer(sliceLen, undefined) 2675 for (var i = 0; i < sliceLen; ++i) { 2676 newBuf[i] = this[i + start] 2677 } 2678 } 2679 2680 return newBuf 2681 } 2682 2683 /* 2684 * Need to make sure that buffer isn't trying to write out of bounds. 2685 */ 2686 function checkOffset (offset, ext, length) { 2687 if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint') 2688 if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length') 2689 } 2690 2691 Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) { 2692 offset = offset | 0 2693 byteLength = byteLength | 0 2694 if (!noAssert) checkOffset(offset, byteLength, this.length) 2695 2696 var val = this[offset] 2697 var mul = 1 2698 var i = 0 2699 while (++i < byteLength && (mul *= 0x100)) { 2700 val += this[offset + i] * mul 2701 } 2702 2703 return val 2704 } 2705 2706 Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) { 2707 offset = offset | 0 2708 byteLength = byteLength | 0 2709 if (!noAssert) { 2710 checkOffset(offset, byteLength, this.length) 2711 } 2712 2713 var val = this[offset + --byteLength] 2714 var mul = 1 2715 while (byteLength > 0 && (mul *= 0x100)) { 2716 val += this[offset + --byteLength] * mul 2717 } 2718 2719 return val 2720 } 2721 2722 Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) { 2723 if (!noAssert) checkOffset(offset, 1, this.length) 2724 return this[offset] 2725 } 2726 2727 Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) { 2728 if (!noAssert) checkOffset(offset, 2, this.length) 2729 return this[offset] | (this[offset + 1] << 8) 2730 } 2731 2732 Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) { 2733 if (!noAssert) checkOffset(offset, 2, this.length) 2734 return (this[offset] << 8) | this[offset + 1] 2735 } 2736 2737 Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) { 2738 if (!noAssert) checkOffset(offset, 4, this.length) 2739 2740 return ((this[offset]) | 2741 (this[offset + 1] << 8) | 2742 (this[offset + 2] << 16)) + 2743 (this[offset + 3] * 0x1000000) 2744 } 2745 2746 Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) { 2747 if (!noAssert) checkOffset(offset, 4, this.length) 2748 2749 return (this[offset] * 0x1000000) + 2750 ((this[offset + 1] << 16) | 2751 (this[offset + 2] << 8) | 2752 this[offset + 3]) 2753 } 2754 2755 Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) { 2756 offset = offset | 0 2757 byteLength = byteLength | 0 2758 if (!noAssert) checkOffset(offset, byteLength, this.length) 2759 2760 var val = this[offset] 2761 var mul = 1 2762 var i = 0 2763 while (++i < byteLength && (mul *= 0x100)) { 2764 val += this[offset + i] * mul 2765 } 2766 mul *= 0x80 2767 2768 if (val >= mul) val -= Math.pow(2, 8 * byteLength) 2769 2770 return val 2771 } 2772 2773 Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) { 2774 offset = offset | 0 2775 byteLength = byteLength | 0 2776 if (!noAssert) checkOffset(offset, byteLength, this.length) 2777 2778 var i = byteLength 2779 var mul = 1 2780 var val = this[offset + --i] 2781 while (i > 0 && (mul *= 0x100)) { 2782 val += this[offset + --i] * mul 2783 } 2784 mul *= 0x80 2785 2786 if (val >= mul) val -= Math.pow(2, 8 * byteLength) 2787 2788 return val 2789 } 2790 2791 Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) { 2792 if (!noAssert) checkOffset(offset, 1, this.length) 2793 if (!(this[offset] & 0x80)) return (this[offset]) 2794 return ((0xff - this[offset] + 1) * -1) 2795 } 2796 2797 Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) { 2798 if (!noAssert) checkOffset(offset, 2, this.length) 2799 var val = this[offset] | (this[offset + 1] << 8) 2800 return (val & 0x8000) ? val | 0xFFFF0000 : val 2801 } 2802 2803 Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) { 2804 if (!noAssert) checkOffset(offset, 2, this.length) 2805 var val = this[offset + 1] | (this[offset] << 8) 2806 return (val & 0x8000) ? val | 0xFFFF0000 : val 2807 } 2808 2809 Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) { 2810 if (!noAssert) checkOffset(offset, 4, this.length) 2811 2812 return (this[offset]) | 2813 (this[offset + 1] << 8) | 2814 (this[offset + 2] << 16) | 2815 (this[offset + 3] << 24) 2816 } 2817 2818 Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) { 2819 if (!noAssert) checkOffset(offset, 4, this.length) 2820 2821 return (this[offset] << 24) | 2822 (this[offset + 1] << 16) | 2823 (this[offset + 2] << 8) | 2824 (this[offset + 3]) 2825 } 2826 2827 Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) { 2828 if (!noAssert) checkOffset(offset, 4, this.length) 2829 return ieee754.read(this, offset, true, 23, 4) 2830 } 2831 2832 Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) { 2833 if (!noAssert) checkOffset(offset, 4, this.length) 2834 return ieee754.read(this, offset, false, 23, 4) 2835 } 2836 2837 Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) { 2838 if (!noAssert) checkOffset(offset, 8, this.length) 2839 return ieee754.read(this, offset, true, 52, 8) 2840 } 2841 2842 Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) { 2843 if (!noAssert) checkOffset(offset, 8, this.length) 2844 return ieee754.read(this, offset, false, 52, 8) 2845 } 2846 2847 function checkInt (buf, value, offset, ext, max, min) { 2848 if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance') 2849 if (value > max || value < min) throw new RangeError('"value" argument is out of bounds') 2850 if (offset + ext > buf.length) throw new RangeError('Index out of range') 2851 } 2852 2853 Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) { 2854 value = +value 2855 offset = offset | 0 2856 byteLength = byteLength | 0 2857 if (!noAssert) { 2858 var maxBytes = Math.pow(2, 8 * byteLength) - 1 2859 checkInt(this, value, offset, byteLength, maxBytes, 0) 2860 } 2861 2862 var mul = 1 2863 var i = 0 2864 this[offset] = value & 0xFF 2865 while (++i < byteLength && (mul *= 0x100)) { 2866 this[offset + i] = (value / mul) & 0xFF 2867 } 2868 2869 return offset + byteLength 2870 } 2871 2872 Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) { 2873 value = +value 2874 offset = offset | 0 2875 byteLength = byteLength | 0 2876 if (!noAssert) { 2877 var maxBytes = Math.pow(2, 8 * byteLength) - 1 2878 checkInt(this, value, offset, byteLength, maxBytes, 0) 2879 } 2880 2881 var i = byteLength - 1 2882 var mul = 1 2883 this[offset + i] = value & 0xFF 2884 while (--i >= 0 && (mul *= 0x100)) { 2885 this[offset + i] = (value / mul) & 0xFF 2886 } 2887 2888 return offset + byteLength 2889 } 2890 2891 Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) { 2892 value = +value 2893 offset = offset | 0 2894 if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0) 2895 if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) 2896 this[offset] = (value & 0xff) 2897 return offset + 1 2898 } 2899 2900 function objectWriteUInt16 (buf, value, offset, littleEndian) { 2901 if (value < 0) value = 0xffff + value + 1 2902 for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) { 2903 buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>> 2904 (littleEndian ? i : 1 - i) * 8 2905 } 2906 } 2907 2908 Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) { 2909 value = +value 2910 offset = offset | 0 2911 if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) 2912 if (Buffer.TYPED_ARRAY_SUPPORT) { 2913 this[offset] = (value & 0xff) 2914 this[offset + 1] = (value >>> 8) 2915 } else { 2916 objectWriteUInt16(this, value, offset, true) 2917 } 2918 return offset + 2 2919 } 2920 2921 Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) { 2922 value = +value 2923 offset = offset | 0 2924 if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) 2925 if (Buffer.TYPED_ARRAY_SUPPORT) { 2926 this[offset] = (value >>> 8) 2927 this[offset + 1] = (value & 0xff) 2928 } else { 2929 objectWriteUInt16(this, value, offset, false) 2930 } 2931 return offset + 2 2932 } 2933 2934 function objectWriteUInt32 (buf, value, offset, littleEndian) { 2935 if (value < 0) value = 0xffffffff + value + 1 2936 for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) { 2937 buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff 2938 } 2939 } 2940 2941 Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) { 2942 value = +value 2943 offset = offset | 0 2944 if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) 2945 if (Buffer.TYPED_ARRAY_SUPPORT) { 2946 this[offset + 3] = (value >>> 24) 2947 this[offset + 2] = (value >>> 16) 2948 this[offset + 1] = (value >>> 8) 2949 this[offset] = (value & 0xff) 2950 } else { 2951 objectWriteUInt32(this, value, offset, true) 2952 } 2953 return offset + 4 2954 } 2955 2956 Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) { 2957 value = +value 2958 offset = offset | 0 2959 if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) 2960 if (Buffer.TYPED_ARRAY_SUPPORT) { 2961 this[offset] = (value >>> 24) 2962 this[offset + 1] = (value >>> 16) 2963 this[offset + 2] = (value >>> 8) 2964 this[offset + 3] = (value & 0xff) 2965 } else { 2966 objectWriteUInt32(this, value, offset, false) 2967 } 2968 return offset + 4 2969 } 2970 2971 Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) { 2972 value = +value 2973 offset = offset | 0 2974 if (!noAssert) { 2975 var limit = Math.pow(2, 8 * byteLength - 1) 2976 2977 checkInt(this, value, offset, byteLength, limit - 1, -limit) 2978 } 2979 2980 var i = 0 2981 var mul = 1 2982 var sub = 0 2983 this[offset] = value & 0xFF 2984 while (++i < byteLength && (mul *= 0x100)) { 2985 if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) { 2986 sub = 1 2987 } 2988 this[offset + i] = ((value / mul) >> 0) - sub & 0xFF 2989 } 2990 2991 return offset + byteLength 2992 } 2993 2994 Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) { 2995 value = +value 2996 offset = offset | 0 2997 if (!noAssert) { 2998 var limit = Math.pow(2, 8 * byteLength - 1) 2999 3000 checkInt(this, value, offset, byteLength, limit - 1, -limit) 3001 } 3002 3003 var i = byteLength - 1 3004 var mul = 1 3005 var sub = 0 3006 this[offset + i] = value & 0xFF 3007 while (--i >= 0 && (mul *= 0x100)) { 3008 if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) { 3009 sub = 1 3010 } 3011 this[offset + i] = ((value / mul) >> 0) - sub & 0xFF 3012 } 3013 3014 return offset + byteLength 3015 } 3016 3017 Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) { 3018 value = +value 3019 offset = offset | 0 3020 if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80) 3021 if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) 3022 if (value < 0) value = 0xff + value + 1 3023 this[offset] = (value & 0xff) 3024 return offset + 1 3025 } 3026 3027 Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) { 3028 value = +value 3029 offset = offset | 0 3030 if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) 3031 if (Buffer.TYPED_ARRAY_SUPPORT) { 3032 this[offset] = (value & 0xff) 3033 this[offset + 1] = (value >>> 8) 3034 } else { 3035 objectWriteUInt16(this, value, offset, true) 3036 } 3037 return offset + 2 3038 } 3039 3040 Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) { 3041 value = +value 3042 offset = offset | 0 3043 if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) 3044 if (Buffer.TYPED_ARRAY_SUPPORT) { 3045 this[offset] = (value >>> 8) 3046 this[offset + 1] = (value & 0xff) 3047 } else { 3048 objectWriteUInt16(this, value, offset, false) 3049 } 3050 return offset + 2 3051 } 3052 3053 Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) { 3054 value = +value 3055 offset = offset | 0 3056 if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) 3057 if (Buffer.TYPED_ARRAY_SUPPORT) { 3058 this[offset] = (value & 0xff) 3059 this[offset + 1] = (value >>> 8) 3060 this[offset + 2] = (value >>> 16) 3061 this[offset + 3] = (value >>> 24) 3062 } else { 3063 objectWriteUInt32(this, value, offset, true) 3064 } 3065 return offset + 4 3066 } 3067 3068 Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) { 3069 value = +value 3070 offset = offset | 0 3071 if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) 3072 if (value < 0) value = 0xffffffff + value + 1 3073 if (Buffer.TYPED_ARRAY_SUPPORT) { 3074 this[offset] = (value >>> 24) 3075 this[offset + 1] = (value >>> 16) 3076 this[offset + 2] = (value >>> 8) 3077 this[offset + 3] = (value & 0xff) 3078 } else { 3079 objectWriteUInt32(this, value, offset, false) 3080 } 3081 return offset + 4 3082 } 3083 3084 function checkIEEE754 (buf, value, offset, ext, max, min) { 3085 if (offset + ext > buf.length) throw new RangeError('Index out of range') 3086 if (offset < 0) throw new RangeError('Index out of range') 3087 } 3088 3089 function writeFloat (buf, value, offset, littleEndian, noAssert) { 3090 if (!noAssert) { 3091 checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38) 3092 } 3093 ieee754.write(buf, value, offset, littleEndian, 23, 4) 3094 return offset + 4 3095 } 3096 3097 Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) { 3098 return writeFloat(this, value, offset, true, noAssert) 3099 } 3100 3101 Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) { 3102 return writeFloat(this, value, offset, false, noAssert) 3103 } 3104 3105 function writeDouble (buf, value, offset, littleEndian, noAssert) { 3106 if (!noAssert) { 3107 checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308) 3108 } 3109 ieee754.write(buf, value, offset, littleEndian, 52, 8) 3110 return offset + 8 3111 } 3112 3113 Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) { 3114 return writeDouble(this, value, offset, true, noAssert) 3115 } 3116 3117 Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) { 3118 return writeDouble(this, value, offset, false, noAssert) 3119 } 3120 3121 // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) 3122 Buffer.prototype.copy = function copy (target, targetStart, start, end) { 3123 if (!start) start = 0 3124 if (!end && end !== 0) end = this.length 3125 if (targetStart >= target.length) targetStart = target.length 3126 if (!targetStart) targetStart = 0 3127 if (end > 0 && end < start) end = start 3128 3129 // Copy 0 bytes; we're done 3130 if (end === start) return 0 3131 if (target.length === 0 || this.length === 0) return 0 3132 3133 // Fatal error conditions 3134 if (targetStart < 0) { 3135 throw new RangeError('targetStart out of bounds') 3136 } 3137 if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds') 3138 if (end < 0) throw new RangeError('sourceEnd out of bounds') 3139 3140 // Are we oob? 3141 if (end > this.length) end = this.length 3142 if (target.length - targetStart < end - start) { 3143 end = target.length - targetStart + start 3144 } 3145 3146 var len = end - start 3147 var i 3148 3149 if (this === target && start < targetStart && targetStart < end) { 3150 // descending copy from end 3151 for (i = len - 1; i >= 0; --i) { 3152 target[i + targetStart] = this[i + start] 3153 } 3154 } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) { 3155 // ascending copy from start 3156 for (i = 0; i < len; ++i) { 3157 target[i + targetStart] = this[i + start] 3158 } 3159 } else { 3160 Uint8Array.prototype.set.call( 3161 target, 3162 this.subarray(start, start + len), 3163 targetStart 3164 ) 3165 } 3166 3167 return len 3168 } 3169 3170 // Usage: 3171 // buffer.fill(number[, offset[, end]]) 3172 // buffer.fill(buffer[, offset[, end]]) 3173 // buffer.fill(string[, offset[, end]][, encoding]) 3174 Buffer.prototype.fill = function fill (val, start, end, encoding) { 3175 // Handle string cases: 3176 if (typeof val === 'string') { 3177 if (typeof start === 'string') { 3178 encoding = start 3179 start = 0 3180 end = this.length 3181 } else if (typeof end === 'string') { 3182 encoding = end 3183 end = this.length 3184 } 3185 if (val.length === 1) { 3186 var code = val.charCodeAt(0) 3187 if (code < 256) { 3188 val = code 3189 } 3190 } 3191 if (encoding !== undefined && typeof encoding !== 'string') { 3192 throw new TypeError('encoding must be a string') 3193 } 3194 if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) { 3195 throw new TypeError('Unknown encoding: ' + encoding) 3196 } 3197 } else if (typeof val === 'number') { 3198 val = val & 255 3199 } 3200 3201 // Invalid ranges are not set to a default, so can range check early. 3202 if (start < 0 || this.length < start || this.length < end) { 3203 throw new RangeError('Out of range index') 3204 } 3205 3206 if (end <= start) { 3207 return this 3208 } 3209 3210 start = start >>> 0 3211 end = end === undefined ? this.length : end >>> 0 3212 3213 if (!val) val = 0 3214 3215 var i 3216 if (typeof val === 'number') { 3217 for (i = start; i < end; ++i) { 3218 this[i] = val 3219 } 3220 } else { 3221 var bytes = Buffer.isBuffer(val) 3222 ? val 3223 : utf8ToBytes(new Buffer(val, encoding).toString()) 3224 var len = bytes.length 3225 for (i = 0; i < end - start; ++i) { 3226 this[i + start] = bytes[i % len] 3227 } 3228 } 3229 3230 return this 3231 } 3232 3233 // HELPER FUNCTIONS 3234 // ================ 3235 3236 var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g 3237 3238 function base64clean (str) { 3239 // Node strips out invalid characters like \n and \t from the string, base64-js does not 3240 str = stringtrim(str).replace(INVALID_BASE64_RE, '') 3241 // Node converts strings with length < 2 to '' 3242 if (str.length < 2) return '' 3243 // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not 3244 while (str.length % 4 !== 0) { 3245 str = str + '=' 3246 } 3247 return str 3248 } 3249 3250 function stringtrim (str) { 3251 if (str.trim) return str.trim() 3252 return str.replace(/^\s+|\s+$/g, '') 3253 } 3254 3255 function toHex (n) { 3256 if (n < 16) return '0' + n.toString(16) 3257 return n.toString(16) 3258 } 3259 3260 function utf8ToBytes (string, units) { 3261 units = units || Infinity 3262 var codePoint 3263 var length = string.length 3264 var leadSurrogate = null 3265 var bytes = [] 3266 3267 for (var i = 0; i < length; ++i) { 3268 codePoint = string.charCodeAt(i) 3269 3270 // is surrogate component 3271 if (codePoint > 0xD7FF && codePoint < 0xE000) { 3272 // last char was a lead 3273 if (!leadSurrogate) { 3274 // no lead yet 3275 if (codePoint > 0xDBFF) { 3276 // unexpected trail 3277 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) 3278 continue 3279 } else if (i + 1 === length) { 3280 // unpaired lead 3281 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) 3282 continue 3283 } 3284 3285 // valid lead 3286 leadSurrogate = codePoint 3287 3288 continue 3289 } 3290 3291 // 2 leads in a row 3292 if (codePoint < 0xDC00) { 3293 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) 3294 leadSurrogate = codePoint 3295 continue 3296 } 3297 3298 // valid surrogate pair 3299 codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000 3300 } else if (leadSurrogate) { 3301 // valid bmp char, but last char was a lead 3302 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) 3303 } 3304 3305 leadSurrogate = null 3306 3307 // encode utf8 3308 if (codePoint < 0x80) { 3309 if ((units -= 1) < 0) break 3310 bytes.push(codePoint) 3311 } else if (codePoint < 0x800) { 3312 if ((units -= 2) < 0) break 3313 bytes.push( 3314 codePoint >> 0x6 | 0xC0, 3315 codePoint & 0x3F | 0x80 3316 ) 3317 } else if (codePoint < 0x10000) { 3318 if ((units -= 3) < 0) break 3319 bytes.push( 3320 codePoint >> 0xC | 0xE0, 3321 codePoint >> 0x6 & 0x3F | 0x80, 3322 codePoint & 0x3F | 0x80 3323 ) 3324 } else if (codePoint < 0x110000) { 3325 if ((units -= 4) < 0) break 3326 bytes.push( 3327 codePoint >> 0x12 | 0xF0, 3328 codePoint >> 0xC & 0x3F | 0x80, 3329 codePoint >> 0x6 & 0x3F | 0x80, 3330 codePoint & 0x3F | 0x80 3331 ) 3332 } else { 3333 throw new Error('Invalid code point') 3334 } 3335 } 3336 3337 return bytes 3338 } 3339 3340 function asciiToBytes (str) { 3341 var byteArray = [] 3342 for (var i = 0; i < str.length; ++i) { 3343 // Node's code seems to be doing this and not & 0x7F.. 3344 byteArray.push(str.charCodeAt(i) & 0xFF) 3345 } 3346 return byteArray 3347 } 3348 3349 function utf16leToBytes (str, units) { 3350 var c, hi, lo 3351 var byteArray = [] 3352 for (var i = 0; i < str.length; ++i) { 3353 if ((units -= 2) < 0) break 3354 3355 c = str.charCodeAt(i) 3356 hi = c >> 8 3357 lo = c % 256 3358 byteArray.push(lo) 3359 byteArray.push(hi) 3360 } 3361 3362 return byteArray 3363 } 3364 3365 function base64ToBytes (str) { 3366 return base64.toByteArray(base64clean(str)) 3367 } 3368 3369 function blitBuffer (src, dst, offset, length) { 3370 for (var i = 0; i < length; ++i) { 3371 if ((i + offset >= dst.length) || (i >= src.length)) break 3372 dst[i + offset] = src[i] 3373 } 3374 return i 3375 } 3376 3377 function isnan (val) { 3378 return val !== val // eslint-disable-line no-self-compare 3379 } 3380 3381 }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer) 3382 },{"base64-js":6,"buffer":7,"ieee754":14,"isarray":16}],8:[function(require,module,exports){ 3383 (function (Buffer){(function (){ 3384 /*! 3385 * The buffer module from node.js, for the browser. 3386 * 3387 * @author Feross Aboukhadijeh <https://feross.org> 3388 * @license MIT 3389 */ 3390 /* eslint-disable no-proto */ 3391 3392 'use strict' 3393 3394 var base64 = require('base64-js') 3395 var ieee754 = require('ieee754') 3396 var customInspectSymbol = 3397 (typeof Symbol === 'function' && typeof Symbol['for'] === 'function') // eslint-disable-line dot-notation 3398 ? Symbol['for']('nodejs.util.inspect.custom') // eslint-disable-line dot-notation 3399 : null 3400 3401 exports.Buffer = Buffer 3402 exports.SlowBuffer = SlowBuffer 3403 exports.INSPECT_MAX_BYTES = 50 3404 3405 var K_MAX_LENGTH = 0x7fffffff 3406 exports.kMaxLength = K_MAX_LENGTH 3407 3408 /** 3409 * If `Buffer.TYPED_ARRAY_SUPPORT`: 3410 * === true Use Uint8Array implementation (fastest) 3411 * === false Print warning and recommend using `buffer` v4.x which has an Object 3412 * implementation (most compatible, even IE6) 3413 * 3414 * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, 3415 * Opera 11.6+, iOS 4.2+. 3416 * 3417 * We report that the browser does not support typed arrays if the are not subclassable 3418 * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array` 3419 * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support 3420 * for __proto__ and has a buggy typed array implementation. 3421 */ 3422 Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport() 3423 3424 if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' && 3425 typeof console.error === 'function') { 3426 console.error( 3427 'This browser lacks typed array (Uint8Array) support which is required by ' + 3428 '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.' 3429 ) 3430 } 3431 3432 function typedArraySupport () { 3433 // Can typed array instances can be augmented? 3434 try { 3435 var arr = new Uint8Array(1) 3436 var proto = { foo: function () { return 42 } } 3437 Object.setPrototypeOf(proto, Uint8Array.prototype) 3438 Object.setPrototypeOf(arr, proto) 3439 return arr.foo() === 42 3440 } catch (e) { 3441 return false 3442 } 3443 } 3444 3445 Object.defineProperty(Buffer.prototype, 'parent', { 3446 enumerable: true, 3447 get: function () { 3448 if (!Buffer.isBuffer(this)) return undefined 3449 return this.buffer 3450 } 3451 }) 3452 3453 Object.defineProperty(Buffer.prototype, 'offset', { 3454 enumerable: true, 3455 get: function () { 3456 if (!Buffer.isBuffer(this)) return undefined 3457 return this.byteOffset 3458 } 3459 }) 3460 3461 function createBuffer (length) { 3462 if (length > K_MAX_LENGTH) { 3463 throw new RangeError('The value "' + length + '" is invalid for option "size"') 3464 } 3465 // Return an augmented `Uint8Array` instance 3466 var buf = new Uint8Array(length) 3467 Object.setPrototypeOf(buf, Buffer.prototype) 3468 return buf 3469 } 3470 3471 /** 3472 * The Buffer constructor returns instances of `Uint8Array` that have their 3473 * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of 3474 * `Uint8Array`, so the returned instances will have all the node `Buffer` methods 3475 * and the `Uint8Array` methods. Square bracket notation works as expected -- it 3476 * returns a single octet. 3477 * 3478 * The `Uint8Array` prototype remains unmodified. 3479 */ 3480 3481 function Buffer (arg, encodingOrOffset, length) { 3482 // Common case. 3483 if (typeof arg === 'number') { 3484 if (typeof encodingOrOffset === 'string') { 3485 throw new TypeError( 3486 'The "string" argument must be of type string. Received type number' 3487 ) 3488 } 3489 return allocUnsafe(arg) 3490 } 3491 return from(arg, encodingOrOffset, length) 3492 } 3493 3494 Buffer.poolSize = 8192 // not used by this implementation 3495 3496 function from (value, encodingOrOffset, length) { 3497 if (typeof value === 'string') { 3498 return fromString(value, encodingOrOffset) 3499 } 3500 3501 if (ArrayBuffer.isView(value)) { 3502 return fromArrayView(value) 3503 } 3504 3505 if (value == null) { 3506 throw new TypeError( 3507 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' + 3508 'or Array-like Object. Received type ' + (typeof value) 3509 ) 3510 } 3511 3512 if (isInstance(value, ArrayBuffer) || 3513 (value && isInstance(value.buffer, ArrayBuffer))) { 3514 return fromArrayBuffer(value, encodingOrOffset, length) 3515 } 3516 3517 if (typeof SharedArrayBuffer !== 'undefined' && 3518 (isInstance(value, SharedArrayBuffer) || 3519 (value && isInstance(value.buffer, SharedArrayBuffer)))) { 3520 return fromArrayBuffer(value, encodingOrOffset, length) 3521 } 3522 3523 if (typeof value === 'number') { 3524 throw new TypeError( 3525 'The "value" argument must not be of type number. Received type number' 3526 ) 3527 } 3528 3529 var valueOf = value.valueOf && value.valueOf() 3530 if (valueOf != null && valueOf !== value) { 3531 return Buffer.from(valueOf, encodingOrOffset, length) 3532 } 3533 3534 var b = fromObject(value) 3535 if (b) return b 3536 3537 if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null && 3538 typeof value[Symbol.toPrimitive] === 'function') { 3539 return Buffer.from( 3540 value[Symbol.toPrimitive]('string'), encodingOrOffset, length 3541 ) 3542 } 3543 3544 throw new TypeError( 3545 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' + 3546 'or Array-like Object. Received type ' + (typeof value) 3547 ) 3548 } 3549 3550 /** 3551 * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError 3552 * if value is a number. 3553 * Buffer.from(str[, encoding]) 3554 * Buffer.from(array) 3555 * Buffer.from(buffer) 3556 * Buffer.from(arrayBuffer[, byteOffset[, length]]) 3557 **/ 3558 Buffer.from = function (value, encodingOrOffset, length) { 3559 return from(value, encodingOrOffset, length) 3560 } 3561 3562 // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug: 3563 // https://github.com/feross/buffer/pull/148 3564 Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype) 3565 Object.setPrototypeOf(Buffer, Uint8Array) 3566 3567 function assertSize (size) { 3568 if (typeof size !== 'number') { 3569 throw new TypeError('"size" argument must be of type number') 3570 } else if (size < 0) { 3571 throw new RangeError('The value "' + size + '" is invalid for option "size"') 3572 } 3573 } 3574 3575 function alloc (size, fill, encoding) { 3576 assertSize(size) 3577 if (size <= 0) { 3578 return createBuffer(size) 3579 } 3580 if (fill !== undefined) { 3581 // Only pay attention to encoding if it's a string. This 3582 // prevents accidentally sending in a number that would 3583 // be interpreted as a start offset. 3584 return typeof encoding === 'string' 3585 ? createBuffer(size).fill(fill, encoding) 3586 : createBuffer(size).fill(fill) 3587 } 3588 return createBuffer(size) 3589 } 3590 3591 /** 3592 * Creates a new filled Buffer instance. 3593 * alloc(size[, fill[, encoding]]) 3594 **/ 3595 Buffer.alloc = function (size, fill, encoding) { 3596 return alloc(size, fill, encoding) 3597 } 3598 3599 function allocUnsafe (size) { 3600 assertSize(size) 3601 return createBuffer(size < 0 ? 0 : checked(size) | 0) 3602 } 3603 3604 /** 3605 * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance. 3606 * */ 3607 Buffer.allocUnsafe = function (size) { 3608 return allocUnsafe(size) 3609 } 3610 /** 3611 * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. 3612 */ 3613 Buffer.allocUnsafeSlow = function (size) { 3614 return allocUnsafe(size) 3615 } 3616 3617 function fromString (string, encoding) { 3618 if (typeof encoding !== 'string' || encoding === '') { 3619 encoding = 'utf8' 3620 } 3621 3622 if (!Buffer.isEncoding(encoding)) { 3623 throw new TypeError('Unknown encoding: ' + encoding) 3624 } 3625 3626 var length = byteLength(string, encoding) | 0 3627 var buf = createBuffer(length) 3628 3629 var actual = buf.write(string, encoding) 3630 3631 if (actual !== length) { 3632 // Writing a hex string, for example, that contains invalid characters will 3633 // cause everything after the first invalid character to be ignored. (e.g. 3634 // 'abxxcd' will be treated as 'ab') 3635 buf = buf.slice(0, actual) 3636 } 3637 3638 return buf 3639 } 3640 3641 function fromArrayLike (array) { 3642 var length = array.length < 0 ? 0 : checked(array.length) | 0 3643 var buf = createBuffer(length) 3644 for (var i = 0; i < length; i += 1) { 3645 buf[i] = array[i] & 255 3646 } 3647 return buf 3648 } 3649 3650 function fromArrayView (arrayView) { 3651 if (isInstance(arrayView, Uint8Array)) { 3652 var copy = new Uint8Array(arrayView) 3653 return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength) 3654 } 3655 return fromArrayLike(arrayView) 3656 } 3657 3658 function fromArrayBuffer (array, byteOffset, length) { 3659 if (byteOffset < 0 || array.byteLength < byteOffset) { 3660 throw new RangeError('"offset" is outside of buffer bounds') 3661 } 3662 3663 if (array.byteLength < byteOffset + (length || 0)) { 3664 throw new RangeError('"length" is outside of buffer bounds') 3665 } 3666 3667 var buf 3668 if (byteOffset === undefined && length === undefined) { 3669 buf = new Uint8Array(array) 3670 } else if (length === undefined) { 3671 buf = new Uint8Array(array, byteOffset) 3672 } else { 3673 buf = new Uint8Array(array, byteOffset, length) 3674 } 3675 3676 // Return an augmented `Uint8Array` instance 3677 Object.setPrototypeOf(buf, Buffer.prototype) 3678 3679 return buf 3680 } 3681 3682 function fromObject (obj) { 3683 if (Buffer.isBuffer(obj)) { 3684 var len = checked(obj.length) | 0 3685 var buf = createBuffer(len) 3686 3687 if (buf.length === 0) { 3688 return buf 3689 } 3690 3691 obj.copy(buf, 0, 0, len) 3692 return buf 3693 } 3694 3695 if (obj.length !== undefined) { 3696 if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) { 3697 return createBuffer(0) 3698 } 3699 return fromArrayLike(obj) 3700 } 3701 3702 if (obj.type === 'Buffer' && Array.isArray(obj.data)) { 3703 return fromArrayLike(obj.data) 3704 } 3705 } 3706 3707 function checked (length) { 3708 // Note: cannot use `length < K_MAX_LENGTH` here because that fails when 3709 // length is NaN (which is otherwise coerced to zero.) 3710 if (length >= K_MAX_LENGTH) { 3711 throw new RangeError('Attempt to allocate Buffer larger than maximum ' + 3712 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes') 3713 } 3714 return length | 0 3715 } 3716 3717 function SlowBuffer (length) { 3718 if (+length != length) { // eslint-disable-line eqeqeq 3719 length = 0 3720 } 3721 return Buffer.alloc(+length) 3722 } 3723 3724 Buffer.isBuffer = function isBuffer (b) { 3725 return b != null && b._isBuffer === true && 3726 b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false 3727 } 3728 3729 Buffer.compare = function compare (a, b) { 3730 if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength) 3731 if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength) 3732 if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) { 3733 throw new TypeError( 3734 'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array' 3735 ) 3736 } 3737 3738 if (a === b) return 0 3739 3740 var x = a.length 3741 var y = b.length 3742 3743 for (var i = 0, len = Math.min(x, y); i < len; ++i) { 3744 if (a[i] !== b[i]) { 3745 x = a[i] 3746 y = b[i] 3747 break 3748 } 3749 } 3750 3751 if (x < y) return -1 3752 if (y < x) return 1 3753 return 0 3754 } 3755 3756 Buffer.isEncoding = function isEncoding (encoding) { 3757 switch (String(encoding).toLowerCase()) { 3758 case 'hex': 3759 case 'utf8': 3760 case 'utf-8': 3761 case 'ascii': 3762 case 'latin1': 3763 case 'binary': 3764 case 'base64': 3765 case 'ucs2': 3766 case 'ucs-2': 3767 case 'utf16le': 3768 case 'utf-16le': 3769 return true 3770 default: 3771 return false 3772 } 3773 } 3774 3775 Buffer.concat = function concat (list, length) { 3776 if (!Array.isArray(list)) { 3777 throw new TypeError('"list" argument must be an Array of Buffers') 3778 } 3779 3780 if (list.length === 0) { 3781 return Buffer.alloc(0) 3782 } 3783 3784 var i 3785 if (length === undefined) { 3786 length = 0 3787 for (i = 0; i < list.length; ++i) { 3788 length += list[i].length 3789 } 3790 } 3791 3792 var buffer = Buffer.allocUnsafe(length) 3793 var pos = 0 3794 for (i = 0; i < list.length; ++i) { 3795 var buf = list[i] 3796 if (isInstance(buf, Uint8Array)) { 3797 if (pos + buf.length > buffer.length) { 3798 Buffer.from(buf).copy(buffer, pos) 3799 } else { 3800 Uint8Array.prototype.set.call( 3801 buffer, 3802 buf, 3803 pos 3804 ) 3805 } 3806 } else if (!Buffer.isBuffer(buf)) { 3807 throw new TypeError('"list" argument must be an Array of Buffers') 3808 } else { 3809 buf.copy(buffer, pos) 3810 } 3811 pos += buf.length 3812 } 3813 return buffer 3814 } 3815 3816 function byteLength (string, encoding) { 3817 if (Buffer.isBuffer(string)) { 3818 return string.length 3819 } 3820 if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) { 3821 return string.byteLength 3822 } 3823 if (typeof string !== 'string') { 3824 throw new TypeError( 3825 'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' + 3826 'Received type ' + typeof string 3827 ) 3828 } 3829 3830 var len = string.length 3831 var mustMatch = (arguments.length > 2 && arguments[2] === true) 3832 if (!mustMatch && len === 0) return 0 3833 3834 // Use a for loop to avoid recursion 3835 var loweredCase = false 3836 for (;;) { 3837 switch (encoding) { 3838 case 'ascii': 3839 case 'latin1': 3840 case 'binary': 3841 return len 3842 case 'utf8': 3843 case 'utf-8': 3844 return utf8ToBytes(string).length 3845 case 'ucs2': 3846 case 'ucs-2': 3847 case 'utf16le': 3848 case 'utf-16le': 3849 return len * 2 3850 case 'hex': 3851 return len >>> 1 3852 case 'base64': 3853 return base64ToBytes(string).length 3854 default: 3855 if (loweredCase) { 3856 return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8 3857 } 3858 encoding = ('' + encoding).toLowerCase() 3859 loweredCase = true 3860 } 3861 } 3862 } 3863 Buffer.byteLength = byteLength 3864 3865 function slowToString (encoding, start, end) { 3866 var loweredCase = false 3867 3868 // No need to verify that "this.length <= MAX_UINT32" since it's a read-only 3869 // property of a typed array. 3870 3871 // This behaves neither like String nor Uint8Array in that we set start/end 3872 // to their upper/lower bounds if the value passed is out of range. 3873 // undefined is handled specially as per ECMA-262 6th Edition, 3874 // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization. 3875 if (start === undefined || start < 0) { 3876 start = 0 3877 } 3878 // Return early if start > this.length. Done here to prevent potential uint32 3879 // coercion fail below. 3880 if (start > this.length) { 3881 return '' 3882 } 3883 3884 if (end === undefined || end > this.length) { 3885 end = this.length 3886 } 3887 3888 if (end <= 0) { 3889 return '' 3890 } 3891 3892 // Force coercion to uint32. This will also coerce falsey/NaN values to 0. 3893 end >>>= 0 3894 start >>>= 0 3895 3896 if (end <= start) { 3897 return '' 3898 } 3899 3900 if (!encoding) encoding = 'utf8' 3901 3902 while (true) { 3903 switch (encoding) { 3904 case 'hex': 3905 return hexSlice(this, start, end) 3906 3907 case 'utf8': 3908 case 'utf-8': 3909 return utf8Slice(this, start, end) 3910 3911 case 'ascii': 3912 return asciiSlice(this, start, end) 3913 3914 case 'latin1': 3915 case 'binary': 3916 return latin1Slice(this, start, end) 3917 3918 case 'base64': 3919 return base64Slice(this, start, end) 3920 3921 case 'ucs2': 3922 case 'ucs-2': 3923 case 'utf16le': 3924 case 'utf-16le': 3925 return utf16leSlice(this, start, end) 3926 3927 default: 3928 if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) 3929 encoding = (encoding + '').toLowerCase() 3930 loweredCase = true 3931 } 3932 } 3933 } 3934 3935 // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package) 3936 // to detect a Buffer instance. It's not possible to use `instanceof Buffer` 3937 // reliably in a browserify context because there could be multiple different 3938 // copies of the 'buffer' package in use. This method works even for Buffer 3939 // instances that were created from another copy of the `buffer` package. 3940 // See: https://github.com/feross/buffer/issues/154 3941 Buffer.prototype._isBuffer = true 3942 3943 function swap (b, n, m) { 3944 var i = b[n] 3945 b[n] = b[m] 3946 b[m] = i 3947 } 3948 3949 Buffer.prototype.swap16 = function swap16 () { 3950 var len = this.length 3951 if (len % 2 !== 0) { 3952 throw new RangeError('Buffer size must be a multiple of 16-bits') 3953 } 3954 for (var i = 0; i < len; i += 2) { 3955 swap(this, i, i + 1) 3956 } 3957 return this 3958 } 3959 3960 Buffer.prototype.swap32 = function swap32 () { 3961 var len = this.length 3962 if (len % 4 !== 0) { 3963 throw new RangeError('Buffer size must be a multiple of 32-bits') 3964 } 3965 for (var i = 0; i < len; i += 4) { 3966 swap(this, i, i + 3) 3967 swap(this, i + 1, i + 2) 3968 } 3969 return this 3970 } 3971 3972 Buffer.prototype.swap64 = function swap64 () { 3973 var len = this.length 3974 if (len % 8 !== 0) { 3975 throw new RangeError('Buffer size must be a multiple of 64-bits') 3976 } 3977 for (var i = 0; i < len; i += 8) { 3978 swap(this, i, i + 7) 3979 swap(this, i + 1, i + 6) 3980 swap(this, i + 2, i + 5) 3981 swap(this, i + 3, i + 4) 3982 } 3983 return this 3984 } 3985 3986 Buffer.prototype.toString = function toString () { 3987 var length = this.length 3988 if (length === 0) return '' 3989 if (arguments.length === 0) return utf8Slice(this, 0, length) 3990 return slowToString.apply(this, arguments) 3991 } 3992 3993 Buffer.prototype.toLocaleString = Buffer.prototype.toString 3994 3995 Buffer.prototype.equals = function equals (b) { 3996 if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') 3997 if (this === b) return true 3998 return Buffer.compare(this, b) === 0 3999 } 4000 4001 Buffer.prototype.inspect = function inspect () { 4002 var str = '' 4003 var max = exports.INSPECT_MAX_BYTES 4004 str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim() 4005 if (this.length > max) str += ' ... ' 4006 return '<Buffer ' + str + '>' 4007 } 4008 if (customInspectSymbol) { 4009 Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect 4010 } 4011 4012 Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) { 4013 if (isInstance(target, Uint8Array)) { 4014 target = Buffer.from(target, target.offset, target.byteLength) 4015 } 4016 if (!Buffer.isBuffer(target)) { 4017 throw new TypeError( 4018 'The "target" argument must be one of type Buffer or Uint8Array. ' + 4019 'Received type ' + (typeof target) 4020 ) 4021 } 4022 4023 if (start === undefined) { 4024 start = 0 4025 } 4026 if (end === undefined) { 4027 end = target ? target.length : 0 4028 } 4029 if (thisStart === undefined) { 4030 thisStart = 0 4031 } 4032 if (thisEnd === undefined) { 4033 thisEnd = this.length 4034 } 4035 4036 if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) { 4037 throw new RangeError('out of range index') 4038 } 4039 4040 if (thisStart >= thisEnd && start >= end) { 4041 return 0 4042 } 4043 if (thisStart >= thisEnd) { 4044 return -1 4045 } 4046 if (start >= end) { 4047 return 1 4048 } 4049 4050 start >>>= 0 4051 end >>>= 0 4052 thisStart >>>= 0 4053 thisEnd >>>= 0 4054 4055 if (this === target) return 0 4056 4057 var x = thisEnd - thisStart 4058 var y = end - start 4059 var len = Math.min(x, y) 4060 4061 var thisCopy = this.slice(thisStart, thisEnd) 4062 var targetCopy = target.slice(start, end) 4063 4064 for (var i = 0; i < len; ++i) { 4065 if (thisCopy[i] !== targetCopy[i]) { 4066 x = thisCopy[i] 4067 y = targetCopy[i] 4068 break 4069 } 4070 } 4071 4072 if (x < y) return -1 4073 if (y < x) return 1 4074 return 0 4075 } 4076 4077 // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`, 4078 // OR the last index of `val` in `buffer` at offset <= `byteOffset`. 4079 // 4080 // Arguments: 4081 // - buffer - a Buffer to search 4082 // - val - a string, Buffer, or number 4083 // - byteOffset - an index into `buffer`; will be clamped to an int32 4084 // - encoding - an optional encoding, relevant is val is a string 4085 // - dir - true for indexOf, false for lastIndexOf 4086 function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) { 4087 // Empty buffer means no match 4088 if (buffer.length === 0) return -1 4089 4090 // Normalize byteOffset 4091 if (typeof byteOffset === 'string') { 4092 encoding = byteOffset 4093 byteOffset = 0 4094 } else if (byteOffset > 0x7fffffff) { 4095 byteOffset = 0x7fffffff 4096 } else if (byteOffset < -0x80000000) { 4097 byteOffset = -0x80000000 4098 } 4099 byteOffset = +byteOffset // Coerce to Number. 4100 if (numberIsNaN(byteOffset)) { 4101 // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer 4102 byteOffset = dir ? 0 : (buffer.length - 1) 4103 } 4104 4105 // Normalize byteOffset: negative offsets start from the end of the buffer 4106 if (byteOffset < 0) byteOffset = buffer.length + byteOffset 4107 if (byteOffset >= buffer.length) { 4108 if (dir) return -1 4109 else byteOffset = buffer.length - 1 4110 } else if (byteOffset < 0) { 4111 if (dir) byteOffset = 0 4112 else return -1 4113 } 4114 4115 // Normalize val 4116 if (typeof val === 'string') { 4117 val = Buffer.from(val, encoding) 4118 } 4119 4120 // Finally, search either indexOf (if dir is true) or lastIndexOf 4121 if (Buffer.isBuffer(val)) { 4122 // Special case: looking for empty string/buffer always fails 4123 if (val.length === 0) { 4124 return -1 4125 } 4126 return arrayIndexOf(buffer, val, byteOffset, encoding, dir) 4127 } else if (typeof val === 'number') { 4128 val = val & 0xFF // Search for a byte value [0-255] 4129 if (typeof Uint8Array.prototype.indexOf === 'function') { 4130 if (dir) { 4131 return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset) 4132 } else { 4133 return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset) 4134 } 4135 } 4136 return arrayIndexOf(buffer, [val], byteOffset, encoding, dir) 4137 } 4138 4139 throw new TypeError('val must be string, number or Buffer') 4140 } 4141 4142 function arrayIndexOf (arr, val, byteOffset, encoding, dir) { 4143 var indexSize = 1 4144 var arrLength = arr.length 4145 var valLength = val.length 4146 4147 if (encoding !== undefined) { 4148 encoding = String(encoding).toLowerCase() 4149 if (encoding === 'ucs2' || encoding === 'ucs-2' || 4150 encoding === 'utf16le' || encoding === 'utf-16le') { 4151 if (arr.length < 2 || val.length < 2) { 4152 return -1 4153 } 4154 indexSize = 2 4155 arrLength /= 2 4156 valLength /= 2 4157 byteOffset /= 2 4158 } 4159 } 4160 4161 function read (buf, i) { 4162 if (indexSize === 1) { 4163 return buf[i] 4164 } else { 4165 return buf.readUInt16BE(i * indexSize) 4166 } 4167 } 4168 4169 var i 4170 if (dir) { 4171 var foundIndex = -1 4172 for (i = byteOffset; i < arrLength; i++) { 4173 if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) { 4174 if (foundIndex === -1) foundIndex = i 4175 if (i - foundIndex + 1 === valLength) return foundIndex * indexSize 4176 } else { 4177 if (foundIndex !== -1) i -= i - foundIndex 4178 foundIndex = -1 4179 } 4180 } 4181 } else { 4182 if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength 4183 for (i = byteOffset; i >= 0; i--) { 4184 var found = true 4185 for (var j = 0; j < valLength; j++) { 4186 if (read(arr, i + j) !== read(val, j)) { 4187 found = false 4188 break 4189 } 4190 } 4191 if (found) return i 4192 } 4193 } 4194 4195 return -1 4196 } 4197 4198 Buffer.prototype.includes = function includes (val, byteOffset, encoding) { 4199 return this.indexOf(val, byteOffset, encoding) !== -1 4200 } 4201 4202 Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) { 4203 return bidirectionalIndexOf(this, val, byteOffset, encoding, true) 4204 } 4205 4206 Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) { 4207 return bidirectionalIndexOf(this, val, byteOffset, encoding, false) 4208 } 4209 4210 function hexWrite (buf, string, offset, length) { 4211 offset = Number(offset) || 0 4212 var remaining = buf.length - offset 4213 if (!length) { 4214 length = remaining 4215 } else { 4216 length = Number(length) 4217 if (length > remaining) { 4218 length = remaining 4219 } 4220 } 4221 4222 var strLen = string.length 4223 4224 if (length > strLen / 2) { 4225 length = strLen / 2 4226 } 4227 for (var i = 0; i < length; ++i) { 4228 var parsed = parseInt(string.substr(i * 2, 2), 16) 4229 if (numberIsNaN(parsed)) return i 4230 buf[offset + i] = parsed 4231 } 4232 return i 4233 } 4234 4235 function utf8Write (buf, string, offset, length) { 4236 return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length) 4237 } 4238 4239 function asciiWrite (buf, string, offset, length) { 4240 return blitBuffer(asciiToBytes(string), buf, offset, length) 4241 } 4242 4243 function base64Write (buf, string, offset, length) { 4244 return blitBuffer(base64ToBytes(string), buf, offset, length) 4245 } 4246 4247 function ucs2Write (buf, string, offset, length) { 4248 return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length) 4249 } 4250 4251 Buffer.prototype.write = function write (string, offset, length, encoding) { 4252 // Buffer#write(string) 4253 if (offset === undefined) { 4254 encoding = 'utf8' 4255 length = this.length 4256 offset = 0 4257 // Buffer#write(string, encoding) 4258 } else if (length === undefined && typeof offset === 'string') { 4259 encoding = offset 4260 length = this.length 4261 offset = 0 4262 // Buffer#write(string, offset[, length][, encoding]) 4263 } else if (isFinite(offset)) { 4264 offset = offset >>> 0 4265 if (isFinite(length)) { 4266 length = length >>> 0 4267 if (encoding === undefined) encoding = 'utf8' 4268 } else { 4269 encoding = length 4270 length = undefined 4271 } 4272 } else { 4273 throw new Error( 4274 'Buffer.write(string, encoding, offset[, length]) is no longer supported' 4275 ) 4276 } 4277 4278 var remaining = this.length - offset 4279 if (length === undefined || length > remaining) length = remaining 4280 4281 if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) { 4282 throw new RangeError('Attempt to write outside buffer bounds') 4283 } 4284 4285 if (!encoding) encoding = 'utf8' 4286 4287 var loweredCase = false 4288 for (;;) { 4289 switch (encoding) { 4290 case 'hex': 4291 return hexWrite(this, string, offset, length) 4292 4293 case 'utf8': 4294 case 'utf-8': 4295 return utf8Write(this, string, offset, length) 4296 4297 case 'ascii': 4298 case 'latin1': 4299 case 'binary': 4300 return asciiWrite(this, string, offset, length) 4301 4302 case 'base64': 4303 // Warning: maxLength not taken into account in base64Write 4304 return base64Write(this, string, offset, length) 4305 4306 case 'ucs2': 4307 case 'ucs-2': 4308 case 'utf16le': 4309 case 'utf-16le': 4310 return ucs2Write(this, string, offset, length) 4311 4312 default: 4313 if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) 4314 encoding = ('' + encoding).toLowerCase() 4315 loweredCase = true 4316 } 4317 } 4318 } 4319 4320 Buffer.prototype.toJSON = function toJSON () { 4321 return { 4322 type: 'Buffer', 4323 data: Array.prototype.slice.call(this._arr || this, 0) 4324 } 4325 } 4326 4327 function base64Slice (buf, start, end) { 4328 if (start === 0 && end === buf.length) { 4329 return base64.fromByteArray(buf) 4330 } else { 4331 return base64.fromByteArray(buf.slice(start, end)) 4332 } 4333 } 4334 4335 function utf8Slice (buf, start, end) { 4336 end = Math.min(buf.length, end) 4337 var res = [] 4338 4339 var i = start 4340 while (i < end) { 4341 var firstByte = buf[i] 4342 var codePoint = null 4343 var bytesPerSequence = (firstByte > 0xEF) 4344 ? 4 4345 : (firstByte > 0xDF) 4346 ? 3 4347 : (firstByte > 0xBF) 4348 ? 2 4349 : 1 4350 4351 if (i + bytesPerSequence <= end) { 4352 var secondByte, thirdByte, fourthByte, tempCodePoint 4353 4354 switch (bytesPerSequence) { 4355 case 1: 4356 if (firstByte < 0x80) { 4357 codePoint = firstByte 4358 } 4359 break 4360 case 2: 4361 secondByte = buf[i + 1] 4362 if ((secondByte & 0xC0) === 0x80) { 4363 tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F) 4364 if (tempCodePoint > 0x7F) { 4365 codePoint = tempCodePoint 4366 } 4367 } 4368 break 4369 case 3: 4370 secondByte = buf[i + 1] 4371 thirdByte = buf[i + 2] 4372 if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) { 4373 tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F) 4374 if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) { 4375 codePoint = tempCodePoint 4376 } 4377 } 4378 break 4379 case 4: 4380 secondByte = buf[i + 1] 4381 thirdByte = buf[i + 2] 4382 fourthByte = buf[i + 3] 4383 if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) { 4384 tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F) 4385 if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) { 4386 codePoint = tempCodePoint 4387 } 4388 } 4389 } 4390 } 4391 4392 if (codePoint === null) { 4393 // we did not generate a valid codePoint so insert a 4394 // replacement char (U+FFFD) and advance only 1 byte 4395 codePoint = 0xFFFD 4396 bytesPerSequence = 1 4397 } else if (codePoint > 0xFFFF) { 4398 // encode to utf16 (surrogate pair dance) 4399 codePoint -= 0x10000 4400 res.push(codePoint >>> 10 & 0x3FF | 0xD800) 4401 codePoint = 0xDC00 | codePoint & 0x3FF 4402 } 4403 4404 res.push(codePoint) 4405 i += bytesPerSequence 4406 } 4407 4408 return decodeCodePointsArray(res) 4409 } 4410 4411 // Based on http://stackoverflow.com/a/22747272/680742, the browser with 4412 // the lowest limit is Chrome, with 0x10000 args. 4413 // We go 1 magnitude less, for safety 4414 var MAX_ARGUMENTS_LENGTH = 0x1000 4415 4416 function decodeCodePointsArray (codePoints) { 4417 var len = codePoints.length 4418 if (len <= MAX_ARGUMENTS_LENGTH) { 4419 return String.fromCharCode.apply(String, codePoints) // avoid extra slice() 4420 } 4421 4422 // Decode in chunks to avoid "call stack size exceeded". 4423 var res = '' 4424 var i = 0 4425 while (i < len) { 4426 res += String.fromCharCode.apply( 4427 String, 4428 codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH) 4429 ) 4430 } 4431 return res 4432 } 4433 4434 function asciiSlice (buf, start, end) { 4435 var ret = '' 4436 end = Math.min(buf.length, end) 4437 4438 for (var i = start; i < end; ++i) { 4439 ret += String.fromCharCode(buf[i] & 0x7F) 4440 } 4441 return ret 4442 } 4443 4444 function latin1Slice (buf, start, end) { 4445 var ret = '' 4446 end = Math.min(buf.length, end) 4447 4448 for (var i = start; i < end; ++i) { 4449 ret += String.fromCharCode(buf[i]) 4450 } 4451 return ret 4452 } 4453 4454 function hexSlice (buf, start, end) { 4455 var len = buf.length 4456 4457 if (!start || start < 0) start = 0 4458 if (!end || end < 0 || end > len) end = len 4459 4460 var out = '' 4461 for (var i = start; i < end; ++i) { 4462 out += hexSliceLookupTable[buf[i]] 4463 } 4464 return out 4465 } 4466 4467 function utf16leSlice (buf, start, end) { 4468 var bytes = buf.slice(start, end) 4469 var res = '' 4470 // If bytes.length is odd, the last 8 bits must be ignored (same as node.js) 4471 for (var i = 0; i < bytes.length - 1; i += 2) { 4472 res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256)) 4473 } 4474 return res 4475 } 4476 4477 Buffer.prototype.slice = function slice (start, end) { 4478 var len = this.length 4479 start = ~~start 4480 end = end === undefined ? len : ~~end 4481 4482 if (start < 0) { 4483 start += len 4484 if (start < 0) start = 0 4485 } else if (start > len) { 4486 start = len 4487 } 4488 4489 if (end < 0) { 4490 end += len 4491 if (end < 0) end = 0 4492 } else if (end > len) { 4493 end = len 4494 } 4495 4496 if (end < start) end = start 4497 4498 var newBuf = this.subarray(start, end) 4499 // Return an augmented `Uint8Array` instance 4500 Object.setPrototypeOf(newBuf, Buffer.prototype) 4501 4502 return newBuf 4503 } 4504 4505 /* 4506 * Need to make sure that buffer isn't trying to write out of bounds. 4507 */ 4508 function checkOffset (offset, ext, length) { 4509 if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint') 4510 if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length') 4511 } 4512 4513 Buffer.prototype.readUintLE = 4514 Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) { 4515 offset = offset >>> 0 4516 byteLength = byteLength >>> 0 4517 if (!noAssert) checkOffset(offset, byteLength, this.length) 4518 4519 var val = this[offset] 4520 var mul = 1 4521 var i = 0 4522 while (++i < byteLength && (mul *= 0x100)) { 4523 val += this[offset + i] * mul 4524 } 4525 4526 return val 4527 } 4528 4529 Buffer.prototype.readUintBE = 4530 Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) { 4531 offset = offset >>> 0 4532 byteLength = byteLength >>> 0 4533 if (!noAssert) { 4534 checkOffset(offset, byteLength, this.length) 4535 } 4536 4537 var val = this[offset + --byteLength] 4538 var mul = 1 4539 while (byteLength > 0 && (mul *= 0x100)) { 4540 val += this[offset + --byteLength] * mul 4541 } 4542 4543 return val 4544 } 4545 4546 Buffer.prototype.readUint8 = 4547 Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) { 4548 offset = offset >>> 0 4549 if (!noAssert) checkOffset(offset, 1, this.length) 4550 return this[offset] 4551 } 4552 4553 Buffer.prototype.readUint16LE = 4554 Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) { 4555 offset = offset >>> 0 4556 if (!noAssert) checkOffset(offset, 2, this.length) 4557 return this[offset] | (this[offset + 1] << 8) 4558 } 4559 4560 Buffer.prototype.readUint16BE = 4561 Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) { 4562 offset = offset >>> 0 4563 if (!noAssert) checkOffset(offset, 2, this.length) 4564 return (this[offset] << 8) | this[offset + 1] 4565 } 4566 4567 Buffer.prototype.readUint32LE = 4568 Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) { 4569 offset = offset >>> 0 4570 if (!noAssert) checkOffset(offset, 4, this.length) 4571 4572 return ((this[offset]) | 4573 (this[offset + 1] << 8) | 4574 (this[offset + 2] << 16)) + 4575 (this[offset + 3] * 0x1000000) 4576 } 4577 4578 Buffer.prototype.readUint32BE = 4579 Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) { 4580 offset = offset >>> 0 4581 if (!noAssert) checkOffset(offset, 4, this.length) 4582 4583 return (this[offset] * 0x1000000) + 4584 ((this[offset + 1] << 16) | 4585 (this[offset + 2] << 8) | 4586 this[offset + 3]) 4587 } 4588 4589 Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) { 4590 offset = offset >>> 0 4591 byteLength = byteLength >>> 0 4592 if (!noAssert) checkOffset(offset, byteLength, this.length) 4593 4594 var val = this[offset] 4595 var mul = 1 4596 var i = 0 4597 while (++i < byteLength && (mul *= 0x100)) { 4598 val += this[offset + i] * mul 4599 } 4600 mul *= 0x80 4601 4602 if (val >= mul) val -= Math.pow(2, 8 * byteLength) 4603 4604 return val 4605 } 4606 4607 Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) { 4608 offset = offset >>> 0 4609 byteLength = byteLength >>> 0 4610 if (!noAssert) checkOffset(offset, byteLength, this.length) 4611 4612 var i = byteLength 4613 var mul = 1 4614 var val = this[offset + --i] 4615 while (i > 0 && (mul *= 0x100)) { 4616 val += this[offset + --i] * mul 4617 } 4618 mul *= 0x80 4619 4620 if (val >= mul) val -= Math.pow(2, 8 * byteLength) 4621 4622 return val 4623 } 4624 4625 Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) { 4626 offset = offset >>> 0 4627 if (!noAssert) checkOffset(offset, 1, this.length) 4628 if (!(this[offset] & 0x80)) return (this[offset]) 4629 return ((0xff - this[offset] + 1) * -1) 4630 } 4631 4632 Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) { 4633 offset = offset >>> 0 4634 if (!noAssert) checkOffset(offset, 2, this.length) 4635 var val = this[offset] | (this[offset + 1] << 8) 4636 return (val & 0x8000) ? val | 0xFFFF0000 : val 4637 } 4638 4639 Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) { 4640 offset = offset >>> 0 4641 if (!noAssert) checkOffset(offset, 2, this.length) 4642 var val = this[offset + 1] | (this[offset] << 8) 4643 return (val & 0x8000) ? val | 0xFFFF0000 : val 4644 } 4645 4646 Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) { 4647 offset = offset >>> 0 4648 if (!noAssert) checkOffset(offset, 4, this.length) 4649 4650 return (this[offset]) | 4651 (this[offset + 1] << 8) | 4652 (this[offset + 2] << 16) | 4653 (this[offset + 3] << 24) 4654 } 4655 4656 Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) { 4657 offset = offset >>> 0 4658 if (!noAssert) checkOffset(offset, 4, this.length) 4659 4660 return (this[offset] << 24) | 4661 (this[offset + 1] << 16) | 4662 (this[offset + 2] << 8) | 4663 (this[offset + 3]) 4664 } 4665 4666 Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) { 4667 offset = offset >>> 0 4668 if (!noAssert) checkOffset(offset, 4, this.length) 4669 return ieee754.read(this, offset, true, 23, 4) 4670 } 4671 4672 Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) { 4673 offset = offset >>> 0 4674 if (!noAssert) checkOffset(offset, 4, this.length) 4675 return ieee754.read(this, offset, false, 23, 4) 4676 } 4677 4678 Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) { 4679 offset = offset >>> 0 4680 if (!noAssert) checkOffset(offset, 8, this.length) 4681 return ieee754.read(this, offset, true, 52, 8) 4682 } 4683 4684 Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) { 4685 offset = offset >>> 0 4686 if (!noAssert) checkOffset(offset, 8, this.length) 4687 return ieee754.read(this, offset, false, 52, 8) 4688 } 4689 4690 function checkInt (buf, value, offset, ext, max, min) { 4691 if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance') 4692 if (value > max || value < min) throw new RangeError('"value" argument is out of bounds') 4693 if (offset + ext > buf.length) throw new RangeError('Index out of range') 4694 } 4695 4696 Buffer.prototype.writeUintLE = 4697 Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) { 4698 value = +value 4699 offset = offset >>> 0 4700 byteLength = byteLength >>> 0 4701 if (!noAssert) { 4702 var maxBytes = Math.pow(2, 8 * byteLength) - 1 4703 checkInt(this, value, offset, byteLength, maxBytes, 0) 4704 } 4705 4706 var mul = 1 4707 var i = 0 4708 this[offset] = value & 0xFF 4709 while (++i < byteLength && (mul *= 0x100)) { 4710 this[offset + i] = (value / mul) & 0xFF 4711 } 4712 4713 return offset + byteLength 4714 } 4715 4716 Buffer.prototype.writeUintBE = 4717 Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) { 4718 value = +value 4719 offset = offset >>> 0 4720 byteLength = byteLength >>> 0 4721 if (!noAssert) { 4722 var maxBytes = Math.pow(2, 8 * byteLength) - 1 4723 checkInt(this, value, offset, byteLength, maxBytes, 0) 4724 } 4725 4726 var i = byteLength - 1 4727 var mul = 1 4728 this[offset + i] = value & 0xFF 4729 while (--i >= 0 && (mul *= 0x100)) { 4730 this[offset + i] = (value / mul) & 0xFF 4731 } 4732 4733 return offset + byteLength 4734 } 4735 4736 Buffer.prototype.writeUint8 = 4737 Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) { 4738 value = +value 4739 offset = offset >>> 0 4740 if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0) 4741 this[offset] = (value & 0xff) 4742 return offset + 1 4743 } 4744 4745 Buffer.prototype.writeUint16LE = 4746 Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) { 4747 value = +value 4748 offset = offset >>> 0 4749 if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) 4750 this[offset] = (value & 0xff) 4751 this[offset + 1] = (value >>> 8) 4752 return offset + 2 4753 } 4754 4755 Buffer.prototype.writeUint16BE = 4756 Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) { 4757 value = +value 4758 offset = offset >>> 0 4759 if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) 4760 this[offset] = (value >>> 8) 4761 this[offset + 1] = (value & 0xff) 4762 return offset + 2 4763 } 4764 4765 Buffer.prototype.writeUint32LE = 4766 Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) { 4767 value = +value 4768 offset = offset >>> 0 4769 if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) 4770 this[offset + 3] = (value >>> 24) 4771 this[offset + 2] = (value >>> 16) 4772 this[offset + 1] = (value >>> 8) 4773 this[offset] = (value & 0xff) 4774 return offset + 4 4775 } 4776 4777 Buffer.prototype.writeUint32BE = 4778 Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) { 4779 value = +value 4780 offset = offset >>> 0 4781 if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) 4782 this[offset] = (value >>> 24) 4783 this[offset + 1] = (value >>> 16) 4784 this[offset + 2] = (value >>> 8) 4785 this[offset + 3] = (value & 0xff) 4786 return offset + 4 4787 } 4788 4789 Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) { 4790 value = +value 4791 offset = offset >>> 0 4792 if (!noAssert) { 4793 var limit = Math.pow(2, (8 * byteLength) - 1) 4794 4795 checkInt(this, value, offset, byteLength, limit - 1, -limit) 4796 } 4797 4798 var i = 0 4799 var mul = 1 4800 var sub = 0 4801 this[offset] = value & 0xFF 4802 while (++i < byteLength && (mul *= 0x100)) { 4803 if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) { 4804 sub = 1 4805 } 4806 this[offset + i] = ((value / mul) >> 0) - sub & 0xFF 4807 } 4808 4809 return offset + byteLength 4810 } 4811 4812 Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) { 4813 value = +value 4814 offset = offset >>> 0 4815 if (!noAssert) { 4816 var limit = Math.pow(2, (8 * byteLength) - 1) 4817 4818 checkInt(this, value, offset, byteLength, limit - 1, -limit) 4819 } 4820 4821 var i = byteLength - 1 4822 var mul = 1 4823 var sub = 0 4824 this[offset + i] = value & 0xFF 4825 while (--i >= 0 && (mul *= 0x100)) { 4826 if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) { 4827 sub = 1 4828 } 4829 this[offset + i] = ((value / mul) >> 0) - sub & 0xFF 4830 } 4831 4832 return offset + byteLength 4833 } 4834 4835 Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) { 4836 value = +value 4837 offset = offset >>> 0 4838 if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80) 4839 if (value < 0) value = 0xff + value + 1 4840 this[offset] = (value & 0xff) 4841 return offset + 1 4842 } 4843 4844 Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) { 4845 value = +value 4846 offset = offset >>> 0 4847 if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) 4848 this[offset] = (value & 0xff) 4849 this[offset + 1] = (value >>> 8) 4850 return offset + 2 4851 } 4852 4853 Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) { 4854 value = +value 4855 offset = offset >>> 0 4856 if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) 4857 this[offset] = (value >>> 8) 4858 this[offset + 1] = (value & 0xff) 4859 return offset + 2 4860 } 4861 4862 Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) { 4863 value = +value 4864 offset = offset >>> 0 4865 if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) 4866 this[offset] = (value & 0xff) 4867 this[offset + 1] = (value >>> 8) 4868 this[offset + 2] = (value >>> 16) 4869 this[offset + 3] = (value >>> 24) 4870 return offset + 4 4871 } 4872 4873 Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) { 4874 value = +value 4875 offset = offset >>> 0 4876 if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) 4877 if (value < 0) value = 0xffffffff + value + 1 4878 this[offset] = (value >>> 24) 4879 this[offset + 1] = (value >>> 16) 4880 this[offset + 2] = (value >>> 8) 4881 this[offset + 3] = (value & 0xff) 4882 return offset + 4 4883 } 4884 4885 function checkIEEE754 (buf, value, offset, ext, max, min) { 4886 if (offset + ext > buf.length) throw new RangeError('Index out of range') 4887 if (offset < 0) throw new RangeError('Index out of range') 4888 } 4889 4890 function writeFloat (buf, value, offset, littleEndian, noAssert) { 4891 value = +value 4892 offset = offset >>> 0 4893 if (!noAssert) { 4894 checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38) 4895 } 4896 ieee754.write(buf, value, offset, littleEndian, 23, 4) 4897 return offset + 4 4898 } 4899 4900 Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) { 4901 return writeFloat(this, value, offset, true, noAssert) 4902 } 4903 4904 Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) { 4905 return writeFloat(this, value, offset, false, noAssert) 4906 } 4907 4908 function writeDouble (buf, value, offset, littleEndian, noAssert) { 4909 value = +value 4910 offset = offset >>> 0 4911 if (!noAssert) { 4912 checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308) 4913 } 4914 ieee754.write(buf, value, offset, littleEndian, 52, 8) 4915 return offset + 8 4916 } 4917 4918 Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) { 4919 return writeDouble(this, value, offset, true, noAssert) 4920 } 4921 4922 Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) { 4923 return writeDouble(this, value, offset, false, noAssert) 4924 } 4925 4926 // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) 4927 Buffer.prototype.copy = function copy (target, targetStart, start, end) { 4928 if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer') 4929 if (!start) start = 0 4930 if (!end && end !== 0) end = this.length 4931 if (targetStart >= target.length) targetStart = target.length 4932 if (!targetStart) targetStart = 0 4933 if (end > 0 && end < start) end = start 4934 4935 // Copy 0 bytes; we're done 4936 if (end === start) return 0 4937 if (target.length === 0 || this.length === 0) return 0 4938 4939 // Fatal error conditions 4940 if (targetStart < 0) { 4941 throw new RangeError('targetStart out of bounds') 4942 } 4943 if (start < 0 || start >= this.length) throw new RangeError('Index out of range') 4944 if (end < 0) throw new RangeError('sourceEnd out of bounds') 4945 4946 // Are we oob? 4947 if (end > this.length) end = this.length 4948 if (target.length - targetStart < end - start) { 4949 end = target.length - targetStart + start 4950 } 4951 4952 var len = end - start 4953 4954 if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') { 4955 // Use built-in when available, missing from IE11 4956 this.copyWithin(targetStart, start, end) 4957 } else { 4958 Uint8Array.prototype.set.call( 4959 target, 4960 this.subarray(start, end), 4961 targetStart 4962 ) 4963 } 4964 4965 return len 4966 } 4967 4968 // Usage: 4969 // buffer.fill(number[, offset[, end]]) 4970 // buffer.fill(buffer[, offset[, end]]) 4971 // buffer.fill(string[, offset[, end]][, encoding]) 4972 Buffer.prototype.fill = function fill (val, start, end, encoding) { 4973 // Handle string cases: 4974 if (typeof val === 'string') { 4975 if (typeof start === 'string') { 4976 encoding = start 4977 start = 0 4978 end = this.length 4979 } else if (typeof end === 'string') { 4980 encoding = end 4981 end = this.length 4982 } 4983 if (encoding !== undefined && typeof encoding !== 'string') { 4984 throw new TypeError('encoding must be a string') 4985 } 4986 if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) { 4987 throw new TypeError('Unknown encoding: ' + encoding) 4988 } 4989 if (val.length === 1) { 4990 var code = val.charCodeAt(0) 4991 if ((encoding === 'utf8' && code < 128) || 4992 encoding === 'latin1') { 4993 // Fast path: If `val` fits into a single byte, use that numeric value. 4994 val = code 4995 } 4996 } 4997 } else if (typeof val === 'number') { 4998 val = val & 255 4999 } else if (typeof val === 'boolean') { 5000 val = Number(val) 5001 } 5002 5003 // Invalid ranges are not set to a default, so can range check early. 5004 if (start < 0 || this.length < start || this.length < end) { 5005 throw new RangeError('Out of range index') 5006 } 5007 5008 if (end <= start) { 5009 return this 5010 } 5011 5012 start = start >>> 0 5013 end = end === undefined ? this.length : end >>> 0 5014 5015 if (!val) val = 0 5016 5017 var i 5018 if (typeof val === 'number') { 5019 for (i = start; i < end; ++i) { 5020 this[i] = val 5021 } 5022 } else { 5023 var bytes = Buffer.isBuffer(val) 5024 ? val 5025 : Buffer.from(val, encoding) 5026 var len = bytes.length 5027 if (len === 0) { 5028 throw new TypeError('The value "' + val + 5029 '" is invalid for argument "value"') 5030 } 5031 for (i = 0; i < end - start; ++i) { 5032 this[i + start] = bytes[i % len] 5033 } 5034 } 5035 5036 return this 5037 } 5038 5039 // HELPER FUNCTIONS 5040 // ================ 5041 5042 var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g 5043 5044 function base64clean (str) { 5045 // Node takes equal signs as end of the Base64 encoding 5046 str = str.split('=')[0] 5047 // Node strips out invalid characters like \n and \t from the string, base64-js does not 5048 str = str.trim().replace(INVALID_BASE64_RE, '') 5049 // Node converts strings with length < 2 to '' 5050 if (str.length < 2) return '' 5051 // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not 5052 while (str.length % 4 !== 0) { 5053 str = str + '=' 5054 } 5055 return str 5056 } 5057 5058 function utf8ToBytes (string, units) { 5059 units = units || Infinity 5060 var codePoint 5061 var length = string.length 5062 var leadSurrogate = null 5063 var bytes = [] 5064 5065 for (var i = 0; i < length; ++i) { 5066 codePoint = string.charCodeAt(i) 5067 5068 // is surrogate component 5069 if (codePoint > 0xD7FF && codePoint < 0xE000) { 5070 // last char was a lead 5071 if (!leadSurrogate) { 5072 // no lead yet 5073 if (codePoint > 0xDBFF) { 5074 // unexpected trail 5075 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) 5076 continue 5077 } else if (i + 1 === length) { 5078 // unpaired lead 5079 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) 5080 continue 5081 } 5082 5083 // valid lead 5084 leadSurrogate = codePoint 5085 5086 continue 5087 } 5088 5089 // 2 leads in a row 5090 if (codePoint < 0xDC00) { 5091 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) 5092 leadSurrogate = codePoint 5093 continue 5094 } 5095 5096 // valid surrogate pair 5097 codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000 5098 } else if (leadSurrogate) { 5099 // valid bmp char, but last char was a lead 5100 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) 5101 } 5102 5103 leadSurrogate = null 5104 5105 // encode utf8 5106 if (codePoint < 0x80) { 5107 if ((units -= 1) < 0) break 5108 bytes.push(codePoint) 5109 } else if (codePoint < 0x800) { 5110 if ((units -= 2) < 0) break 5111 bytes.push( 5112 codePoint >> 0x6 | 0xC0, 5113 codePoint & 0x3F | 0x80 5114 ) 5115 } else if (codePoint < 0x10000) { 5116 if ((units -= 3) < 0) break 5117 bytes.push( 5118 codePoint >> 0xC | 0xE0, 5119 codePoint >> 0x6 & 0x3F | 0x80, 5120 codePoint & 0x3F | 0x80 5121 ) 5122 } else if (codePoint < 0x110000) { 5123 if ((units -= 4) < 0) break 5124 bytes.push( 5125 codePoint >> 0x12 | 0xF0, 5126 codePoint >> 0xC & 0x3F | 0x80, 5127 codePoint >> 0x6 & 0x3F | 0x80, 5128 codePoint & 0x3F | 0x80 5129 ) 5130 } else { 5131 throw new Error('Invalid code point') 5132 } 5133 } 5134 5135 return bytes 5136 } 5137 5138 function asciiToBytes (str) { 5139 var byteArray = [] 5140 for (var i = 0; i < str.length; ++i) { 5141 // Node's code seems to be doing this and not & 0x7F.. 5142 byteArray.push(str.charCodeAt(i) & 0xFF) 5143 } 5144 return byteArray 5145 } 5146 5147 function utf16leToBytes (str, units) { 5148 var c, hi, lo 5149 var byteArray = [] 5150 for (var i = 0; i < str.length; ++i) { 5151 if ((units -= 2) < 0) break 5152 5153 c = str.charCodeAt(i) 5154 hi = c >> 8 5155 lo = c % 256 5156 byteArray.push(lo) 5157 byteArray.push(hi) 5158 } 5159 5160 return byteArray 5161 } 5162 5163 function base64ToBytes (str) { 5164 return base64.toByteArray(base64clean(str)) 5165 } 5166 5167 function blitBuffer (src, dst, offset, length) { 5168 for (var i = 0; i < length; ++i) { 5169 if ((i + offset >= dst.length) || (i >= src.length)) break 5170 dst[i + offset] = src[i] 5171 } 5172 return i 5173 } 5174 5175 // ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass 5176 // the `instanceof` check but they should be treated as of that type. 5177 // See: https://github.com/feross/buffer/issues/166 5178 function isInstance (obj, type) { 5179 return obj instanceof type || 5180 (obj != null && obj.constructor != null && obj.constructor.name != null && 5181 obj.constructor.name === type.name) 5182 } 5183 function numberIsNaN (obj) { 5184 // For IE11 support 5185 return obj !== obj // eslint-disable-line no-self-compare 5186 } 5187 5188 // Create lookup table for `toString('hex')` 5189 // See: https://github.com/feross/buffer/issues/219 5190 var hexSliceLookupTable = (function () { 5191 var alphabet = '0123456789abcdef' 5192 var table = new Array(256) 5193 for (var i = 0; i < 16; ++i) { 5194 var i16 = i * 16 5195 for (var j = 0; j < 16; ++j) { 5196 table[i16 + j] = alphabet[i] + alphabet[j] 5197 } 5198 } 5199 return table 5200 })() 5201 5202 }).call(this)}).call(this,require("buffer").Buffer) 5203 },{"base64-js":6,"buffer":7,"ieee754":14}],9:[function(require,module,exports){ 5204 var BufferReader = require('./lib/buffer-reader') 5205 5206 var XIPH_LACING = 1 5207 var EBML_LACING = 3 5208 var FIXED_SIZE_LACING = 2 5209 5210 module.exports = function (buffer) { 5211 var block = {} 5212 var reader = new BufferReader(buffer) 5213 5214 block.trackNumber = reader.nextUIntV() 5215 block.timecode = reader.nextInt16BE() 5216 5217 var flags = reader.nextUInt8() 5218 5219 block.invisible = !!(flags & 0x8) 5220 5221 // only valid for SimpleBlock 5222 block.keyframe = !!(flags & 0x80) 5223 block.discardable = !!(flags & 0x1) 5224 5225 var lacing = (flags & 0x6) >> 1 5226 5227 block.frames = readLacedData(reader, lacing) 5228 5229 return block 5230 } 5231 5232 function readLacedData (reader, lacing) { 5233 if (!lacing) return [reader.nextBuffer()] 5234 5235 var i, frameSize 5236 var frames = [] 5237 var framesNum = reader.nextUInt8() + 1 // number of frames 5238 5239 if (lacing === FIXED_SIZE_LACING) { 5240 // remaining data should be divisible by the number of frames 5241 if (reader.length % framesNum !== 0) throw new Error('Fixed-Size Lacing Error') 5242 5243 frameSize = reader.length / framesNum 5244 for (i = 0; i < framesNum; i++) { 5245 frames.push(reader.nextBuffer(frameSize)) 5246 } 5247 return frames 5248 } 5249 5250 var frameSizes = [] 5251 5252 if (lacing === XIPH_LACING) { 5253 for (i = 0; i < framesNum - 1; i++) { 5254 var val 5255 frameSize = 0 5256 do { 5257 val = reader.nextUInt8() 5258 frameSize += val 5259 } while (val === 0xff) 5260 frameSizes.push(frameSize) 5261 } 5262 } else if (lacing === EBML_LACING) { 5263 // first frame 5264 frameSize = reader.nextUIntV() 5265 frameSizes.push(frameSize) 5266 5267 // middle frames 5268 for (i = 1; i < framesNum - 1; i++) { 5269 frameSize += reader.nextIntV() 5270 frameSizes.push(frameSize) 5271 } 5272 } 5273 5274 for (i = 0; i < framesNum - 1; i++) { 5275 frames.push(reader.nextBuffer(frameSizes[i])) 5276 } 5277 5278 // last frame (remaining buffer) 5279 frames.push(reader.nextBuffer()) 5280 5281 return frames 5282 } 5283 5284 },{"./lib/buffer-reader":10}],10:[function(require,module,exports){ 5285 var vint = require('./vint') 5286 5287 function BufferReader (buffer) { 5288 this.buffer = buffer 5289 this.offset = 0 5290 } 5291 5292 // a super limited subset of the node buffer API 5293 BufferReader.prototype.nextInt16BE = function () { 5294 var value = this.buffer.readInt16BE(this.offset) 5295 this.offset += 2 5296 return value 5297 } 5298 5299 BufferReader.prototype.nextUInt8 = function () { 5300 var value = this.buffer.readUInt8(this.offset) 5301 this.offset += 1 5302 return value 5303 } 5304 5305 // EBML variable sized integers 5306 BufferReader.prototype.nextUIntV = function () { 5307 var v = vint(this.buffer, this.offset) 5308 this.offset += v.length 5309 return v.value 5310 } 5311 5312 BufferReader.prototype.nextIntV = function () { 5313 var v = vint(this.buffer, this.offset, true) 5314 this.offset += v.length 5315 return v.value 5316 } 5317 5318 // buffer slice 5319 BufferReader.prototype.nextBuffer = function (length) { 5320 var buffer = length 5321 ? this.buffer.slice(this.offset, this.offset + length) 5322 : this.buffer.slice(this.offset) 5323 this.offset += length || this.length 5324 return buffer 5325 } 5326 5327 // remaining bytes to read 5328 Object.defineProperty(BufferReader.prototype, 'length', { 5329 get: function () { return this.buffer.length - this.offset } 5330 }) 5331 5332 module.exports = BufferReader 5333 5334 },{"./vint":11}],11:[function(require,module,exports){ 5335 // https://github.com/themasch/node-ebml/blob/master/lib/ebml/tools.js 5336 module.exports = function (buffer, start, signed) { 5337 start = start || 0 5338 for (var length = 1; length <= 8; length++) { 5339 if (buffer[start] >= Math.pow(2, 8 - length)) { 5340 break 5341 } 5342 } 5343 if (length > 8) { 5344 throw new Error('Unrepresentable length: ' + length + ' ' + 5345 buffer.toString('hex', start, start + length)) 5346 } 5347 if (start + length > buffer.length) { 5348 return null 5349 } 5350 var i 5351 var value = buffer[start] & (1 << (8 - length)) - 1 5352 for (i = 1; i < length; i++) { 5353 if (i === 7) { 5354 if (value >= Math.pow(2, 53 - 8) && buffer[start + 7] > 0) { 5355 return { 5356 length: length, 5357 value: -1 5358 } 5359 } 5360 } 5361 value *= Math.pow(2, 8) 5362 value += buffer[start + i] 5363 } 5364 if (signed) { 5365 value -= Math.pow(2, length * 7 - 1) - 1 5366 } 5367 return { 5368 length: length, 5369 value: value 5370 } 5371 } 5372 5373 },{}],12:[function(require,module,exports){ 5374 (function (Buffer){(function (){ 5375 var tools = { 5376 readVint: function(buffer, start) { 5377 start = start || 0; 5378 for (var length = 1; length <= 8; length++) { 5379 if (buffer[start] >= Math.pow(2, 8 - length)) { 5380 break; 5381 } 5382 } 5383 if (length > 8) { 5384 throw new Error("Unrepresentable length: " + length + " " + 5385 buffer.toString('hex', start, start + length)); 5386 } 5387 if (start + length > buffer.length) { 5388 return null; 5389 } 5390 var value = buffer[start] & (1 << (8 - length)) - 1; 5391 for (var i = 1; i < length; i++) { 5392 if (i === 7) { 5393 if (value >= Math.pow(2, 53 - 8) && buffer[start + 7] > 0) { 5394 return { 5395 length: length, 5396 value: -1 5397 }; 5398 } 5399 } 5400 value *= Math.pow(2, 8); 5401 value += buffer[start + i]; 5402 } 5403 return { 5404 length: length, 5405 value: value 5406 }; 5407 }, 5408 5409 writeVint: function(value) { 5410 if (value < 0 || value > Math.pow(2, 53)) { 5411 throw new Error("Unrepresentable value: " + value); 5412 } 5413 for (var length = 1; length <= 8; length++) { 5414 if (value < Math.pow(2, 7 * length) - 1) { 5415 break; 5416 } 5417 } 5418 var buffer = new Buffer(length); 5419 for (var i = 1; i <= length; i++) { 5420 var b = value & 0xFF; 5421 buffer[length - i] = b; 5422 value -= b; 5423 value /= Math.pow(2, 8); 5424 } 5425 buffer[0] = buffer[0] | (1 << (8 - length)); 5426 return buffer; 5427 } 5428 }; 5429 5430 module.exports = tools; 5431 5432 }).call(this)}).call(this,require("buffer").Buffer) 5433 },{"buffer":7}],13:[function(require,module,exports){ 5434 // Copyright Joyent, Inc. and other Node contributors. 5435 // 5436 // Permission is hereby granted, free of charge, to any person obtaining a 5437 // copy of this software and associated documentation files (the 5438 // "Software"), to deal in the Software without restriction, including 5439 // without limitation the rights to use, copy, modify, merge, publish, 5440 // distribute, sublicense, and/or sell copies of the Software, and to permit 5441 // persons to whom the Software is furnished to do so, subject to the 5442 // following conditions: 5443 // 5444 // The above copyright notice and this permission notice shall be included 5445 // in all copies or substantial portions of the Software. 5446 // 5447 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 5448 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 5449 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 5450 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 5451 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 5452 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 5453 // USE OR OTHER DEALINGS IN THE SOFTWARE. 5454 5455 function EventEmitter() { 5456 this._events = this._events || {}; 5457 this._maxListeners = this._maxListeners || undefined; 5458 } 5459 module.exports = EventEmitter; 5460 5461 // Backwards-compat with node 0.10.x 5462 EventEmitter.EventEmitter = EventEmitter; 5463 5464 EventEmitter.prototype._events = undefined; 5465 EventEmitter.prototype._maxListeners = undefined; 5466 5467 // By default EventEmitters will print a warning if more than 10 listeners are 5468 // added to it. This is a useful default which helps finding memory leaks. 5469 EventEmitter.defaultMaxListeners = 10; 5470 5471 // Obviously not all Emitters should be limited to 10. This function allows 5472 // that to be increased. Set to zero for unlimited. 5473 EventEmitter.prototype.setMaxListeners = function(n) { 5474 if (!isNumber(n) || n < 0 || isNaN(n)) 5475 throw TypeError('n must be a positive number'); 5476 this._maxListeners = n; 5477 return this; 5478 }; 5479 5480 EventEmitter.prototype.emit = function(type) { 5481 var er, handler, len, args, i, listeners; 5482 5483 if (!this._events) 5484 this._events = {}; 5485 5486 // If there is no 'error' event listener then throw. 5487 if (type === 'error') { 5488 if (!this._events.error || 5489 (isObject(this._events.error) && !this._events.error.length)) { 5490 er = arguments[1]; 5491 if (er instanceof Error) { 5492 throw er; // Unhandled 'error' event 5493 } else { 5494 // At least give some kind of context to the user 5495 var err = new Error('Uncaught, unspecified "error" event. (' + er + ')'); 5496 err.context = er; 5497 throw err; 5498 } 5499 } 5500 } 5501 5502 handler = this._events[type]; 5503 5504 if (isUndefined(handler)) 5505 return false; 5506 5507 if (isFunction(handler)) { 5508 switch (arguments.length) { 5509 // fast cases 5510 case 1: 5511 handler.call(this); 5512 break; 5513 case 2: 5514 handler.call(this, arguments[1]); 5515 break; 5516 case 3: 5517 handler.call(this, arguments[1], arguments[2]); 5518 break; 5519 // slower 5520 default: 5521 args = Array.prototype.slice.call(arguments, 1); 5522 handler.apply(this, args); 5523 } 5524 } else if (isObject(handler)) { 5525 args = Array.prototype.slice.call(arguments, 1); 5526 listeners = handler.slice(); 5527 len = listeners.length; 5528 for (i = 0; i < len; i++) 5529 listeners[i].apply(this, args); 5530 } 5531 5532 return true; 5533 }; 5534 5535 EventEmitter.prototype.addListener = function(type, listener) { 5536 var m; 5537 5538 if (!isFunction(listener)) 5539 throw TypeError('listener must be a function'); 5540 5541 if (!this._events) 5542 this._events = {}; 5543 5544 // To avoid recursion in the case that type === "newListener"! Before 5545 // adding it to the listeners, first emit "newListener". 5546 if (this._events.newListener) 5547 this.emit('newListener', type, 5548 isFunction(listener.listener) ? 5549 listener.listener : listener); 5550 5551 if (!this._events[type]) 5552 // Optimize the case of one listener. Don't need the extra array object. 5553 this._events[type] = listener; 5554 else if (isObject(this._events[type])) 5555 // If we've already got an array, just append. 5556 this._events[type].push(listener); 5557 else 5558 // Adding the second element, need to change to array. 5559 this._events[type] = [this._events[type], listener]; 5560 5561 // Check for listener leak 5562 if (isObject(this._events[type]) && !this._events[type].warned) { 5563 if (!isUndefined(this._maxListeners)) { 5564 m = this._maxListeners; 5565 } else { 5566 m = EventEmitter.defaultMaxListeners; 5567 } 5568 5569 if (m && m > 0 && this._events[type].length > m) { 5570 this._events[type].warned = true; 5571 console.error('(node) warning: possible EventEmitter memory ' + 5572 'leak detected. %d listeners added. ' + 5573 'Use emitter.setMaxListeners() to increase limit.', 5574 this._events[type].length); 5575 if (typeof console.trace === 'function') { 5576 // not supported in IE 10 5577 console.trace(); 5578 } 5579 } 5580 } 5581 5582 return this; 5583 }; 5584 5585 EventEmitter.prototype.on = EventEmitter.prototype.addListener; 5586 5587 EventEmitter.prototype.once = function(type, listener) { 5588 if (!isFunction(listener)) 5589 throw TypeError('listener must be a function'); 5590 5591 var fired = false; 5592 5593 function g() { 5594 this.removeListener(type, g); 5595 5596 if (!fired) { 5597 fired = true; 5598 listener.apply(this, arguments); 5599 } 5600 } 5601 5602 g.listener = listener; 5603 this.on(type, g); 5604 5605 return this; 5606 }; 5607 5608 // emits a 'removeListener' event iff the listener was removed 5609 EventEmitter.prototype.removeListener = function(type, listener) { 5610 var list, position, length, i; 5611 5612 if (!isFunction(listener)) 5613 throw TypeError('listener must be a function'); 5614 5615 if (!this._events || !this._events[type]) 5616 return this; 5617 5618 list = this._events[type]; 5619 length = list.length; 5620 position = -1; 5621 5622 if (list === listener || 5623 (isFunction(list.listener) && list.listener === listener)) { 5624 delete this._events[type]; 5625 if (this._events.removeListener) 5626 this.emit('removeListener', type, listener); 5627 5628 } else if (isObject(list)) { 5629 for (i = length; i-- > 0;) { 5630 if (list[i] === listener || 5631 (list[i].listener && list[i].listener === listener)) { 5632 position = i; 5633 break; 5634 } 5635 } 5636 5637 if (position < 0) 5638 return this; 5639 5640 if (list.length === 1) { 5641 list.length = 0; 5642 delete this._events[type]; 5643 } else { 5644 list.splice(position, 1); 5645 } 5646 5647 if (this._events.removeListener) 5648 this.emit('removeListener', type, listener); 5649 } 5650 5651 return this; 5652 }; 5653 5654 EventEmitter.prototype.removeAllListeners = function(type) { 5655 var key, listeners; 5656 5657 if (!this._events) 5658 return this; 5659 5660 // not listening for removeListener, no need to emit 5661 if (!this._events.removeListener) { 5662 if (arguments.length === 0) 5663 this._events = {}; 5664 else if (this._events[type]) 5665 delete this._events[type]; 5666 return this; 5667 } 5668 5669 // emit removeListener for all listeners on all events 5670 if (arguments.length === 0) { 5671 for (key in this._events) { 5672 if (key === 'removeListener') continue; 5673 this.removeAllListeners(key); 5674 } 5675 this.removeAllListeners('removeListener'); 5676 this._events = {}; 5677 return this; 5678 } 5679 5680 listeners = this._events[type]; 5681 5682 if (isFunction(listeners)) { 5683 this.removeListener(type, listeners); 5684 } else if (listeners) { 5685 // LIFO order 5686 while (listeners.length) 5687 this.removeListener(type, listeners[listeners.length - 1]); 5688 } 5689 delete this._events[type]; 5690 5691 return this; 5692 }; 5693 5694 EventEmitter.prototype.listeners = function(type) { 5695 var ret; 5696 if (!this._events || !this._events[type]) 5697 ret = []; 5698 else if (isFunction(this._events[type])) 5699 ret = [this._events[type]]; 5700 else 5701 ret = this._events[type].slice(); 5702 return ret; 5703 }; 5704 5705 EventEmitter.prototype.listenerCount = function(type) { 5706 if (this._events) { 5707 var evlistener = this._events[type]; 5708 5709 if (isFunction(evlistener)) 5710 return 1; 5711 else if (evlistener) 5712 return evlistener.length; 5713 } 5714 return 0; 5715 }; 5716 5717 EventEmitter.listenerCount = function(emitter, type) { 5718 return emitter.listenerCount(type); 5719 }; 5720 5721 function isFunction(arg) { 5722 return typeof arg === 'function'; 5723 } 5724 5725 function isNumber(arg) { 5726 return typeof arg === 'number'; 5727 } 5728 5729 function isObject(arg) { 5730 return typeof arg === 'object' && arg !== null; 5731 } 5732 5733 function isUndefined(arg) { 5734 return arg === void 0; 5735 } 5736 5737 },{}],14:[function(require,module,exports){ 5738 /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */ 5739 exports.read = function (buffer, offset, isLE, mLen, nBytes) { 5740 var e, m 5741 var eLen = (nBytes * 8) - mLen - 1 5742 var eMax = (1 << eLen) - 1 5743 var eBias = eMax >> 1 5744 var nBits = -7 5745 var i = isLE ? (nBytes - 1) : 0 5746 var d = isLE ? -1 : 1 5747 var s = buffer[offset + i] 5748 5749 i += d 5750 5751 e = s & ((1 << (-nBits)) - 1) 5752 s >>= (-nBits) 5753 nBits += eLen 5754 for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {} 5755 5756 m = e & ((1 << (-nBits)) - 1) 5757 e >>= (-nBits) 5758 nBits += mLen 5759 for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {} 5760 5761 if (e === 0) { 5762 e = 1 - eBias 5763 } else if (e === eMax) { 5764 return m ? NaN : ((s ? -1 : 1) * Infinity) 5765 } else { 5766 m = m + Math.pow(2, mLen) 5767 e = e - eBias 5768 } 5769 return (s ? -1 : 1) * m * Math.pow(2, e - mLen) 5770 } 5771 5772 exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { 5773 var e, m, c 5774 var eLen = (nBytes * 8) - mLen - 1 5775 var eMax = (1 << eLen) - 1 5776 var eBias = eMax >> 1 5777 var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0) 5778 var i = isLE ? 0 : (nBytes - 1) 5779 var d = isLE ? 1 : -1 5780 var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0 5781 5782 value = Math.abs(value) 5783 5784 if (isNaN(value) || value === Infinity) { 5785 m = isNaN(value) ? 1 : 0 5786 e = eMax 5787 } else { 5788 e = Math.floor(Math.log(value) / Math.LN2) 5789 if (value * (c = Math.pow(2, -e)) < 1) { 5790 e-- 5791 c *= 2 5792 } 5793 if (e + eBias >= 1) { 5794 value += rt / c 5795 } else { 5796 value += rt * Math.pow(2, 1 - eBias) 5797 } 5798 if (value * c >= 2) { 5799 e++ 5800 c /= 2 5801 } 5802 5803 if (e + eBias >= eMax) { 5804 m = 0 5805 e = eMax 5806 } else if (e + eBias >= 1) { 5807 m = ((value * c) - 1) * Math.pow(2, mLen) 5808 e = e + eBias 5809 } else { 5810 m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen) 5811 e = 0 5812 } 5813 } 5814 5815 for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {} 5816 5817 e = (e << mLen) | m 5818 eLen += mLen 5819 for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {} 5820 5821 buffer[offset + i - d] |= s * 128 5822 } 5823 5824 },{}],15:[function(require,module,exports){ 5825 (function (Buffer){(function (){ 5826 // int64-buffer.js 5827 5828 /*jshint -W018 */ // Confusing use of '!'. 5829 /*jshint -W030 */ // Expected an assignment or function call and instead saw an expression. 5830 /*jshint -W093 */ // Did you mean to return a conditional instead of an assignment? 5831 5832 var Uint64BE, Int64BE, Uint64LE, Int64LE; 5833 5834 !function(exports) { 5835 // constants 5836 5837 var UNDEFINED = "undefined"; 5838 var BUFFER = (UNDEFINED !== typeof Buffer) && Buffer; 5839 var UINT8ARRAY = (UNDEFINED !== typeof Uint8Array) && Uint8Array; 5840 var ARRAYBUFFER = (UNDEFINED !== typeof ArrayBuffer) && ArrayBuffer; 5841 var ZERO = [0, 0, 0, 0, 0, 0, 0, 0]; 5842 var isArray = Array.isArray || _isArray; 5843 var BIT32 = 4294967296; 5844 var BIT24 = 16777216; 5845 5846 // storage class 5847 5848 var storage; // Array; 5849 5850 // generate classes 5851 5852 Uint64BE = factory("Uint64BE", true, true); 5853 Int64BE = factory("Int64BE", true, false); 5854 Uint64LE = factory("Uint64LE", false, true); 5855 Int64LE = factory("Int64LE", false, false); 5856 5857 // class factory 5858 5859 function factory(name, bigendian, unsigned) { 5860 var posH = bigendian ? 0 : 4; 5861 var posL = bigendian ? 4 : 0; 5862 var pos0 = bigendian ? 0 : 3; 5863 var pos1 = bigendian ? 1 : 2; 5864 var pos2 = bigendian ? 2 : 1; 5865 var pos3 = bigendian ? 3 : 0; 5866 var fromPositive = bigendian ? fromPositiveBE : fromPositiveLE; 5867 var fromNegative = bigendian ? fromNegativeBE : fromNegativeLE; 5868 var proto = Int64.prototype; 5869 var isName = "is" + name; 5870 var _isInt64 = "_" + isName; 5871 5872 // properties 5873 proto.buffer = void 0; 5874 proto.offset = 0; 5875 proto[_isInt64] = true; 5876 5877 // methods 5878 proto.toNumber = toNumber; 5879 proto.toString = toString; 5880 proto.toJSON = toNumber; 5881 proto.toArray = toArray; 5882 5883 // add .toBuffer() method only when Buffer available 5884 if (BUFFER) proto.toBuffer = toBuffer; 5885 5886 // add .toArrayBuffer() method only when Uint8Array available 5887 if (UINT8ARRAY) proto.toArrayBuffer = toArrayBuffer; 5888 5889 // isUint64BE, isInt64BE 5890 Int64[isName] = isInt64; 5891 5892 // CommonJS 5893 exports[name] = Int64; 5894 5895 return Int64; 5896 5897 // constructor 5898 function Int64(buffer, offset, value, raddix) { 5899 if (!(this instanceof Int64)) return new Int64(buffer, offset, value, raddix); 5900 return init(this, buffer, offset, value, raddix); 5901 } 5902 5903 // isUint64BE, isInt64BE 5904 function isInt64(b) { 5905 return !!(b && b[_isInt64]); 5906 } 5907 5908 // initializer 5909 function init(that, buffer, offset, value, raddix) { 5910 if (UINT8ARRAY && ARRAYBUFFER) { 5911 if (buffer instanceof ARRAYBUFFER) buffer = new UINT8ARRAY(buffer); 5912 if (value instanceof ARRAYBUFFER) value = new UINT8ARRAY(value); 5913 } 5914 5915 // Int64BE() style 5916 if (!buffer && !offset && !value && !storage) { 5917 // shortcut to initialize with zero 5918 that.buffer = newArray(ZERO, 0); 5919 return; 5920 } 5921 5922 // Int64BE(value, raddix) style 5923 if (!isValidBuffer(buffer, offset)) { 5924 var _storage = storage || Array; 5925 raddix = offset; 5926 value = buffer; 5927 offset = 0; 5928 buffer = new _storage(8); 5929 } 5930 5931 that.buffer = buffer; 5932 that.offset = offset |= 0; 5933 5934 // Int64BE(buffer, offset) style 5935 if (UNDEFINED === typeof value) return; 5936 5937 // Int64BE(buffer, offset, value, raddix) style 5938 if ("string" === typeof value) { 5939 fromString(buffer, offset, value, raddix || 10); 5940 } else if (isValidBuffer(value, raddix)) { 5941 fromArray(buffer, offset, value, raddix); 5942 } else if ("number" === typeof raddix) { 5943 writeInt32(buffer, offset + posH, value); // high 5944 writeInt32(buffer, offset + posL, raddix); // low 5945 } else if (value > 0) { 5946 fromPositive(buffer, offset, value); // positive 5947 } else if (value < 0) { 5948 fromNegative(buffer, offset, value); // negative 5949 } else { 5950 fromArray(buffer, offset, ZERO, 0); // zero, NaN and others 5951 } 5952 } 5953 5954 function fromString(buffer, offset, str, raddix) { 5955 var pos = 0; 5956 var len = str.length; 5957 var high = 0; 5958 var low = 0; 5959 if (str[0] === "-") pos++; 5960 var sign = pos; 5961 while (pos < len) { 5962 var chr = parseInt(str[pos++], raddix); 5963 if (!(chr >= 0)) break; // NaN 5964 low = low * raddix + chr; 5965 high = high * raddix + Math.floor(low / BIT32); 5966 low %= BIT32; 5967 } 5968 if (sign) { 5969 high = ~high; 5970 if (low) { 5971 low = BIT32 - low; 5972 } else { 5973 high++; 5974 } 5975 } 5976 writeInt32(buffer, offset + posH, high); 5977 writeInt32(buffer, offset + posL, low); 5978 } 5979 5980 function toNumber() { 5981 var buffer = this.buffer; 5982 var offset = this.offset; 5983 var high = readInt32(buffer, offset + posH); 5984 var low = readInt32(buffer, offset + posL); 5985 if (!unsigned) high |= 0; // a trick to get signed 5986 return high ? (high * BIT32 + low) : low; 5987 } 5988 5989 function toString(radix) { 5990 var buffer = this.buffer; 5991 var offset = this.offset; 5992 var high = readInt32(buffer, offset + posH); 5993 var low = readInt32(buffer, offset + posL); 5994 var str = ""; 5995 var sign = !unsigned && (high & 0x80000000); 5996 if (sign) { 5997 high = ~high; 5998 low = BIT32 - low; 5999 } 6000 radix = radix || 10; 6001 while (1) { 6002 var mod = (high % radix) * BIT32 + low; 6003 high = Math.floor(high / radix); 6004 low = Math.floor(mod / radix); 6005 str = (mod % radix).toString(radix) + str; 6006 if (!high && !low) break; 6007 } 6008 if (sign) { 6009 str = "-" + str; 6010 } 6011 return str; 6012 } 6013 6014 function writeInt32(buffer, offset, value) { 6015 buffer[offset + pos3] = value & 255; 6016 value = value >> 8; 6017 buffer[offset + pos2] = value & 255; 6018 value = value >> 8; 6019 buffer[offset + pos1] = value & 255; 6020 value = value >> 8; 6021 buffer[offset + pos0] = value & 255; 6022 } 6023 6024 function readInt32(buffer, offset) { 6025 return (buffer[offset + pos0] * BIT24) + 6026 (buffer[offset + pos1] << 16) + 6027 (buffer[offset + pos2] << 8) + 6028 buffer[offset + pos3]; 6029 } 6030 } 6031 6032 function toArray(raw) { 6033 var buffer = this.buffer; 6034 var offset = this.offset; 6035 storage = null; // Array 6036 if (raw !== false && offset === 0 && buffer.length === 8 && isArray(buffer)) return buffer; 6037 return newArray(buffer, offset); 6038 } 6039 6040 function toBuffer(raw) { 6041 var buffer = this.buffer; 6042 var offset = this.offset; 6043 storage = BUFFER; 6044 if (raw !== false && offset === 0 && buffer.length === 8 && Buffer.isBuffer(buffer)) return buffer; 6045 var dest = new BUFFER(8); 6046 fromArray(dest, 0, buffer, offset); 6047 return dest; 6048 } 6049 6050 function toArrayBuffer(raw) { 6051 var buffer = this.buffer; 6052 var offset = this.offset; 6053 var arrbuf = buffer.buffer; 6054 storage = UINT8ARRAY; 6055 if (raw !== false && offset === 0 && (arrbuf instanceof ARRAYBUFFER) && arrbuf.byteLength === 8) return arrbuf; 6056 var dest = new UINT8ARRAY(8); 6057 fromArray(dest, 0, buffer, offset); 6058 return dest.buffer; 6059 } 6060 6061 function isValidBuffer(buffer, offset) { 6062 var len = buffer && buffer.length; 6063 offset |= 0; 6064 return len && (offset + 8 <= len) && ("string" !== typeof buffer[offset]); 6065 } 6066 6067 function fromArray(destbuf, destoff, srcbuf, srcoff) { 6068 destoff |= 0; 6069 srcoff |= 0; 6070 for (var i = 0; i < 8; i++) { 6071 destbuf[destoff++] = srcbuf[srcoff++] & 255; 6072 } 6073 } 6074 6075 function newArray(buffer, offset) { 6076 return Array.prototype.slice.call(buffer, offset, offset + 8); 6077 } 6078 6079 function fromPositiveBE(buffer, offset, value) { 6080 var pos = offset + 8; 6081 while (pos > offset) { 6082 buffer[--pos] = value & 255; 6083 value /= 256; 6084 } 6085 } 6086 6087 function fromNegativeBE(buffer, offset, value) { 6088 var pos = offset + 8; 6089 value++; 6090 while (pos > offset) { 6091 buffer[--pos] = ((-value) & 255) ^ 255; 6092 value /= 256; 6093 } 6094 } 6095 6096 function fromPositiveLE(buffer, offset, value) { 6097 var end = offset + 8; 6098 while (offset < end) { 6099 buffer[offset++] = value & 255; 6100 value /= 256; 6101 } 6102 } 6103 6104 function fromNegativeLE(buffer, offset, value) { 6105 var end = offset + 8; 6106 value++; 6107 while (offset < end) { 6108 buffer[offset++] = ((-value) & 255) ^ 255; 6109 value /= 256; 6110 } 6111 } 6112 6113 // https://github.com/retrofox/is-array 6114 function _isArray(val) { 6115 return !!val && "[object Array]" == Object.prototype.toString.call(val); 6116 } 6117 6118 }(typeof exports === 'object' && typeof exports.nodeName !== 'string' ? exports : (this || {})); 6119 6120 }).call(this)}).call(this,require("buffer").Buffer) 6121 },{"buffer":7}],16:[function(require,module,exports){ 6122 var toString = {}.toString; 6123 6124 module.exports = Array.isArray || function (arr) { 6125 return toString.call(arr) == '[object Array]'; 6126 }; 6127 6128 },{}],17:[function(require,module,exports){ 6129 /*jslint node: true, vars: true, nomen: true */ 6130 'use strict'; 6131 6132 var byEbmlID = { 6133 0x80: { 6134 name: "ChapterDisplay", 6135 level: 4, 6136 type: "m", 6137 multiple: true, 6138 webm: true, 6139 description: "Contains all possible strings to use for the chapter display." 6140 }, 6141 0x83: { 6142 name: "TrackType", 6143 level: 3, 6144 type: "u", 6145 mandatory: true, 6146 description: "The `TrackType` defines the type of each frame found in the Track. The value **SHOULD** be stored on 1 octet." 6147 }, 6148 0x85: { 6149 name: "ChapString", 6150 cppname: "ChapterString", 6151 level: 5, 6152 type: "8", 6153 mandatory: true, 6154 webm: true, 6155 description: "Contains the string to use as the chapter atom." 6156 }, 6157 0x86: { 6158 name: "CodecID", 6159 level: 3, 6160 type: "s", 6161 mandatory: true, 6162 description: "An ID corresponding to the codec, see [@!MatroskaCodec] for more info." 6163 }, 6164 0x88: { 6165 name: "FlagDefault", 6166 cppname: "TrackFlagDefault", 6167 level: 3, 6168 type: "u", 6169 mandatory: true, 6170 "default": "1", 6171 range: "0-1", 6172 description: "Set if that track (audio, video or subs) **SHOULD** be eligible for automatic selection by the player; see (#default-track-selection) for more details." 6173 }, 6174 0x89: { 6175 name: "ChapterTrackUID", 6176 cppname: "ChapterTrackNumber", 6177 level: 5, 6178 type: "u", 6179 mandatory: true, 6180 multiple: true, 6181 range: "not 0", 6182 description: "UID of the Track to apply this chapter to. In the absence of a control track, choosing this chapter will select the listed Tracks and deselect unlisted tracks. Absence of this Element indicates that the Chapter **SHOULD** be applied to any currently used Tracks." 6183 }, 6184 0x8e: { 6185 name: "Slices", 6186 level: 3, 6187 type: "m", 6188 maxver: 1, 6189 description: "Contains slices description." 6190 }, 6191 0x8f: { 6192 name: "ChapterTrack", 6193 level: 4, 6194 type: "m", 6195 description: "List of tracks on which the chapter applies. If this Element is not present, all tracks apply" 6196 }, 6197 0x91: { 6198 name: "ChapterTimeStart", 6199 level: 4, 6200 type: "u", 6201 mandatory: true, 6202 webm: true, 6203 description: "Timestamp of the start of Chapter, expressed in Matroska Ticks -- ie in nanoseconds; see (#timestamp-ticks)." 6204 }, 6205 0x92: { 6206 name: "ChapterTimeEnd", 6207 level: 4, 6208 type: "u", 6209 webm: true, 6210 description: "Timestamp of the end of Chapter timestamp excluded, expressed in Matroska Ticks -- ie in nanoseconds; see (#timestamp-ticks). The value **MUST** be greater than or equal to the `ChapterTimeStart` of the same `ChapterAtom`." 6211 }, 6212 0x96: { 6213 name: "CueRefTime", 6214 level: 5, 6215 type: "u", 6216 mandatory: true, 6217 minver: 2, 6218 description: "Timestamp of the referenced Block, expressed in Matroska Ticks -- ie in nanoseconds; see (#timestamp-ticks)." 6219 }, 6220 0x97: { 6221 name: "CueRefCluster", 6222 level: 5, 6223 type: "u", 6224 mandatory: true, 6225 minver: 0, 6226 maxver: 0, 6227 description: "The Segment Position of the Cluster containing the referenced Block." 6228 }, 6229 0x98: { 6230 name: "ChapterFlagHidden", 6231 level: 4, 6232 type: "u", 6233 mandatory: true, 6234 "default": "0", 6235 range: "0-1", 6236 description: "Set to 1 if a chapter is hidden. Hidden chapters **SHOULD NOT** be available to the user interface (but still to Control Tracks; see (#chapterflaghidden) on Chapter flags)." 6237 }, 6238 0x9a: { 6239 name: "FlagInterlaced", 6240 cppname: "VideoFlagInterlaced", 6241 level: 4, 6242 type: "u", 6243 mandatory: true, 6244 minver: 2, 6245 webm: true, 6246 "default": "0", 6247 description: "Specify whether the video frames in this track are interlaced or not." 6248 }, 6249 0x9b: { 6250 name: "BlockDuration", 6251 level: 3, 6252 type: "u", 6253 description: "The duration of the Block, expressed in Track Ticks; see (#timestamp-ticks). The BlockDuration Element can be useful at the end of a Track to define the duration of the last frame (as there is no subsequent Block available), or when there is a break in a track like for subtitle tracks." 6254 }, 6255 0x9c: { 6256 name: "FlagLacing", 6257 cppname: "TrackFlagLacing", 6258 level: 3, 6259 type: "u", 6260 mandatory: true, 6261 "default": "1", 6262 range: "0-1", 6263 description: "Set to 1 if the track **MAY** contain blocks using lacing. When set to 0 all blocks **MUST** have their lacing flags set to No lacing; see (#block-lacing) on Block Lacing." 6264 }, 6265 0x9d: { 6266 name: "FieldOrder", 6267 cppname: "VideoFieldOrder", 6268 level: 4, 6269 type: "u", 6270 mandatory: true, 6271 minver: 4, 6272 "default": "2", 6273 description: "Specify the field ordering of video frames in this track." 6274 }, 6275 0x9f: { 6276 name: "Channels", 6277 cppname: "AudioChannels", 6278 level: 4, 6279 type: "u", 6280 mandatory: true, 6281 "default": "1", 6282 range: "not 0", 6283 description: "Numbers of channels in the track." 6284 }, 6285 0xa0: { 6286 name: "BlockGroup", 6287 level: 2, 6288 type: "m", 6289 multiple: true, 6290 description: "Basic container of information containing a single Block and information specific to that Block." 6291 }, 6292 0xa1: { 6293 name: "Block", 6294 level: 3, 6295 type: "b", 6296 mandatory: true, 6297 description: "Block containing the actual data to be rendered and a timestamp relative to the Cluster Timestamp; see (#block-structure) on Block Structure." 6298 }, 6299 0xa2: { 6300 name: "BlockVirtual", 6301 level: 3, 6302 type: "b", 6303 minver: 0, 6304 maxver: 0, 6305 description: "A Block with no data. It **MUST** be stored in the stream at the place the real Block would be in display order. " 6306 }, 6307 0xa3: { 6308 name: "SimpleBlock", 6309 level: 2, 6310 type: "b", 6311 multiple: true, 6312 minver: 2, 6313 webm: true, 6314 divx: true, 6315 description: "Similar to Block, see (#block-structure), but without all the extra information, mostly used to reduced overhead when no extra feature is needed; see (#simpleblock-structure) on SimpleBlock Structure." 6316 }, 6317 0xa4: { 6318 name: "CodecState", 6319 level: 3, 6320 type: "b", 6321 minver: 2, 6322 description: "The new codec state to use. Data interpretation is private to the codec. This information **SHOULD** always be referenced by a seek entry." 6323 }, 6324 0xa5: { 6325 name: "BlockAdditional", 6326 level: 5, 6327 type: "b", 6328 mandatory: true, 6329 webm: true, 6330 description: "Interpreted by the codec as it wishes (using the BlockAddID)." 6331 }, 6332 0xa6: { 6333 name: "BlockMore", 6334 level: 4, 6335 type: "m", 6336 mandatory: true, 6337 multiple: true, 6338 webm: true, 6339 description: "Contain the BlockAdditional and some parameters." 6340 }, 6341 0xa7: { 6342 name: "Position", 6343 cppname: "ClusterPosition", 6344 level: 2, 6345 type: "u", 6346 description: "The Segment Position of the Cluster in the Segment (0 in live streams). It might help to resynchronise offset on damaged streams." 6347 }, 6348 0xaa: { 6349 name: "CodecDecodeAll", 6350 level: 3, 6351 type: "u", 6352 mandatory: true, 6353 maxver: 0, 6354 "default": "1", 6355 range: "0-1", 6356 description: "Set to 1 if the codec can decode potentially damaged data." 6357 }, 6358 0xab: { 6359 name: "PrevSize", 6360 cppname: "ClusterPrevSize", 6361 level: 2, 6362 type: "u", 6363 description: "Size of the previous Cluster, in octets. Can be useful for backward playing." 6364 }, 6365 0xae: { 6366 name: "TrackEntry", 6367 level: 2, 6368 type: "m", 6369 mandatory: true, 6370 multiple: true, 6371 description: "Describes a track with all Elements." 6372 }, 6373 0xaf: { 6374 name: "EncryptedBlock", 6375 level: 2, 6376 type: "b", 6377 multiple: true, 6378 minver: 0, 6379 maxver: 0, 6380 description: "Similar to SimpleBlock, see (#simpleblock-structure), but the data inside the Block are Transformed (encrypt and/or signed)." 6381 }, 6382 0xb0: { 6383 name: "PixelWidth", 6384 cppname: "VideoPixelWidth", 6385 level: 4, 6386 type: "u", 6387 mandatory: true, 6388 range: "not 0", 6389 description: "Width of the encoded video frames in pixels." 6390 }, 6391 0xb2: { 6392 name: "CueDuration", 6393 level: 4, 6394 type: "u", 6395 minver: 4, 6396 webm: true, 6397 description: "The duration of the block, expressed in Segment Ticks which is based on TimestampScale; see (#timestamp-ticks). If missing, the track's DefaultDuration does not apply and no duration information is available in terms of the cues." 6398 }, 6399 0xb3: { 6400 name: "CueTime", 6401 level: 3, 6402 type: "u", 6403 mandatory: true, 6404 description: "Absolute timestamp of the seek point, expressed in Matroska Ticks -- ie in nanoseconds; see (#timestamp-ticks)." 6405 }, 6406 0xb5: { 6407 name: "SamplingFrequency", 6408 cppname: "AudioSamplingFreq", 6409 level: 4, 6410 type: "f", 6411 mandatory: true, 6412 "default": "0x1.f4p+12", 6413 range: "> 0x0p+0", 6414 description: "Sampling frequency in Hz." 6415 }, 6416 0xb6: { 6417 name: "ChapterAtom", 6418 level: 3, 6419 type: "m", 6420 mandatory: true, 6421 multiple: true, 6422 webm: true, 6423 description: "Contains the atom information to use as the chapter atom (apply to all tracks)." 6424 }, 6425 0xb7: { 6426 name: "CueTrackPositions", 6427 level: 3, 6428 type: "m", 6429 mandatory: true, 6430 multiple: true, 6431 description: "Contain positions for different tracks corresponding to the timestamp." 6432 }, 6433 0xb9: { 6434 name: "FlagEnabled", 6435 cppname: "TrackFlagEnabled", 6436 level: 3, 6437 type: "u", 6438 mandatory: true, 6439 minver: 2, 6440 webm: true, 6441 "default": "1", 6442 range: "0-1", 6443 description: "Set to 1 if the track is usable. It is possible to turn a not usable track into a usable track using chapter codecs or control tracks." 6444 }, 6445 0xba: { 6446 name: "PixelHeight", 6447 cppname: "VideoPixelHeight", 6448 level: 4, 6449 type: "u", 6450 mandatory: true, 6451 range: "not 0", 6452 description: "Height of the encoded video frames in pixels." 6453 }, 6454 0xbb: { 6455 name: "CuePoint", 6456 level: 2, 6457 type: "m", 6458 mandatory: true, 6459 multiple: true, 6460 description: "Contains all information relative to a seek point in the Segment." 6461 }, 6462 0xbf: { 6463 name: "CRC-32", 6464 level: -1, 6465 type: "b", 6466 minver: 1, 6467 webm: false, 6468 description: "The CRC is computed on all the data of the Master element it's in. The CRC element should be the first in it's parent master for easier reading. All level 1 elements should include a CRC-32. The CRC in use is the IEEE CRC32 Little Endian", 6469 crc: true 6470 }, 6471 0xc0: { 6472 name: "TrickTrackUID", 6473 level: 3, 6474 type: "u", 6475 minver: 0, 6476 maxver: 0, 6477 divx: true, 6478 description: "The TrackUID of the Smooth FF/RW video in the paired EBML structure corresponding to this video track. See [@?DivXTrickTrack]." 6479 }, 6480 0xc1: { 6481 name: "TrickTrackSegmentUID", 6482 level: 3, 6483 type: "b", 6484 minver: 0, 6485 maxver: 0, 6486 divx: true, 6487 description: "The SegmentUID of the Segment containing the track identified by TrickTrackUID. See [@?DivXTrickTrack]." 6488 }, 6489 0xc4: { 6490 name: "TrickMasterTrackSegmentUID", 6491 level: 3, 6492 type: "b", 6493 minver: 0, 6494 maxver: 0, 6495 divx: true, 6496 description: "The SegmentUID of the Segment containing the track identified by MasterTrackUID. See [@?DivXTrickTrack]." 6497 }, 6498 0xc6: { 6499 name: "TrickTrackFlag", 6500 level: 3, 6501 type: "u", 6502 minver: 0, 6503 maxver: 0, 6504 divx: true, 6505 "default": "0", 6506 description: "Set to 1 if this video track is a Smooth FF/RW track. If set to 1, MasterTrackUID and MasterTrackSegUID should must be present and BlockGroups for this track must contain ReferenceFrame structures. Otherwise, TrickTrackUID and TrickTrackSegUID must be present if this track has a corresponding Smooth FF/RW track. See [@?DivXTrickTrack]." 6507 }, 6508 0xc7: { 6509 name: "TrickMasterTrackUID", 6510 level: 3, 6511 type: "u", 6512 minver: 0, 6513 maxver: 0, 6514 divx: true, 6515 description: "The TrackUID of the video track in the paired EBML structure that corresponds to this Smooth FF/RW track. See [@?DivXTrickTrack]." 6516 }, 6517 0xc8: { 6518 name: "ReferenceFrame", 6519 level: 3, 6520 type: "m", 6521 minver: 0, 6522 maxver: 0, 6523 divx: true, 6524 description: "Contains information about the last reference frame. See [@?DivXTrickTrack]." 6525 }, 6526 0xc9: { 6527 name: "ReferenceOffset", 6528 level: 4, 6529 type: "u", 6530 mandatory: true, 6531 minver: 0, 6532 maxver: 0, 6533 divx: true, 6534 description: "The relative offset, in bytes, from the previous BlockGroup element for this Smooth FF/RW video track to the containing BlockGroup element. See [@?DivXTrickTrack]." 6535 }, 6536 0xca: { 6537 name: "ReferenceTimestamp", 6538 cppname: "ReferenceTimeCode", 6539 level: 4, 6540 type: "u", 6541 mandatory: true, 6542 minver: 0, 6543 maxver: 0, 6544 divx: true, 6545 description: "The timestamp of the BlockGroup pointed to by ReferenceOffset, expressed in Track Ticks; see (#timestamp-ticks). See [@?DivXTrickTrack]." 6546 }, 6547 0xcb: { 6548 name: "BlockAdditionID", 6549 cppname: "SliceBlockAddID", 6550 level: 5, 6551 type: "u", 6552 minver: 0, 6553 maxver: 0, 6554 "default": "0", 6555 description: "The ID of the BlockAdditional Element (0 is the main Block)." 6556 }, 6557 0xcc: { 6558 name: "LaceNumber", 6559 cppname: "SliceLaceNumber", 6560 level: 5, 6561 type: "u", 6562 minver: 0, 6563 maxver: 0, 6564 description: "The reverse number of the frame in the lace (0 is the last frame, 1 is the next to last, etc). Being able to interpret this Element is not **REQUIRED** for playback." 6565 }, 6566 0xcd: { 6567 name: "FrameNumber", 6568 cppname: "SliceFrameNumber", 6569 level: 5, 6570 type: "u", 6571 minver: 0, 6572 maxver: 0, 6573 "default": "0", 6574 description: "The number of the frame to generate from this lace with this delay (allow you to generate many frames from the same Block/Frame)." 6575 }, 6576 0xce: { 6577 name: "Delay", 6578 cppname: "SliceDelay", 6579 level: 5, 6580 type: "u", 6581 minver: 0, 6582 maxver: 0, 6583 "default": "0", 6584 description: "The delay to apply to the Element, expressed in Track Ticks; see (#timestamp-ticks)." 6585 }, 6586 0xcf: { 6587 name: "SliceDuration", 6588 level: 5, 6589 type: "u", 6590 minver: 0, 6591 maxver: 0, 6592 "default": "0", 6593 description: "The duration to apply to the Element, expressed in Track Ticks; see (#timestamp-ticks)." 6594 }, 6595 0xd7: { 6596 name: "TrackNumber", 6597 level: 3, 6598 type: "u", 6599 mandatory: true, 6600 range: "not 0", 6601 description: "The track number as used in the Block Header (using more than 127 tracks is not encouraged, though the design allows an unlimited number)." 6602 }, 6603 0xdb: { 6604 name: "CueReference", 6605 level: 4, 6606 type: "m", 6607 multiple: true, 6608 minver: 2, 6609 description: "The Clusters containing the referenced Blocks." 6610 }, 6611 0xe0: { 6612 name: "Video", 6613 cppname: "TrackVideo", 6614 level: 3, 6615 type: "m", 6616 description: "Video settings." 6617 }, 6618 0xe1: { 6619 name: "Audio", 6620 cppname: "TrackAudio", 6621 level: 3, 6622 type: "m", 6623 description: "Audio settings." 6624 }, 6625 0xe2: { 6626 name: "TrackOperation", 6627 level: 3, 6628 type: "m", 6629 minver: 3, 6630 description: "Operation that needs to be applied on tracks to create this virtual track. For more details look at (#track-operation)." 6631 }, 6632 0xe3: { 6633 name: "TrackCombinePlanes", 6634 level: 4, 6635 type: "m", 6636 minver: 3, 6637 description: "Contains the list of all video plane tracks that need to be combined to create this 3D track" 6638 }, 6639 0xe4: { 6640 name: "TrackPlane", 6641 level: 5, 6642 type: "m", 6643 mandatory: true, 6644 multiple: true, 6645 minver: 3, 6646 description: "Contains a video plane track that need to be combined to create this 3D track" 6647 }, 6648 0xe5: { 6649 name: "TrackPlaneUID", 6650 level: 6, 6651 type: "u", 6652 mandatory: true, 6653 minver: 3, 6654 range: "not 0", 6655 description: "The trackUID number of the track representing the plane." 6656 }, 6657 0xe6: { 6658 name: "TrackPlaneType", 6659 level: 6, 6660 type: "u", 6661 mandatory: true, 6662 minver: 3, 6663 description: "The kind of plane this track corresponds to." 6664 }, 6665 0xe7: { 6666 name: "Timestamp", 6667 cppname: "ClusterTimecode", 6668 level: 2, 6669 type: "u", 6670 mandatory: true, 6671 description: "Absolute timestamp of the cluster, expressed in Segment Ticks which is based on TimestampScale; see (#timestamp-ticks)." 6672 }, 6673 0xe8: { 6674 name: "TimeSlice", 6675 level: 4, 6676 type: "m", 6677 multiple: true, 6678 minver: 0, 6679 maxver: 0, 6680 description: "Contains extra time information about the data contained in the Block. Being able to interpret this Element is not **REQUIRED** for playback." 6681 }, 6682 0xe9: { 6683 name: "TrackJoinBlocks", 6684 level: 4, 6685 type: "m", 6686 minver: 3, 6687 description: "Contains the list of all tracks whose Blocks need to be combined to create this virtual track" 6688 }, 6689 0xea: { 6690 name: "CueCodecState", 6691 level: 4, 6692 type: "u", 6693 mandatory: true, 6694 minver: 2, 6695 "default": "0", 6696 description: "The Segment Position of the Codec State corresponding to this Cue Element. 0 means that the data is taken from the initial Track Entry." 6697 }, 6698 0xeb: { 6699 name: "CueRefCodecState", 6700 level: 5, 6701 type: "u", 6702 minver: 0, 6703 maxver: 0, 6704 "default": "0", 6705 description: "The Segment Position of the Codec State corresponding to this referenced Element. 0 means that the data is taken from the initial Track Entry." 6706 }, 6707 0xec: { 6708 name: "Void", 6709 level: -1, 6710 type: "b", 6711 minver: 1, 6712 description: "Used to void damaged data, to avoid unexpected behaviors when using damaged data. The content is discarded. Also used to reserve space in a sub-element for later use." 6713 }, 6714 0xed: { 6715 name: "TrackJoinUID", 6716 level: 5, 6717 type: "u", 6718 mandatory: true, 6719 multiple: true, 6720 minver: 3, 6721 range: "not 0", 6722 description: "The trackUID number of a track whose blocks are used to create this virtual track." 6723 }, 6724 0xee: { 6725 name: "BlockAddID", 6726 level: 5, 6727 type: "u", 6728 mandatory: true, 6729 webm: true, 6730 "default": "1", 6731 range: "not 0", 6732 description: "An ID to identify the BlockAdditional level. If BlockAddIDType of the corresponding block is 0, this value is also the value of BlockAddIDType for the meaning of the content of BlockAdditional." 6733 }, 6734 0xf0: { 6735 name: "CueRelativePosition", 6736 level: 4, 6737 type: "u", 6738 minver: 4, 6739 webm: true, 6740 description: "The relative position inside the Cluster of the referenced SimpleBlock or BlockGroup with 0 being the first possible position for an Element inside that Cluster." 6741 }, 6742 0xf1: { 6743 name: "CueClusterPosition", 6744 level: 4, 6745 type: "u", 6746 mandatory: true, 6747 description: "The Segment Position of the Cluster containing the associated Block." 6748 }, 6749 0xf7: { 6750 name: "CueTrack", 6751 level: 4, 6752 type: "u", 6753 mandatory: true, 6754 range: "not 0", 6755 description: "The track for which a position is given." 6756 }, 6757 0xfa: { 6758 name: "ReferencePriority", 6759 level: 3, 6760 type: "u", 6761 mandatory: true, 6762 "default": "0", 6763 description: "This frame is referenced and has the specified cache priority. In cache only a frame of the same or higher priority can replace this frame. A value of 0 means the frame is not referenced." 6764 }, 6765 0xfb: { 6766 name: "ReferenceBlock", 6767 level: 3, 6768 type: "i", 6769 multiple: true, 6770 description: "A timestamp value, relative to the timestamp of the Block in this BlockGroup, expressed in Track Ticks; see (#timestamp-ticks). This is used to reference other frames necessary to decode this frame. The relative value **SHOULD** correspond to a valid `Block` this `Block` depends on. Historically Matroska Writer didn't write the actual `Block(s)` this `Block` depends on, but *some* `Block` in the past. The value \"0\" **MAY** also be used to signify this `Block` cannot be decoded on its own, but without knownledge of which `Block` is necessary. In this case, other `ReferenceBlock` **MUST NOT** be found in the same `BlockGroup`. If the `BlockGroup` doesn't have any `ReferenceBlock` element, then the `Block` it contains can be decoded without using any other `Block` data." 6771 }, 6772 0xfd: { 6773 name: "ReferenceVirtual", 6774 level: 3, 6775 type: "i", 6776 minver: 0, 6777 maxver: 0, 6778 description: "The Segment Position of the data that would otherwise be in position of the virtual block." 6779 }, 6780 0x41a4: { 6781 name: "BlockAddIDName", 6782 level: 4, 6783 type: "s", 6784 minver: 4, 6785 description: "A human-friendly name describing the type of BlockAdditional data, as defined by the associated Block Additional Mapping." 6786 }, 6787 0x41e4: { 6788 name: "BlockAdditionMapping", 6789 level: 3, 6790 type: "m", 6791 multiple: true, 6792 minver: 4, 6793 description: "Contains elements that extend the track format, by adding content either to each frame, with BlockAddID ((#blockaddid-element)), or to the track as a whole with BlockAddIDExtraData." 6794 }, 6795 0x41e7: { 6796 name: "BlockAddIDType", 6797 level: 4, 6798 type: "u", 6799 mandatory: true, 6800 minver: 4, 6801 "default": "0", 6802 description: "Stores the registered identifier of the Block Additional Mapping to define how the BlockAdditional data should be handled." 6803 }, 6804 0x41ed: { 6805 name: "BlockAddIDExtraData", 6806 level: 4, 6807 type: "b", 6808 minver: 4, 6809 description: "Extra binary data that the BlockAddIDType can use to interpret the BlockAdditional data. The interpretation of the binary data depends on the BlockAddIDType value and the corresponding Block Additional Mapping." 6810 }, 6811 0x41f0: { 6812 name: "BlockAddIDValue", 6813 level: 4, 6814 type: "u", 6815 minver: 4, 6816 range: ">=2", 6817 description: "If the track format extension needs content beside frames, the value refers to the BlockAddID ((#blockaddid-element)), value being described. To keep MaxBlockAdditionID as low as possible, small values **SHOULD** be used." 6818 }, 6819 0x4254: { 6820 name: "ContentCompAlgo", 6821 level: 6, 6822 type: "u", 6823 mandatory: true, 6824 "default": "0", 6825 description: "The compression algorithm used." 6826 }, 6827 0x4255: { 6828 name: "ContentCompSettings", 6829 level: 6, 6830 type: "b", 6831 description: "Settings that might be needed by the decompressor. For Header Stripping (`ContentCompAlgo`=3), the bytes that were removed from the beginning of each frames of the track." 6832 }, 6833 0x4282: { 6834 name: "DocType", 6835 level: 1, 6836 type: "s", 6837 mandatory: true, 6838 "default": "matroska", 6839 minver: 1, 6840 description: "A string that describes the type of document that follows this EBML header. 'matroska' in our case or 'webm' for webm files." 6841 }, 6842 0x4285: { 6843 name: "DocTypeReadVersion", 6844 level: 1, 6845 type: "u", 6846 mandatory: true, 6847 "default": 1, 6848 minver: 1, 6849 description: "The minimum DocType version an interpreter has to support to read this file." 6850 }, 6851 0x4286: { 6852 name: "EBMLVersion", 6853 level: 1, 6854 type: "u", 6855 mandatory: true, 6856 "default": 1, 6857 minver: 1, 6858 description: "The version of EBML parser used to create the file." 6859 }, 6860 0x4287: { 6861 name: "DocTypeVersion", 6862 level: 1, 6863 type: "u", 6864 mandatory: true, 6865 "default": 1, 6866 minver: 1, 6867 description: "The version of DocType interpreter used to create the file." 6868 }, 6869 0x42f2: { 6870 name: "EBMLMaxIDLength", 6871 level: 1, 6872 type: "u", 6873 mandatory: true, 6874 "default": "4", 6875 range: "4" 6876 }, 6877 0x42f3: { 6878 name: "EBMLMaxSizeLength", 6879 level: 1, 6880 type: "u", 6881 mandatory: true, 6882 "default": "8", 6883 range: "1-8" 6884 }, 6885 0x42f7: { 6886 name: "EBMLReadVersion", 6887 level: 1, 6888 type: "u", 6889 mandatory: true, 6890 "default": 1, 6891 minver: 1, 6892 description: "The minimum EBML version a parser has to support to read this file." 6893 }, 6894 0x437c: { 6895 name: "ChapLanguage", 6896 cppname: "ChapterLanguage", 6897 level: 5, 6898 type: "s", 6899 mandatory: true, 6900 multiple: true, 6901 webm: true, 6902 "default": "eng", 6903 description: "A language corresponding to the string, in the bibliographic ISO-639-2 form [@!ISO639-2]. This Element **MUST** be ignored if a ChapLanguageIETF Element is used within the same ChapterDisplay Element." 6904 }, 6905 0x437d: { 6906 name: "ChapLanguageIETF", 6907 level: 5, 6908 type: "s", 6909 multiple: true, 6910 minver: 4, 6911 description: "Specifies a language corresponding to the ChapString in the format defined in [@!BCP47] and using the IANA Language Subtag Registry [@!IANALangRegistry]. If a ChapLanguageIETF Element is used, then any ChapLanguage and ChapCountry Elements used in the same ChapterDisplay **MUST** be ignored." 6912 }, 6913 0x437e: { 6914 name: "ChapCountry", 6915 cppname: "ChapterCountry", 6916 level: 5, 6917 type: "s", 6918 multiple: true, 6919 webm: true, 6920 description: "A country corresponding to the string, using the same 2 octets country-codes as in Internet domains [@!IANADomains] based on [@!ISO3166-1] alpha-2 codes. This Element **MUST** be ignored if a ChapLanguageIETF Element is used within the same ChapterDisplay Element." 6921 }, 6922 0x4444: { 6923 name: "SegmentFamily", 6924 level: 2, 6925 type: "b", 6926 multiple: true, 6927 description: "A randomly generated unique ID that all Segments of a Linked Segment **MUST** share (128 bits)." 6928 }, 6929 0x4461: { 6930 name: "DateUTC", 6931 level: 2, 6932 type: "d", 6933 description: "The date and time that the Segment was created by the muxing application or library." 6934 }, 6935 0x447a: { 6936 name: "TagLanguage", 6937 cppname: "TagLangue", 6938 level: 4, 6939 type: "s", 6940 mandatory: true, 6941 webm: true, 6942 "default": "und", 6943 description: "Specifies the language of the tag specified, in the Matroska languages form; see (#language-codes) on language codes. This Element **MUST** be ignored if the TagLanguageIETF Element is used within the same SimpleTag Element." 6944 }, 6945 0x447b: { 6946 name: "TagLanguageIETF", 6947 level: 4, 6948 type: "s", 6949 minver: 4, 6950 description: "Specifies the language used in the TagString according to [@!BCP47] and using the IANA Language Subtag Registry [@!IANALangRegistry]. If this Element is used, then any TagLanguage Elements used in the same SimpleTag **MUST** be ignored." 6951 }, 6952 0x4484: { 6953 name: "TagDefault", 6954 level: 4, 6955 type: "u", 6956 mandatory: true, 6957 webm: true, 6958 "default": "1", 6959 range: "0-1", 6960 description: "A boolean value to indicate if this is the default/original language to use for the given tag." 6961 }, 6962 0x4485: { 6963 name: "TagBinary", 6964 level: 4, 6965 type: "b", 6966 webm: true, 6967 description: "The values of the Tag, if it is binary. Note that this cannot be used in the same SimpleTag as TagString." 6968 }, 6969 0x4487: { 6970 name: "TagString", 6971 level: 4, 6972 type: "8", 6973 webm: true, 6974 description: "The value of the Tag." 6975 }, 6976 0x4489: { 6977 name: "Duration", 6978 level: 2, 6979 type: "f", 6980 range: "> 0x0p+0", 6981 description: "Duration of the Segment, expressed in Segment Ticks which is based on TimestampScale; see (#timestamp-ticks)." 6982 }, 6983 0x44b4: { 6984 name: "TagDefaultBogus", 6985 level: 4, 6986 type: "u", 6987 mandatory: true, 6988 minver: 0, 6989 maxver: 0, 6990 "default": "1", 6991 range: "0-1", 6992 description: "A variant of the TagDefault element with a bogus Element ID; see (#tagdefault-element)." 6993 }, 6994 0x450d: { 6995 name: "ChapProcessPrivate", 6996 cppname: "ChapterProcessPrivate", 6997 level: 5, 6998 type: "b", 6999 description: "Some optional data attached to the ChapProcessCodecID information. For ChapProcessCodecID = 1, it is the \"DVD level\" equivalent; see (#menu-features) on DVD menus." 7000 }, 7001 0x4598: { 7002 name: "ChapterFlagEnabled", 7003 level: 4, 7004 type: "u", 7005 mandatory: true, 7006 "default": "1", 7007 range: "0-1", 7008 description: "Set to 1 if the chapter is enabled. It can be enabled/disabled by a Control Track. When disabled, the movie **SHOULD** skip all the content between the TimeStart and TimeEnd of this chapter; see (#chapter-flags) on Chapter flags." 7009 }, 7010 0x45a3: { 7011 name: "TagName", 7012 level: 4, 7013 type: "8", 7014 mandatory: true, 7015 webm: true, 7016 description: "The name of the Tag that is going to be stored." 7017 }, 7018 0x45b9: { 7019 name: "EditionEntry", 7020 level: 2, 7021 type: "m", 7022 mandatory: true, 7023 multiple: true, 7024 webm: true, 7025 description: "Contains all information about a Segment edition." 7026 }, 7027 0x45bc: { 7028 name: "EditionUID", 7029 level: 3, 7030 type: "u", 7031 range: "not 0", 7032 description: "A unique ID to identify the edition. It's useful for tagging an edition." 7033 }, 7034 0x45bd: { 7035 name: "EditionFlagHidden", 7036 level: 3, 7037 type: "u", 7038 mandatory: true, 7039 "default": "0", 7040 range: "0-1", 7041 description: "Set to 1 if an edition is hidden. Hidden editions **SHOULD NOT** be available to the user interface (but still to Control Tracks; see (#chapter-flags) on Chapter flags)." 7042 }, 7043 0x45db: { 7044 name: "EditionFlagDefault", 7045 level: 3, 7046 type: "u", 7047 mandatory: true, 7048 "default": "0", 7049 range: "0-1", 7050 description: "Set to 1 if the edition **SHOULD** be used as the default one." 7051 }, 7052 0x45dd: { 7053 name: "EditionFlagOrdered", 7054 level: 3, 7055 type: "u", 7056 mandatory: true, 7057 "default": "0", 7058 range: "0-1", 7059 description: "Set to 1 if the chapters can be defined multiple times and the order to play them is enforced; see (#editionflagordered)." 7060 }, 7061 0x465c: { 7062 name: "FileData", 7063 level: 3, 7064 type: "b", 7065 mandatory: true, 7066 description: "The data of the file." 7067 }, 7068 0x4660: { 7069 name: "FileMimeType", 7070 cppname: "MimeType", 7071 level: 3, 7072 type: "s", 7073 mandatory: true, 7074 description: "MIME type of the file." 7075 }, 7076 0x4661: { 7077 name: "FileUsedStartTime", 7078 level: 3, 7079 type: "u", 7080 minver: 0, 7081 maxver: 0, 7082 divx: true, 7083 description: "The timestamp at which this optimized font attachment comes into context, expressed in Segment Ticks which is based on TimestampScale. See [@?DivXWorldFonts]." 7084 }, 7085 0x4662: { 7086 name: "FileUsedEndTime", 7087 level: 3, 7088 type: "u", 7089 minver: 0, 7090 maxver: 0, 7091 divx: true, 7092 description: "The timestamp at which this optimized font attachment goes out of context, expressed in Segment Ticks which is based on TimestampScale. See [@?DivXWorldFonts]." 7093 }, 7094 0x466e: { 7095 name: "FileName", 7096 level: 3, 7097 type: "8", 7098 mandatory: true, 7099 description: "Filename of the attached file." 7100 }, 7101 0x4675: { 7102 name: "FileReferral", 7103 level: 3, 7104 type: "b", 7105 minver: 0, 7106 maxver: 0, 7107 description: "A binary value that a track/codec can refer to when the attachment is needed." 7108 }, 7109 0x467e: { 7110 name: "FileDescription", 7111 level: 3, 7112 type: "8", 7113 description: "A human-friendly name for the attached file." 7114 }, 7115 0x46ae: { 7116 name: "FileUID", 7117 level: 3, 7118 type: "u", 7119 mandatory: true, 7120 range: "not 0", 7121 description: "Unique ID representing the file, as random as possible." 7122 }, 7123 0x47e1: { 7124 name: "ContentEncAlgo", 7125 level: 6, 7126 type: "u", 7127 mandatory: true, 7128 webm: true, 7129 "default": "0", 7130 description: "The encryption algorithm used. The value \"0\" means that the contents have not been encrypted." 7131 }, 7132 0x47e2: { 7133 name: "ContentEncKeyID", 7134 level: 6, 7135 type: "b", 7136 webm: true, 7137 description: "For public key algorithms this is the ID of the public key the the data was encrypted with." 7138 }, 7139 0x47e3: { 7140 name: "ContentSignature", 7141 level: 6, 7142 type: "b", 7143 maxver: 0, 7144 description: "A cryptographic signature of the contents." 7145 }, 7146 0x47e4: { 7147 name: "ContentSigKeyID", 7148 level: 6, 7149 type: "b", 7150 maxver: 0, 7151 description: "This is the ID of the private key the data was signed with." 7152 }, 7153 0x47e5: { 7154 name: "ContentSigAlgo", 7155 level: 6, 7156 type: "u", 7157 maxver: 0, 7158 "default": "0", 7159 description: "The algorithm used for the signature." 7160 }, 7161 0x47e6: { 7162 name: "ContentSigHashAlgo", 7163 level: 6, 7164 type: "u", 7165 maxver: 0, 7166 "default": "0", 7167 description: "The hash algorithm used for the signature." 7168 }, 7169 0x47e7: { 7170 name: "ContentEncAESSettings", 7171 level: 6, 7172 type: "m", 7173 minver: 4, 7174 webm: true, 7175 description: "Settings describing the encryption algorithm used. If `ContentEncAlgo` != 5 this **MUST** be ignored." 7176 }, 7177 0x47e8: { 7178 name: "AESSettingsCipherMode", 7179 level: 7, 7180 type: "u", 7181 mandatory: true, 7182 minver: 4, 7183 webm: true, 7184 description: "The AES cipher mode used in the encryption." 7185 }, 7186 0x4d80: { 7187 name: "MuxingApp", 7188 level: 2, 7189 type: "8", 7190 mandatory: true, 7191 description: "Muxing application or library (example: \"libmatroska-0.4.3\")." 7192 }, 7193 0x4dbb: { 7194 name: "Seek", 7195 level: 2, 7196 type: "m", 7197 mandatory: true, 7198 multiple: true, 7199 description: "Contains a single seek entry to an EBML Element." 7200 }, 7201 0x5031: { 7202 name: "ContentEncodingOrder", 7203 level: 5, 7204 type: "u", 7205 mandatory: true, 7206 webm: true, 7207 "default": "0", 7208 description: "Tells when this modification was used during encoding/muxing starting with 0 and counting upwards. The decoder/demuxer has to start with the highest order number it finds and work its way down. This value has to be unique over all ContentEncodingOrder Elements in the TrackEntry that contains this ContentEncodingOrder element." 7209 }, 7210 0x5032: { 7211 name: "ContentEncodingScope", 7212 level: 5, 7213 type: "u", 7214 mandatory: true, 7215 webm: true, 7216 "default": "1", 7217 description: "A bit field that describes which Elements have been modified in this way. Values (big-endian) can be OR'ed." 7218 }, 7219 0x5033: { 7220 name: "ContentEncodingType", 7221 level: 5, 7222 type: "u", 7223 mandatory: true, 7224 webm: true, 7225 "default": "0", 7226 description: "A value describing what kind of transformation is applied." 7227 }, 7228 0x5034: { 7229 name: "ContentCompression", 7230 level: 5, 7231 type: "m", 7232 description: "Settings describing the compression used. This Element **MUST** be present if the value of ContentEncodingType is 0 and absent otherwise. Each block **MUST** be decompressable even if no previous block is available in order not to prevent seeking." 7233 }, 7234 0x5035: { 7235 name: "ContentEncryption", 7236 level: 5, 7237 type: "m", 7238 webm: true, 7239 description: "Settings describing the encryption used. This Element **MUST** be present if the value of `ContentEncodingType` is 1 (encryption) and **MUST** be ignored otherwise." 7240 }, 7241 0x535f: { 7242 name: "CueRefNumber", 7243 level: 5, 7244 type: "u", 7245 minver: 0, 7246 maxver: 0, 7247 "default": "1", 7248 range: "not 0", 7249 description: "Number of the referenced Block of Track X in the specified Cluster." 7250 }, 7251 0x536e: { 7252 name: "Name", 7253 cppname: "TrackName", 7254 level: 3, 7255 type: "8", 7256 description: "A human-readable track name." 7257 }, 7258 0x5378: { 7259 name: "CueBlockNumber", 7260 level: 4, 7261 type: "u", 7262 range: "not 0", 7263 description: "Number of the Block in the specified Cluster." 7264 }, 7265 0x537f: { 7266 name: "TrackOffset", 7267 level: 3, 7268 type: "i", 7269 minver: 0, 7270 maxver: 0, 7271 "default": "0", 7272 description: "A value to add to the Block's Timestamp, expressed in Matroska Ticks -- ie in nanoseconds; see (#timestamp-ticks). This can be used to adjust the playback offset of a track." 7273 }, 7274 0x53ab: { 7275 name: "SeekID", 7276 level: 3, 7277 type: "b", 7278 mandatory: true, 7279 description: "The binary ID corresponding to the Element name." 7280 }, 7281 0x53ac: { 7282 name: "SeekPosition", 7283 level: 3, 7284 type: "u", 7285 mandatory: true, 7286 description: "The Segment Position of the Element." 7287 }, 7288 0x53b8: { 7289 name: "StereoMode", 7290 cppname: "VideoStereoMode", 7291 level: 4, 7292 type: "u", 7293 mandatory: true, 7294 minver: 3, 7295 webm: true, 7296 "default": "0", 7297 description: "Stereo-3D video mode. There are some more details in (#multi-planar-and-3d-videos)." 7298 }, 7299 0x53b9: { 7300 name: "OldStereoMode", 7301 level: 4, 7302 type: "u", 7303 maxver: 0, 7304 description: "DEPRECATED, DO NOT USE. Bogus StereoMode value used in old versions of libmatroska." 7305 }, 7306 0x53c0: { 7307 name: "AlphaMode", 7308 cppname: "VideoAlphaMode", 7309 level: 4, 7310 type: "u", 7311 mandatory: true, 7312 minver: 3, 7313 webm: true, 7314 "default": "0", 7315 description: "Indicate whether the BlockAdditional Element with BlockAddID of \"1\" contains Alpha data, as defined by to the Codec Mapping for the `CodecID`. Undefined values **SHOULD NOT** be used as the behavior of known implementations is different (considered either as 0 or 1)." 7316 }, 7317 0x54aa: { 7318 name: "PixelCropBottom", 7319 cppname: "VideoPixelCropBottom", 7320 level: 4, 7321 type: "u", 7322 mandatory: true, 7323 "default": "0", 7324 description: "The number of video pixels to remove at the bottom of the image." 7325 }, 7326 0x54b0: { 7327 name: "DisplayWidth", 7328 cppname: "VideoDisplayWidth", 7329 level: 4, 7330 type: "u", 7331 range: "not 0", 7332 description: "Width of the video frames to display. Applies to the video frame after cropping (PixelCrop* Elements)." 7333 }, 7334 0x54b2: { 7335 name: "DisplayUnit", 7336 cppname: "VideoDisplayUnit", 7337 level: 4, 7338 type: "u", 7339 mandatory: true, 7340 "default": "0", 7341 description: "How DisplayWidth & DisplayHeight are interpreted." 7342 }, 7343 0x54b3: { 7344 name: "AspectRatioType", 7345 cppname: "VideoAspectRatio", 7346 level: 4, 7347 type: "u", 7348 minver: 0, 7349 maxver: 0, 7350 "default": "0", 7351 description: "Specify the possible modifications to the aspect ratio." 7352 }, 7353 0x54ba: { 7354 name: "DisplayHeight", 7355 cppname: "VideoDisplayHeight", 7356 level: 4, 7357 type: "u", 7358 range: "not 0", 7359 description: "Height of the video frames to display. Applies to the video frame after cropping (PixelCrop* Elements)." 7360 }, 7361 0x54bb: { 7362 name: "PixelCropTop", 7363 cppname: "VideoPixelCropTop", 7364 level: 4, 7365 type: "u", 7366 mandatory: true, 7367 "default": "0", 7368 description: "The number of video pixels to remove at the top of the image." 7369 }, 7370 0x54cc: { 7371 name: "PixelCropLeft", 7372 cppname: "VideoPixelCropLeft", 7373 level: 4, 7374 type: "u", 7375 mandatory: true, 7376 "default": "0", 7377 description: "The number of video pixels to remove on the left of the image." 7378 }, 7379 0x54dd: { 7380 name: "PixelCropRight", 7381 cppname: "VideoPixelCropRight", 7382 level: 4, 7383 type: "u", 7384 mandatory: true, 7385 "default": "0", 7386 description: "The number of video pixels to remove on the right of the image." 7387 }, 7388 0x55aa: { 7389 name: "FlagForced", 7390 cppname: "TrackFlagForced", 7391 level: 3, 7392 type: "u", 7393 mandatory: true, 7394 "default": "0", 7395 range: "0-1", 7396 description: "Applies only to subtitles. Set if that track **SHOULD** be eligible for automatic selection by the player if it matches the user's language preference, even if the user's preferences would normally not enable subtitles with the selected audio track; this can be used for tracks containing only translations of foreign-language audio or onscreen text. See (#default-track-selection) for more details." 7397 }, 7398 0x55ab: { 7399 name: "FlagHearingImpaired", 7400 level: 3, 7401 type: "u", 7402 minver: 4, 7403 range: "0-1", 7404 description: "Set to 1 if that track is suitable for users with hearing impairments, set to 0 if it is unsuitable for users with hearing impairments." 7405 }, 7406 0x55ac: { 7407 name: "FlagVisualImpaired", 7408 level: 3, 7409 type: "u", 7410 minver: 4, 7411 range: "0-1", 7412 description: "Set to 1 if that track is suitable for users with visual impairments, set to 0 if it is unsuitable for users with visual impairments." 7413 }, 7414 0x55ad: { 7415 name: "FlagTextDescriptions", 7416 level: 3, 7417 type: "u", 7418 minver: 4, 7419 range: "0-1", 7420 description: "Set to 1 if that track contains textual descriptions of video content, set to 0 if that track does not contain textual descriptions of video content." 7421 }, 7422 0x55ae: { 7423 name: "FlagOriginal", 7424 level: 3, 7425 type: "u", 7426 minver: 4, 7427 range: "0-1", 7428 description: "Set to 1 if that track is in the content's original language, set to 0 if it is a translation." 7429 }, 7430 0x55af: { 7431 name: "FlagCommentary", 7432 level: 3, 7433 type: "u", 7434 minver: 4, 7435 range: "0-1", 7436 description: "Set to 1 if that track contains commentary, set to 0 if it does not contain commentary." 7437 }, 7438 0x55b0: { 7439 name: "Colour", 7440 cppname: "VideoColour", 7441 level: 4, 7442 type: "m", 7443 minver: 4, 7444 webm: true, 7445 description: "Settings describing the colour format." 7446 }, 7447 0x55b1: { 7448 name: "MatrixCoefficients", 7449 cppname: "VideoColourMatrix", 7450 level: 5, 7451 type: "u", 7452 mandatory: true, 7453 minver: 4, 7454 webm: true, 7455 "default": "2", 7456 description: "The Matrix Coefficients of the video used to derive luma and chroma values from red, green, and blue color primaries. For clarity, the value and meanings for MatrixCoefficients are adopted from Table 4 of ISO/IEC 23001-8:2016 or ITU-T H.273." 7457 }, 7458 0x55b2: { 7459 name: "BitsPerChannel", 7460 cppname: "VideoBitsPerChannel", 7461 level: 5, 7462 type: "u", 7463 mandatory: true, 7464 minver: 4, 7465 webm: true, 7466 "default": "0", 7467 description: "Number of decoded bits per channel. A value of 0 indicates that the BitsPerChannel is unspecified." 7468 }, 7469 0x55b3: { 7470 name: "ChromaSubsamplingHorz", 7471 cppname: "VideoChromaSubsampHorz", 7472 level: 5, 7473 type: "u", 7474 minver: 4, 7475 webm: true, 7476 description: "The amount of pixels to remove in the Cr and Cb channels for every pixel not removed horizontally. Example: For video with 4:2:0 chroma subsampling, the ChromaSubsamplingHorz **SHOULD** be set to 1." 7477 }, 7478 0x55b4: { 7479 name: "ChromaSubsamplingVert", 7480 cppname: "VideoChromaSubsampVert", 7481 level: 5, 7482 type: "u", 7483 minver: 4, 7484 webm: true, 7485 description: "The amount of pixels to remove in the Cr and Cb channels for every pixel not removed vertically. Example: For video with 4:2:0 chroma subsampling, the ChromaSubsamplingVert **SHOULD** be set to 1." 7486 }, 7487 0x55b5: { 7488 name: "CbSubsamplingHorz", 7489 cppname: "VideoCbSubsampHorz", 7490 level: 5, 7491 type: "u", 7492 minver: 4, 7493 webm: true, 7494 description: "The amount of pixels to remove in the Cb channel for every pixel not removed horizontally. This is additive with ChromaSubsamplingHorz. Example: For video with 4:2:1 chroma subsampling, the ChromaSubsamplingHorz **SHOULD** be set to 1 and CbSubsamplingHorz **SHOULD** be set to 1." 7495 }, 7496 0x55b6: { 7497 name: "CbSubsamplingVert", 7498 cppname: "VideoCbSubsampVert", 7499 level: 5, 7500 type: "u", 7501 minver: 4, 7502 webm: true, 7503 description: "The amount of pixels to remove in the Cb channel for every pixel not removed vertically. This is additive with ChromaSubsamplingVert." 7504 }, 7505 0x55b7: { 7506 name: "ChromaSitingHorz", 7507 cppname: "VideoChromaSitHorz", 7508 level: 5, 7509 type: "u", 7510 mandatory: true, 7511 minver: 4, 7512 webm: true, 7513 "default": "0", 7514 description: "How chroma is subsampled horizontally." 7515 }, 7516 0x55b8: { 7517 name: "ChromaSitingVert", 7518 cppname: "VideoChromaSitVert", 7519 level: 5, 7520 type: "u", 7521 mandatory: true, 7522 minver: 4, 7523 webm: true, 7524 "default": "0", 7525 description: "How chroma is subsampled vertically." 7526 }, 7527 0x55b9: { 7528 name: "Range", 7529 cppname: "VideoColourRange", 7530 level: 5, 7531 type: "u", 7532 mandatory: true, 7533 minver: 4, 7534 webm: true, 7535 "default": "0", 7536 description: "Clipping of the color ranges." 7537 }, 7538 0x55ba: { 7539 name: "TransferCharacteristics", 7540 cppname: "VideoColourTransferCharacter", 7541 level: 5, 7542 type: "u", 7543 mandatory: true, 7544 minver: 4, 7545 webm: true, 7546 "default": "2", 7547 description: "The transfer characteristics of the video. For clarity, the value and meanings for TransferCharacteristics are adopted from Table 3 of ISO/IEC 23091-4 or ITU-T H.273." 7548 }, 7549 0x55bb: { 7550 name: "Primaries", 7551 cppname: "VideoColourPrimaries", 7552 level: 5, 7553 type: "u", 7554 mandatory: true, 7555 minver: 4, 7556 webm: true, 7557 "default": "2", 7558 description: "The colour primaries of the video. For clarity, the value and meanings for Primaries are adopted from Table 2 of ISO/IEC 23091-4 or ITU-T H.273." 7559 }, 7560 0x55bc: { 7561 name: "MaxCLL", 7562 cppname: "VideoColourMaxCLL", 7563 level: 5, 7564 type: "u", 7565 minver: 4, 7566 webm: true, 7567 description: "Maximum brightness of a single pixel (Maximum Content Light Level) in candelas per square meter (cd/m^2^)." 7568 }, 7569 0x55bd: { 7570 name: "MaxFALL", 7571 cppname: "VideoColourMaxFALL", 7572 level: 5, 7573 type: "u", 7574 minver: 4, 7575 webm: true, 7576 description: "Maximum brightness of a single full frame (Maximum Frame-Average Light Level) in candelas per square meter (cd/m^2^)." 7577 }, 7578 0x55d0: { 7579 name: "MasteringMetadata", 7580 cppname: "VideoColourMasterMeta", 7581 level: 5, 7582 type: "m", 7583 minver: 4, 7584 webm: true, 7585 description: "SMPTE 2086 mastering data." 7586 }, 7587 0x55d1: { 7588 name: "PrimaryRChromaticityX", 7589 cppname: "VideoRChromaX", 7590 level: 6, 7591 type: "f", 7592 minver: 4, 7593 webm: true, 7594 range: "0-1", 7595 description: "Red X chromaticity coordinate, as defined by CIE 1931." 7596 }, 7597 0x55d2: { 7598 name: "PrimaryRChromaticityY", 7599 cppname: "VideoRChromaY", 7600 level: 6, 7601 type: "f", 7602 minver: 4, 7603 webm: true, 7604 range: "0-1", 7605 description: "Red Y chromaticity coordinate, as defined by CIE 1931." 7606 }, 7607 0x55d3: { 7608 name: "PrimaryGChromaticityX", 7609 cppname: "VideoGChromaX", 7610 level: 6, 7611 type: "f", 7612 minver: 4, 7613 webm: true, 7614 range: "0-1", 7615 description: "Green X chromaticity coordinate, as defined by CIE 1931." 7616 }, 7617 0x55d4: { 7618 name: "PrimaryGChromaticityY", 7619 cppname: "VideoGChromaY", 7620 level: 6, 7621 type: "f", 7622 minver: 4, 7623 webm: true, 7624 range: "0-1", 7625 description: "Green Y chromaticity coordinate, as defined by CIE 1931." 7626 }, 7627 0x55d5: { 7628 name: "PrimaryBChromaticityX", 7629 cppname: "VideoBChromaX", 7630 level: 6, 7631 type: "f", 7632 minver: 4, 7633 webm: true, 7634 range: "0-1", 7635 description: "Blue X chromaticity coordinate, as defined by CIE 1931." 7636 }, 7637 0x55d6: { 7638 name: "PrimaryBChromaticityY", 7639 cppname: "VideoBChromaY", 7640 level: 6, 7641 type: "f", 7642 minver: 4, 7643 webm: true, 7644 range: "0-1", 7645 description: "Blue Y chromaticity coordinate, as defined by CIE 1931." 7646 }, 7647 0x55d7: { 7648 name: "WhitePointChromaticityX", 7649 cppname: "VideoWhitePointChromaX", 7650 level: 6, 7651 type: "f", 7652 minver: 4, 7653 webm: true, 7654 range: "0-1", 7655 description: "White X chromaticity coordinate, as defined by CIE 1931." 7656 }, 7657 0x55d8: { 7658 name: "WhitePointChromaticityY", 7659 cppname: "VideoWhitePointChromaY", 7660 level: 6, 7661 type: "f", 7662 minver: 4, 7663 webm: true, 7664 range: "0-1", 7665 description: "White Y chromaticity coordinate, as defined by CIE 1931." 7666 }, 7667 0x55d9: { 7668 name: "LuminanceMax", 7669 cppname: "VideoLuminanceMax", 7670 level: 6, 7671 type: "f", 7672 minver: 4, 7673 webm: true, 7674 range: ">= 0x0p+0", 7675 description: "Maximum luminance. Represented in candelas per square meter (cd/m^2^)." 7676 }, 7677 0x55da: { 7678 name: "LuminanceMin", 7679 cppname: "VideoLuminanceMin", 7680 level: 6, 7681 type: "f", 7682 minver: 4, 7683 webm: true, 7684 range: ">= 0x0p+0", 7685 description: "Minimum luminance. Represented in candelas per square meter (cd/m^2^)." 7686 }, 7687 0x55ee: { 7688 name: "MaxBlockAdditionID", 7689 level: 3, 7690 type: "u", 7691 mandatory: true, 7692 "default": "0", 7693 description: "The maximum value of BlockAddID ((#blockaddid-element)). A value 0 means there is no BlockAdditions ((#blockadditions-element)) for this track." 7694 }, 7695 0x5654: { 7696 name: "ChapterStringUID", 7697 level: 4, 7698 type: "8", 7699 minver: 3, 7700 webm: true, 7701 description: "A unique string ID to identify the Chapter. Use for WebVTT cue identifier storage [@!WebVTT]." 7702 }, 7703 0x56aa: { 7704 name: "CodecDelay", 7705 level: 3, 7706 type: "u", 7707 mandatory: true, 7708 minver: 4, 7709 webm: true, 7710 description: "CodecDelay is The codec-built-in delay, expressed in Matroska Ticks -- ie in nanoseconds; see (#timestamp-ticks). It represents the amount of codec samples that will be discarded by the decoder during playback. This timestamp value **MUST** be subtracted from each frame timestamp in order to get the timestamp that will be actually played. The value **SHOULD** be small so the muxing of tracks with the same actual timestamp are in the same Cluster." 7711 }, 7712 0x56bb: { 7713 name: "SeekPreRoll", 7714 level: 3, 7715 type: "u", 7716 mandatory: true, 7717 minver: 4, 7718 webm: true, 7719 "default": "0", 7720 description: "After a discontinuity, SeekPreRoll is the duration of the data the decoder **MUST** decode before the decoded data is valid, expressed in Matroska Ticks -- ie in nanoseconds; see (#timestamp-ticks)." 7721 }, 7722 0x5741: { 7723 name: "WritingApp", 7724 level: 2, 7725 type: "8", 7726 mandatory: true, 7727 description: "Writing application (example: \"mkvmerge-0.3.3\")." 7728 }, 7729 0x5854: { 7730 name: "SilentTracks", 7731 cppname: "ClusterSilentTracks", 7732 level: 2, 7733 type: "m", 7734 minver: 0, 7735 maxver: 0, 7736 description: "The list of tracks that are not used in that part of the stream. It is useful when using overlay tracks on seeking or to decide what track to use." 7737 }, 7738 0x58d7: { 7739 name: "SilentTrackNumber", 7740 cppname: "ClusterSilentTrackNumber", 7741 level: 3, 7742 type: "u", 7743 multiple: true, 7744 minver: 0, 7745 maxver: 0, 7746 description: "One of the track number that are not used from now on in the stream. It could change later if not specified as silent in a further Cluster." 7747 }, 7748 0x61a7: { 7749 name: "AttachedFile", 7750 cppname: "Attached", 7751 level: 2, 7752 type: "m", 7753 mandatory: true, 7754 multiple: true, 7755 description: "An attached file." 7756 }, 7757 0x6240: { 7758 name: "ContentEncoding", 7759 level: 4, 7760 type: "m", 7761 mandatory: true, 7762 multiple: true, 7763 webm: true, 7764 description: "Settings for one content encoding like compression or encryption." 7765 }, 7766 0x6264: { 7767 name: "BitDepth", 7768 cppname: "AudioBitDepth", 7769 level: 4, 7770 type: "u", 7771 range: "not 0", 7772 description: "Bits per sample, mostly used for PCM." 7773 }, 7774 0x63a2: { 7775 name: "CodecPrivate", 7776 level: 3, 7777 type: "b", 7778 description: "Private data only known to the codec." 7779 }, 7780 0x63c0: { 7781 name: "Targets", 7782 cppname: "TagTargets", 7783 level: 3, 7784 type: "m", 7785 mandatory: true, 7786 webm: true, 7787 description: "Specifies which other elements the metadata represented by the Tag applies to. If empty or not present, then the Tag describes everything in the Segment." 7788 }, 7789 0x63c3: { 7790 name: "ChapterPhysicalEquiv", 7791 level: 4, 7792 type: "u", 7793 description: "Specify the physical equivalent of this ChapterAtom like \"DVD\" (60) or \"SIDE\" (50); see (#physical-types) for a complete list of values." 7794 }, 7795 0x63c4: { 7796 name: "TagChapterUID", 7797 level: 4, 7798 type: "u", 7799 multiple: true, 7800 "default": "0", 7801 description: "A unique ID to identify the Chapter(s) the tags belong to." 7802 }, 7803 0x63c5: { 7804 name: "TagTrackUID", 7805 level: 4, 7806 type: "u", 7807 multiple: true, 7808 webm: true, 7809 "default": "0", 7810 description: "A unique ID to identify the Track(s) the tags belong to." 7811 }, 7812 0x63c6: { 7813 name: "TagAttachmentUID", 7814 level: 4, 7815 type: "u", 7816 multiple: true, 7817 "default": "0", 7818 description: "A unique ID to identify the Attachment(s) the tags belong to." 7819 }, 7820 0x63c9: { 7821 name: "TagEditionUID", 7822 level: 4, 7823 type: "u", 7824 multiple: true, 7825 "default": "0", 7826 description: "A unique ID to identify the EditionEntry(s) the tags belong to." 7827 }, 7828 0x63ca: { 7829 name: "TargetType", 7830 cppname: "TagTargetType", 7831 level: 4, 7832 type: "s", 7833 webm: true, 7834 description: "An informational string that can be used to display the logical level of the target like \"ALBUM\", \"TRACK\", \"MOVIE\", \"CHAPTER\", etc ; see Section 6.4 of [@!MatroskaTags]." 7835 }, 7836 0x6532: { 7837 name: "SignedElement", 7838 level: 3, 7839 type: "b", 7840 multiple: true, 7841 webm: false, 7842 description: "An element ID whose data will be used to compute the signature." 7843 }, 7844 0x6624: { 7845 name: "TrackTranslate", 7846 level: 3, 7847 type: "m", 7848 multiple: true, 7849 description: "The mapping between this `TrackEntry` and a track value in the given Chapter Codec." 7850 }, 7851 0x66a5: { 7852 name: "TrackTranslateTrackID", 7853 level: 4, 7854 type: "b", 7855 mandatory: true, 7856 description: "The binary value used to represent this `TrackEntry` in the chapter codec data. The format depends on the `ChapProcessCodecID` used; see (#chapprocesscodecid-element)." 7857 }, 7858 0x66bf: { 7859 name: "TrackTranslateCodec", 7860 level: 4, 7861 type: "u", 7862 mandatory: true, 7863 description: "This `TrackTranslate` applies to this chapter codec of the given chapter edition(s); see (#chapprocesscodecid-element)." 7864 }, 7865 0x66fc: { 7866 name: "TrackTranslateEditionUID", 7867 level: 4, 7868 type: "u", 7869 multiple: true, 7870 description: "Specify a chapter edition UID on which this `TrackTranslate` applies." 7871 }, 7872 0x67c8: { 7873 name: "SimpleTag", 7874 cppname: "TagSimple", 7875 level: 3, 7876 type: "m", 7877 mandatory: true, 7878 multiple: true, 7879 webm: true, 7880 description: "Contains general information about the target." 7881 }, 7882 0x68ca: { 7883 name: "TargetTypeValue", 7884 cppname: "TagTargetTypeValue", 7885 level: 4, 7886 type: "u", 7887 mandatory: true, 7888 webm: true, 7889 "default": "50", 7890 description: "A number to indicate the logical level of the target." 7891 }, 7892 0x6911: { 7893 name: "ChapProcessCommand", 7894 cppname: "ChapterProcessCommand", 7895 level: 5, 7896 type: "m", 7897 multiple: true, 7898 description: "Contains all the commands associated to the Atom." 7899 }, 7900 0x6922: { 7901 name: "ChapProcessTime", 7902 cppname: "ChapterProcessTime", 7903 level: 6, 7904 type: "u", 7905 mandatory: true, 7906 description: "Defines when the process command **SHOULD** be handled" 7907 }, 7908 0x6924: { 7909 name: "ChapterTranslate", 7910 level: 2, 7911 type: "m", 7912 multiple: true, 7913 description: "The mapping between this `Segment` and a segment value in the given Chapter Codec." 7914 }, 7915 0x6933: { 7916 name: "ChapProcessData", 7917 cppname: "ChapterProcessData", 7918 level: 6, 7919 type: "b", 7920 mandatory: true, 7921 description: "Contains the command information. The data **SHOULD** be interpreted depending on the ChapProcessCodecID value. For ChapProcessCodecID = 1, the data correspond to the binary DVD cell pre/post commands; see (#menu-features) on DVD menus." 7922 }, 7923 0x6944: { 7924 name: "ChapProcess", 7925 cppname: "ChapterProcess", 7926 level: 4, 7927 type: "m", 7928 multiple: true, 7929 description: "Contains all the commands associated to the Atom." 7930 }, 7931 0x6955: { 7932 name: "ChapProcessCodecID", 7933 cppname: "ChapterProcessCodecID", 7934 level: 5, 7935 type: "u", 7936 mandatory: true, 7937 "default": "0", 7938 description: "Contains the type of the codec used for the processing. A value of 0 means native Matroska processing (to be defined), a value of 1 means the DVD command set is used; see (#menu-features) on DVD menus. More codec IDs can be added later." 7939 }, 7940 0x69a5: { 7941 name: "ChapterTranslateID", 7942 level: 3, 7943 type: "b", 7944 mandatory: true, 7945 description: "The binary value used to represent this Segment in the chapter codec data. The format depends on the ChapProcessCodecID used; see (#chapprocesscodecid-element)." 7946 }, 7947 0x69bf: { 7948 name: "ChapterTranslateCodec", 7949 level: 3, 7950 type: "u", 7951 mandatory: true, 7952 description: "This `ChapterTranslate` applies to this chapter codec of the given chapter edition(s); see (#chapprocesscodecid-element)." 7953 }, 7954 0x69fc: { 7955 name: "ChapterTranslateEditionUID", 7956 level: 3, 7957 type: "u", 7958 multiple: true, 7959 description: "Specify a chapter edition UID on which this `ChapterTranslate` applies." 7960 }, 7961 0x6d80: { 7962 name: "ContentEncodings", 7963 level: 3, 7964 type: "m", 7965 webm: true, 7966 description: "Settings for several content encoding mechanisms like compression or encryption." 7967 }, 7968 0x6de7: { 7969 name: "MinCache", 7970 cppname: "TrackMinCache", 7971 level: 3, 7972 type: "u", 7973 mandatory: true, 7974 "default": "0", 7975 description: "The minimum number of frames a player **SHOULD** be able to cache during playback. If set to 0, the reference pseudo-cache system is not used." 7976 }, 7977 0x6df8: { 7978 name: "MaxCache", 7979 cppname: "TrackMaxCache", 7980 level: 3, 7981 type: "u", 7982 description: "The maximum cache size necessary to store referenced frames in and the current frame. 0 means no cache is needed." 7983 }, 7984 0x6e67: { 7985 name: "ChapterSegmentUID", 7986 level: 4, 7987 type: "b", 7988 range: ">0", 7989 description: "The SegmentUID of another Segment to play during this chapter." 7990 }, 7991 0x6ebc: { 7992 name: "ChapterSegmentEditionUID", 7993 level: 4, 7994 type: "u", 7995 range: "not 0", 7996 description: "The EditionUID to play from the Segment linked in ChapterSegmentUID. If ChapterSegmentEditionUID is undeclared, then no Edition of the linked Segment is used; see (#medium-linking) on medium-linking Segments." 7997 }, 7998 0x6fab: { 7999 name: "TrackOverlay", 8000 level: 3, 8001 type: "u", 8002 multiple: true, 8003 description: "Specify that this track is an overlay track for the Track specified (in the u-integer). That means when this track has a gap, see (#silenttracks-element) on SilentTracks, the overlay track **SHOULD** be used instead. The order of multiple TrackOverlay matters, the first one is the one that **SHOULD** be used. If not found it **SHOULD** be the second, etc." 8004 }, 8005 0x7373: { 8006 name: "Tag", 8007 level: 2, 8008 type: "m", 8009 mandatory: true, 8010 multiple: true, 8011 webm: true, 8012 description: "A single metadata descriptor." 8013 }, 8014 0x7384: { 8015 name: "SegmentFilename", 8016 level: 2, 8017 type: "8", 8018 description: "A filename corresponding to this Segment." 8019 }, 8020 0x73a4: { 8021 name: "SegmentUID", 8022 level: 2, 8023 type: "b", 8024 range: "not 0", 8025 description: "A randomly generated unique ID to identify the Segment amongst many others (128 bits)." 8026 }, 8027 0x73c4: { 8028 name: "ChapterUID", 8029 level: 4, 8030 type: "u", 8031 mandatory: true, 8032 webm: true, 8033 range: "not 0", 8034 description: "A unique ID to identify the Chapter." 8035 }, 8036 0x73c5: { 8037 name: "TrackUID", 8038 level: 3, 8039 type: "u", 8040 mandatory: true, 8041 range: "not 0", 8042 description: "A unique ID to identify the Track." 8043 }, 8044 0x7446: { 8045 name: "AttachmentLink", 8046 cppname: "TrackAttachmentLink", 8047 level: 3, 8048 type: "u", 8049 maxver: 3, 8050 range: "not 0", 8051 description: "The UID of an attachment that is used by this codec." 8052 }, 8053 0x75a1: { 8054 name: "BlockAdditions", 8055 level: 3, 8056 type: "m", 8057 webm: true, 8058 description: "Contain additional blocks to complete the main one. An EBML parser that has no knowledge of the Block structure could still see and use/skip these data." 8059 }, 8060 0x75a2: { 8061 name: "DiscardPadding", 8062 level: 3, 8063 type: "i", 8064 minver: 4, 8065 webm: true, 8066 description: "Duration of the silent data added to the Block, expressed in Matroska Ticks -- ie in nanoseconds; see (#timestamp-ticks) (padding at the end of the Block for positive value, at the beginning of the Block for negative value). The duration of DiscardPadding is not calculated in the duration of the TrackEntry and **SHOULD** be discarded during playback." 8067 }, 8068 0x7670: { 8069 name: "Projection", 8070 cppname: "VideoProjection", 8071 level: 4, 8072 type: "m", 8073 minver: 4, 8074 webm: true, 8075 description: "Describes the video projection details. Used to render spherical, VR videos or flipping videos horizontally/vertically." 8076 }, 8077 0x7671: { 8078 name: "ProjectionType", 8079 cppname: "VideoProjectionType", 8080 level: 5, 8081 type: "u", 8082 mandatory: true, 8083 minver: 4, 8084 webm: true, 8085 "default": "0", 8086 description: "Describes the projection used for this video track." 8087 }, 8088 0x7672: { 8089 name: "ProjectionPrivate", 8090 cppname: "VideoProjectionPrivate", 8091 level: 5, 8092 type: "b", 8093 minver: 4, 8094 webm: true, 8095 description: "Private data that only applies to a specific projection. * If `ProjectionType` equals 0 (Rectangular), then this element must not be present. * If `ProjectionType` equals 1 (Equirectangular), then this element must be present and contain the same binary data that would be stored inside an ISOBMFF Equirectangular Projection Box ('equi'). * If `ProjectionType` equals 2 (Cubemap), then this element must be present and contain the same binary data that would be stored inside an ISOBMFF Cubemap Projection Box ('cbmp'). * If `ProjectionType` equals 3 (Mesh), then this element must be present and contain the same binary data that would be stored inside an ISOBMFF Mesh Projection Box ('mshp')." 8096 }, 8097 0x7673: { 8098 name: "ProjectionPoseYaw", 8099 cppname: "VideoProjectionPoseYaw", 8100 level: 5, 8101 type: "f", 8102 mandatory: true, 8103 minver: 4, 8104 webm: true, 8105 "default": "0x0p+0", 8106 range: ">= -0xB4p+0, <= 0xB4p+0", 8107 description: "Specifies a yaw rotation to the projection. Value represents a clockwise rotation, in degrees, around the up vector. This rotation must be applied before any `ProjectionPosePitch` or `ProjectionPoseRoll` rotations. The value of this element **MUST** be in the -180 to 180 degree range, both included. Setting `ProjectionPoseYaw` to 180 or -180 degrees, with the `ProjectionPoseRoll` and `ProjectionPosePitch` set to 0 degrees flips the image horizontally." 8108 }, 8109 0x7674: { 8110 name: "ProjectionPosePitch", 8111 cppname: "VideoProjectionPosePitch", 8112 level: 5, 8113 type: "f", 8114 mandatory: true, 8115 minver: 4, 8116 webm: true, 8117 "default": "0x0p+0", 8118 range: ">= -0x5Ap+0, <= 0x5Ap+0", 8119 description: "Specifies a pitch rotation to the projection. Value represents a counter-clockwise rotation, in degrees, around the right vector. This rotation must be applied after the `ProjectionPoseYaw` rotation and before the `ProjectionPoseRoll` rotation. The value of this element **MUST** be in the -90 to 90 degree range, both included." 8120 }, 8121 0x7675: { 8122 name: "ProjectionPoseRoll", 8123 cppname: "VideoProjectionPoseRoll", 8124 level: 5, 8125 type: "f", 8126 mandatory: true, 8127 minver: 4, 8128 webm: true, 8129 "default": "0x0p+0", 8130 range: ">= -0xB4p+0, <= 0xB4p+0", 8131 description: "Specifies a roll rotation to the projection. Value represents a counter-clockwise rotation, in degrees, around the forward vector. This rotation must be applied after the `ProjectionPoseYaw` and `ProjectionPosePitch` rotations. The value of this element **MUST** be in the -180 to 180 degree range, both included. Setting `ProjectionPoseRoll` to 180 or -180 degrees, the `ProjectionPoseYaw` to 180 or -180 degrees with `ProjectionPosePitch` set to 0 degrees flips the image vertically. Setting `ProjectionPoseRoll` to 180 or -180 degrees, with the `ProjectionPoseYaw` and `ProjectionPosePitch` set to 0 degrees flips the image horizontally and vertically." 8132 }, 8133 0x78b5: { 8134 name: "OutputSamplingFrequency", 8135 cppname: "AudioOutputSamplingFreq", 8136 level: 4, 8137 type: "f", 8138 range: "> 0x0p+0", 8139 description: "Real output sampling frequency in Hz (used for SBR techniques)." 8140 }, 8141 0x7ba9: { 8142 name: "Title", 8143 level: 2, 8144 type: "8", 8145 webm: true, 8146 description: "General name of the Segment." 8147 }, 8148 0x7d7b: { 8149 name: "ChannelPositions", 8150 cppname: "AudioPosition", 8151 level: 4, 8152 type: "b", 8153 minver: 0, 8154 maxver: 0, 8155 description: "Table of horizontal angles for each successive channel." 8156 }, 8157 0x7e5b: { 8158 name: "SignatureElements", 8159 level: 1, 8160 type: "m", 8161 webm: false, 8162 description: "Contains elements that will be used to compute the signature." 8163 }, 8164 0x7e7b: { 8165 name: "SignatureElementList", 8166 level: 2, 8167 type: "m", 8168 multiple: true, 8169 webm: false, 8170 i: "Cluster|Block|BlockAdditional", 8171 description: "A list consists of a number of consecutive elements that represent one case where data is used in signature. Ex: means that the BlockAdditional of all Blocks in all Clusters is used for encryption." 8172 }, 8173 0x7e8a: { 8174 name: "SignatureAlgo", 8175 level: 1, 8176 type: "u", 8177 webm: false, 8178 description: "Signature algorithm used (1=RSA, 2=elliptic)." 8179 }, 8180 0x7e9a: { 8181 name: "SignatureHash", 8182 level: 1, 8183 type: "u", 8184 webm: false, 8185 description: "Hash algorithm used (1=SHA1-160, 2=MD5)." 8186 }, 8187 0x7ea5: { 8188 name: "SignaturePublicKey", 8189 level: 1, 8190 type: "b", 8191 webm: false, 8192 description: "The public key to use with the algorithm (in the case of a PKI-based signature)." 8193 }, 8194 0x7eb5: { 8195 name: "Signature", 8196 level: 1, 8197 type: "b", 8198 webm: false, 8199 description: "The signature of the data (until a new." 8200 }, 8201 0x22b59c: { 8202 name: "Language", 8203 cppname: "TrackLanguage", 8204 level: 3, 8205 type: "s", 8206 mandatory: true, 8207 "default": "eng", 8208 description: "Specifies the language of the track in the Matroska languages form; see (#language-codes) on language codes. This Element **MUST** be ignored if the LanguageIETF Element is used in the same TrackEntry." 8209 }, 8210 0x22b59d: { 8211 name: "LanguageIETF", 8212 level: 3, 8213 type: "s", 8214 minver: 4, 8215 description: "Specifies the language of the track according to [@!BCP47] and using the IANA Language Subtag Registry [@!IANALangRegistry]. If this Element is used, then any Language Elements used in the same TrackEntry **MUST** be ignored." 8216 }, 8217 0x23314f: { 8218 name: "TrackTimestampScale", 8219 cppname: "TrackTimecodeScale", 8220 level: 3, 8221 type: "f", 8222 mandatory: true, 8223 maxver: 3, 8224 "default": "0x1p+0", 8225 range: "> 0x0p+0", 8226 description: "DEPRECATED, DO NOT USE. The scale to apply on this track to work at normal speed in relation with other tracks (mostly used to adjust video speed when the audio length differs)." 8227 }, 8228 0x234e7a: { 8229 name: "DefaultDecodedFieldDuration", 8230 cppname: "TrackDefaultDecodedFieldDuration", 8231 level: 3, 8232 type: "u", 8233 minver: 4, 8234 range: "not 0", 8235 description: "The period between two successive fields at the output of the decoding process, expressed in Matroska Ticks -- ie in nanoseconds; see (#timestamp-ticks). see (#defaultdecodedfieldduration) for more information" 8236 }, 8237 0x2383e3: { 8238 name: "FrameRate", 8239 cppname: "VideoFrameRate", 8240 level: 4, 8241 type: "f", 8242 minver: 0, 8243 maxver: 0, 8244 range: "> 0x0p+0", 8245 description: "Number of frames per second. This value is Informational only. It is intended for constant frame rate streams, and **SHOULD NOT** be used for a variable frame rate TrackEntry." 8246 }, 8247 0x23e383: { 8248 name: "DefaultDuration", 8249 cppname: "TrackDefaultDuration", 8250 level: 3, 8251 type: "u", 8252 range: "not 0", 8253 description: "Number of nanoseconds per frame, expressed in Matroska Ticks -- ie in nanoseconds; see (#timestamp-ticks) (frame in the Matroska sense -- one Element put into a (Simple)Block)." 8254 }, 8255 0x258688: { 8256 name: "CodecName", 8257 level: 3, 8258 type: "8", 8259 description: "A human-readable string specifying the codec." 8260 }, 8261 0x26b240: { 8262 name: "CodecDownloadURL", 8263 level: 3, 8264 type: "s", 8265 multiple: true, 8266 minver: 0, 8267 maxver: 0, 8268 description: "A URL to download about the codec used." 8269 }, 8270 0x2ad7b1: { 8271 name: "TimestampScale", 8272 cppname: "TimecodeScale", 8273 level: 2, 8274 type: "u", 8275 mandatory: true, 8276 "default": "1000000", 8277 range: "not 0", 8278 description: "Base unit for Segment Ticks and Track Ticks, in nanoseconds. A TimestampScale value of 1.000.000 means scaled timestamps in the Segment are expressed in milliseconds; see (#timestamps) on how to interpret timestamps." 8279 }, 8280 0x2ad7b2: { 8281 name: "TimecodeScaleDenominator", 8282 level: 2, 8283 type: "u", 8284 mandatory: true, 8285 minver: 4, 8286 "default": "1000000000", 8287 description: "Timestamp scale numerator, see TimecodeScale." 8288 }, 8289 0x2eb524: { 8290 name: "UncompressedFourCC", 8291 cppname: "VideoColourSpace", 8292 level: 4, 8293 type: "b", 8294 description: "Specify the uncompressed pixel format used for the Track's data as a FourCC. This value is similar in scope to the biCompression value of AVI's `BITMAPINFO` [@?AVIFormat]. See the YUV video formats [@?FourCC-YUV] and RGB video formats [@?FourCC-RGB] for common values." 8295 }, 8296 0x2fb523: { 8297 name: "GammaValue", 8298 cppname: "VideoGamma", 8299 level: 4, 8300 type: "f", 8301 minver: 0, 8302 maxver: 0, 8303 range: "> 0x0p+0", 8304 description: "Gamma Value." 8305 }, 8306 0x3a9697: { 8307 name: "CodecSettings", 8308 level: 3, 8309 type: "8", 8310 minver: 0, 8311 maxver: 0, 8312 description: "A string describing the encoding setting used." 8313 }, 8314 0x3b4040: { 8315 name: "CodecInfoURL", 8316 level: 3, 8317 type: "s", 8318 multiple: true, 8319 minver: 0, 8320 maxver: 0, 8321 description: "A URL to find information about the codec used." 8322 }, 8323 0x3c83ab: { 8324 name: "PrevFilename", 8325 level: 2, 8326 type: "8", 8327 description: "A filename corresponding to the file of the previous Linked Segment." 8328 }, 8329 0x3cb923: { 8330 name: "PrevUID", 8331 level: 2, 8332 type: "b", 8333 description: "A unique ID to identify the previous Segment of a Linked Segment (128 bits)." 8334 }, 8335 0x3e83bb: { 8336 name: "NextFilename", 8337 level: 2, 8338 type: "8", 8339 description: "A filename corresponding to the file of the next Linked Segment." 8340 }, 8341 0x3eb923: { 8342 name: "NextUID", 8343 level: 2, 8344 type: "b", 8345 description: "A unique ID to identify the next Segment of a Linked Segment (128 bits)." 8346 }, 8347 0x1043a770: { 8348 name: "Chapters", 8349 level: 1, 8350 type: "m", 8351 webm: true, 8352 description: "A system to define basic menus and partition data. For more detailed information, look at the Chapters explanation in (#chapters)." 8353 }, 8354 0x114d9b74: { 8355 name: "SeekHead", 8356 level: 1, 8357 type: "m", 8358 multiple: true, 8359 description: "Contains the Segment Position of other Top-Level Elements." 8360 }, 8361 0x1254c367: { 8362 name: "Tags", 8363 level: 1, 8364 type: "m", 8365 multiple: true, 8366 webm: true, 8367 description: "Element containing metadata describing Tracks, Editions, Chapters, Attachments, or the Segment as a whole. A list of valid tags can be found in [@!MatroskaTags]." 8368 }, 8369 0x1549a966: { 8370 name: "Info", 8371 level: 1, 8372 type: "m", 8373 mandatory: true, 8374 description: "Contains general information about the Segment." 8375 }, 8376 0x1654ae6b: { 8377 name: "Tracks", 8378 level: 1, 8379 type: "m", 8380 description: "A Top-Level Element of information with many tracks described." 8381 }, 8382 0x18538067: { 8383 name: "Segment", 8384 level: 0, 8385 type: "m", 8386 mandatory: true, 8387 description: "The Root Element that contains all other Top-Level Elements (Elements defined only at Level 1). A Matroska file is composed of 1 Segment." 8388 }, 8389 0x1941a469: { 8390 name: "Attachments", 8391 level: 1, 8392 type: "m", 8393 description: "Contain attached files." 8394 }, 8395 0x1a45dfa3: { 8396 name: "EBML", 8397 level: "0", 8398 type: "m", 8399 mandatory: true, 8400 multiple: true, 8401 minver: 1, 8402 description: "Set the EBML characteristics of the data to follow. Each EBML document has to start with this." 8403 }, 8404 0x1b538667: { 8405 name: "SignatureSlot", 8406 level: -1, 8407 type: "m", 8408 multiple: true, 8409 webm: false, 8410 description: "Contain signature of some (coming) elements in the stream." 8411 }, 8412 0x1c53bb6b: { 8413 name: "Cues", 8414 level: 1, 8415 type: "m", 8416 description: "A Top-Level Element to speed seeking access. All entries are local to the Segment." 8417 }, 8418 0x1f43b675: { 8419 name: "Cluster", 8420 level: 1, 8421 type: "m", 8422 multiple: true, 8423 description: "The Top-Level Element containing the (monolithic) Block structure." 8424 } 8425 }; 8426 8427 var byName = {}; 8428 8429 var schema = { 8430 byEbmlID: byEbmlID, 8431 byName: byName 8432 } 8433 8434 for ( var ebmlID in byEbmlID) { 8435 var desc = byEbmlID[ebmlID]; 8436 byName[desc.name.replace('-', '_')] = parseInt(ebmlID, 10); 8437 } 8438 8439 module.exports = schema; 8440 8441 },{}],18:[function(require,module,exports){ 8442 module.exports={ 8443 "name": "ts-ebml", 8444 "version": "2.0.2", 8445 "description": "ebml decoder and encoder", 8446 "scripts": { 8447 "setup": "npm install -g http-server;", 8448 "init": "npm run update; npm run mkdir; npm run build", 8449 "update": "npm run reset; npm update", 8450 "reset": "rm -rf node_modules", 8451 "mkdir": "mkdir lib dist 2>/dev/null", 8452 "clean": "rm -rf lib/* dist/* test/*.js; mkdir -p dist", 8453 "build": "npm run clean && tsc -p .; npm run browserify", 8454 "start": "http-server . -s & tsc -w -p .& watchify lib/example_seekable.js -o test/example_seekable.js", 8455 "stop": "killall -- node */tsc -w -p", 8456 "browserify": "browserify lib/index.js --standalone EBML -o dist/EBML.js", 8457 "watchify": "watchify lib/index.js --standalone EBML -o dist/EBMl.js -v", 8458 "test": "tsc; espower lib/test.js > lib/test.tmp; mv -f lib/test.tmp lib/test.js; browserify lib/test.js -o test/test.js", 8459 "example": "tsc; browserify lib/example_seekable.js -o test/example_seekable.js", 8460 "examples": "tsc; for file in `find lib -name 'example_*.js' -type f -printf '%f\\n'`; do browserify lib/$file -o test/$file; done", 8461 "examples_bsd": "tsc; for file in `find lib -name 'example_*.js' -type f -print`; do browserify lib/$(basename $file) -o test/$(basename $file); done", 8462 "check": "tsc -w --noEmit -p ./", 8463 "lint": "tslint -c ./tslint.json --project ./tsconfig.json --type-check", 8464 "doc": "typedoc --mode modules --out doc --disableOutputCheck" 8465 }, 8466 "repository": { 8467 "type": "git", 8468 "url": "git+https://github.com/legokichi/ts-ebml.git" 8469 }, 8470 "keywords": [ 8471 "ebml", 8472 "webm", 8473 "mkv", 8474 "matrosika", 8475 "webp" 8476 ], 8477 "author": "legokichi duckscallion", 8478 "license": "MIT", 8479 "bugs": { 8480 "url": "https://github.com/legokichi/ts-ebml/issues" 8481 }, 8482 "homepage": "https://github.com/legokichi/ts-ebml#readme", 8483 "dependencies": { 8484 "buffer": "^5.0.7", 8485 "commander": "^2.11.0", 8486 "ebml": "^2.2.1", 8487 "ebml-block": "^1.1.0", 8488 "events": "^1.1.1", 8489 "int64-buffer": "^0.1.9", 8490 "matroska": "^2.2.3" 8491 }, 8492 "devDependencies": { 8493 "@types/commander": "^2.9.1", 8494 "@types/qunit": "^2.0.31", 8495 "browserify": "^13.1.0", 8496 "empower": "^1.2.3", 8497 "espower-cli": "^1.1.0", 8498 "power-assert": "^1.4.4", 8499 "power-assert-formatter": "^1.4.1", 8500 "qunit-tap": "^1.5.1", 8501 "qunitjs": "^2.4.0", 8502 "tslint": "^5.13.1", 8503 "typedoc": "^0.14.2", 8504 "typescript": "^3.3.3333", 8505 "watchify": "^3.7.0" 8506 }, 8507 "bin": "./lib/cli.js", 8508 "main": "./lib/index.js", 8509 "typings": "./lib/index.d.ts" 8510 } 8511 8512 },{}]},{},[4])(4) 8513 });