1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 | 946 946 946 946 946 946 946 946 1118 1118 1118 946 309710 270233 2 270233 39477 39397 80 946 946 946 946 946 142 142 946 946 946 270312 122 270190 268771 72 268771 268771 268771 1419 946 39397 38406 39397 39397 22 39375 100 39375 39374 39374 39374 946 80 6 6 6 74 68 68 68 614 68 6 4 4 1 3 4 4 12 4 1 1 1 1 4 1 946 66 946 7 2 5 1 4 946 3993 3993 4007 3981 26 12 14 14 946 3222 3222 11 3211 2987 224 7 7 71 217 224 224 224 263465 263465 263465 224 946 76 40 76 18 76 946 46352 4 46352 46352 53 46299 46299 48109 2287 39873 51 2204 76 3618 1808 1810 1810 946 946 5 1 4 946 946 25258 25258 25258 25258 25258 25258 25258 23301 23303 480 13283 6707 60 161 2609 3 1 2 2 946 6 1 5 1 4 946 159 159 159 155 155 29 159 946 6 1 5 1 4 946 56 7 49 5 56 56 22 34 22 12 9 3 946 317 317 317 2 315 9 306 36 270 258 258 257 306 306 946 946 946 946 946 41501 1508 1508 1508 39993 11 11 11 39982 39979 39979 13 13 1 39966 39966 3 1 1 1 1 3 3 3 3 41501 41501 39969 41501 3 41498 77 41498 41498 41500 155 40456 524 232 74 55 4 2 2 2 946 14 946 15925 15925 15925 15925 12 12 2 15913 1 15925 12 12 15913 3 15925 1 15925 946 161 14 946 6 6 6 6 6 6 6 6 17 6 946 6 6 6 6 6 6 6 17 6 946 7 7 7 6 946 6 6 6 5 946 6 6 6 5 946 5 5 5 4 946 5 5 5 4 946 8 8 8 8 8 8 8 8 23 8 8 2 8 946 8 8 8 8 8 8 8 8 23 8 8 2 8 946 8 8 8 7 7 946 9 9 9 8 8 946 9 9 9 8 8 946 7 7 7 6 946 7 7 7 6 946 17 17 17 13 946 11 11 11 11 946 19 19 19 19 946 17 17 17 17 946 76 76 12 64 946 2 2 2 2 2 2 2 2 2 6 2 946 2 2 2 2 2 2 2 2 2 6 2 946 11 11 11 11 11 11 946 5 5 5 5 5 5 5 946 4 4 4 4 4 4 4 946 4 4 4 4 4 4 4 4 4 946 3 3 3 3 3 3 3 3 3 946 4 4 4 4 4 4 4 4 4 12 4 946 4 4 4 4 4 4 4 4 4 12 4 946 9 9 9 9 5 5 946 7 7 7 7 5 5 5 946 7 7 7 7 5 5 5 946 7 7 7 7 5 5 5 5 5 946 7 7 7 7 5 5 5 5 5 946 37 37 4 946 12 12 12 12 8 8 946 8 8 8 8 8 8 946 9 9 9 9 9 9 946 8 8 8 8 8 8 | (function () { 'use strict'; const binding = process.binding('buffer'); const util = require('util'); exports.Buffer = Buffer; exports.SlowBuffer = SlowBuffer; exports.INSPECT_MAX_BYTES = 50; Buffer.poolSize = 8 * 1024; var poolSize, poolOffset, allocPool; function createPool() { poolSize = Buffer.poolSize; allocPool = binding.create(poolSize); poolOffset = 0; } function Buffer(arg) { // Common case. if (typeof arg === 'number') { // If less than zero, or NaN. if (arg < 0 || arg !== arg) arg = 0; return allocate(arg); } // Slightly less common case. if (typeof arg === 'string') { return fromString(arg, arguments[1]); } // Unusual. return fromObject(arg); }; Buffer.prototype.__proto__ = Uint8Array.prototype; Buffer.__proto__ = Uint8Array; binding.setupBufferJS(Buffer.prototype); // Buffer prototype must be past before creating our first pool. createPool(); function SlowBuffer(length) { Iif (length < 0) length = 0; return binding.create(length); }; SlowBuffer.prototype.__proto__ = Buffer.prototype; SlowBuffer.__proto__ = Buffer; function allocate(size) { if (size === 0) return binding.create(0); if (size < (Buffer.poolSize >>> 1)) { if (size > (poolSize - poolOffset)) createPool(); var b = binding.slice(allocPool, poolOffset, poolOffset + size); poolOffset += size; return b; } else { return binding.create(size); } } function fromString(string, encoding) { if (typeof encoding !== 'string' || encoding === '') encoding = 'utf8'; var length = byteLength(string, encoding); if (length >= (Buffer.poolSize >>> 1)) return binding.createFromString(string, encoding); if (length > (poolSize - poolOffset)) createPool(); var actual = allocPool.write(string, poolOffset, encoding); var b = binding.slice(allocPool, poolOffset, poolOffset + actual); poolOffset += actual; return b; } function fromObject(obj) { if (obj instanceof Buffer) { var b = allocate(obj.length); obj.copy(b, 0, 0, obj.length); return b; } if (Array.isArray(obj)) { var length = obj.length; var b = allocate(length); for (var i = 0; i < length; i++) b[i] = obj[i] & 255; return b; } // TODO(trevnorris): This will fail for an actual ArrayBuffer. if (obj.buffer instanceof ArrayBuffer || obj.length) { var length; if (typeof obj.length !== 'number' || obj.length !== obj.length) length = 0; else length = obj.length; var b = allocate(length); for (var i = 0; i < length; i++) { b[i] = obj[i] & 255; } return b; } Eif (obj.type === 'Buffer' && Array.isArray(obj.data)) { var array = obj.data; var b = allocate(array.length); for (var i = 0; i < array.length; i++) b[i] = array[i] & 255; return b; } throw new TypeError('must start with number, buffer, array or string'); } // Static methods Buffer.isBuffer = function isBuffer(b) { return b instanceof Buffer; }; Buffer.compare = function compare(a, b) { if (!(a instanceof Buffer) || !(b instanceof Buffer)) { throw new TypeError('Arguments must be Buffers'); } if (a === b) { return 0; } return binding.compare(a, b); }; Buffer.isEncoding = function(encoding) { var loweredCase = false; for (;;) { switch (encoding) { case 'hex': case 'utf8': case 'utf-8': case 'ascii': case 'binary': case 'base64': case 'ucs2': case 'ucs-2': case 'utf16le': case 'utf-16le': case 'raw': return true; default: if (loweredCase) return false; encoding = ('' + encoding).toLowerCase(); loweredCase = true; } } }; Buffer.concat = function(list, length) { Iif (!Array.isArray(list)) throw new TypeError('list argument must be an Array of Buffers.'); if (list.length === 0) return new Buffer(0); else if (list.length === 1) return list[0]; if (length === undefined) { length = 0; for (var i = 0; i < list.length; i++) length += list[i].length; } else { length = length >>> 0; } var buffer = new Buffer(length); var pos = 0; for (var i = 0; i < list.length; i++) { var buf = list[i]; buf.copy(buffer, pos); pos += buf.length; } return buffer; }; function base64ByteLength(str, bytes) { // Handle padding if (str.charCodeAt(bytes - 1) === 0x3D) bytes--; if (bytes > 1 && str.charCodeAt(bytes - 1) === 0x3D) bytes--; // Base64 ratio: 3/4 return (bytes * 3) >>> 2; } function byteLength(string, encoding) { if (typeof string !== 'string') string = '' + string; var len = string.length; if (len === 0) return 0; // Use a for loop to avoid recursion var loweredCase = false; for (;;) { switch (encoding) { case 'ascii': case 'binary': // Deprecated case 'raw': case 'raws': return len; case 'utf8': case 'utf-8': return binding.byteLengthUtf8(string); case 'ucs2': case 'ucs-2': case 'utf16le': case 'utf-16le': return len * 2; case 'hex': return len >>> 1; case 'base64': return base64ByteLength(string, len); default: // The C++ binding defaulted to UTF8, we should too. if (loweredCase) return binding.byteLengthUtf8(string); encoding = ('' + encoding).toLowerCase(); loweredCase = true; } } } Buffer.byteLength = byteLength; // For backwards compatibility. Object.defineProperty(Buffer.prototype, 'parent', { enumerable: true, get: function() { if (this.byteLength === 0 || this.byteLength === this.buffer.byteLength) { return undefined; } return this.buffer; } }); Object.defineProperty(Buffer.prototype, 'offset', { enumerable: true, get: function() { return this.byteOffset; } }); // toString(encoding, start=0, end=buffer.length) Buffer.prototype.toString = function(encoding, start, end) { var loweredCase = false; start = start >>> 0; end = end === undefined || end === Infinity ? this.length : end >>> 0; if (!encoding) encoding = 'utf8'; Iif (start < 0) start = 0; if (end > this.length) end = this.length; if (end <= start) return ''; while (true) { switch (encoding) { case 'hex': return this.hexSlice(start, end); case 'utf8': case 'utf-8': return this.utf8Slice(start, end); case 'ascii': return this.asciiSlice(start, end); case 'binary': return this.binarySlice(start, end); case 'base64': return this.base64Slice(start, end); case 'ucs2': case 'ucs-2': case 'utf16le': case 'utf-16le': return this.ucs2Slice(start, end); default: if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding); encoding = (encoding + '').toLowerCase(); loweredCase = true; } } }; Buffer.prototype.equals = function equals(b) { if (!(b instanceof Buffer)) throw new TypeError('Argument must be a Buffer'); if (this === b) return true; return binding.compare(this, b) === 0; }; // Inspect Buffer.prototype.inspect = function inspect() { var str = ''; var max = exports.INSPECT_MAX_BYTES; if (this.length > 0) { str = this.toString('hex', 0, max).match(/.{2}/g).join(' '); if (this.length > max) str += ' ... '; } return '<' + this.constructor.name + ' ' + str + '>'; }; Buffer.prototype.compare = function compare(b) { if (!(b instanceof Buffer)) throw new TypeError('Argument must be a Buffer'); if (this === b) return 0; return binding.compare(this, b); }; Buffer.prototype.indexOf = function indexOf(val, byteOffset) { if (byteOffset > 0x7fffffff) byteOffset = 0x7fffffff; else if (byteOffset < -0x80000000) byteOffset = -0x80000000; byteOffset >>= 0; if (typeof val === 'string') return binding.indexOfString(this, val, byteOffset); if (val instanceof Buffer) return binding.indexOfBuffer(this, val, byteOffset); if (typeof val === 'number') return binding.indexOfNumber(this, val, byteOffset); throw new TypeError('val must be string, number or Buffer'); }; Buffer.prototype.fill = function fill(val, start, end) { start = start >> 0; end = (end === undefined) ? this.length : end >> 0; if (start < 0 || end > this.length) throw new RangeError('out of range index'); if (end <= start) return this; if (typeof val !== 'string') { val = val >>> 0; } else if (val.length === 1) { var code = val.charCodeAt(0); if (code < 256) val = code; } binding.fill(this, val, start, end); return this; }; // XXX remove in v0.13 Buffer.prototype.get = util.deprecate(function get(offset) { offset = ~~offset; if (offset < 0 || offset >= this.length) throw new RangeError('index out of range'); return this[offset]; }, '.get() is deprecated. Access using array indexes instead.'); // XXX remove in v0.13 Buffer.prototype.set = util.deprecate(function set(offset, v) { offset = ~~offset; if (offset < 0 || offset >= this.length) throw new RangeError('index out of range'); return this[offset] = v; }, '.set() is deprecated. Set using array indexes instead.'); // TODO(trevnorris): fix these checks to follow new standard // write(string, offset = 0, length = buffer.length, encoding = 'utf8') var writeWarned = false; const writeMsg = '.write(string, encoding, offset, length) is deprecated.' + ' Use write(string[, offset[, length]][, encoding]) instead.'; Buffer.prototype.write = function(string, offset, length, encoding) { // Buffer#write(string); if (offset === undefined) { encoding = 'utf8'; length = this.length; offset = 0; // Buffer#write(string, encoding) } else if (length === undefined && typeof offset === 'string') { encoding = offset; length = this.length; offset = 0; // Buffer#write(string, offset[, length][, encoding]) } else if (isFinite(offset)) { offset = offset >>> 0; if (isFinite(length)) { length = length >>> 0; if (encoding === undefined) encoding = 'utf8'; } else { encoding = length; length = undefined; } // XXX legacy write(string, encoding, offset, length) - remove in v0.13 } else { if (!writeWarned) { Iif (process.throwDeprecation) throw new Error(writeMsg); else Iif (process.traceDeprecation) console.trace(writeMsg); else console.error(writeMsg); writeWarned = true; } var swap = encoding; encoding = offset; offset = length >>> 0; length = swap; } var remaining = this.length - offset; if (length === undefined || length > remaining) length = remaining; if (string.length > 0 && (length < 0 || offset < 0)) throw new RangeError('attempt to write outside buffer bounds'); if (!encoding) encoding = 'utf8'; var loweredCase = false; for (;;) { switch (encoding) { case 'hex': return this.hexWrite(string, offset, length); case 'utf8': case 'utf-8': return this.utf8Write(string, offset, length); case 'ascii': return this.asciiWrite(string, offset, length); case 'binary': return this.binaryWrite(string, offset, length); case 'base64': // Warning: maxLength not taken into account in base64Write return this.base64Write(string, offset, length); case 'ucs2': case 'ucs-2': case 'utf16le': case 'utf-16le': return this.ucs2Write(string, offset, length); default: if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding); encoding = ('' + encoding).toLowerCase(); loweredCase = true; } } }; Buffer.prototype.toJSON = function() { return { type: 'Buffer', data: Array.prototype.slice.call(this, 0) }; }; // TODO(trevnorris): currently works like Array.prototype.slice(), which // doesn't follow the new standard for throwing on out of range indexes. Buffer.prototype.slice = function slice(start, end) { var len = this.length; start = ~~start; end = end === undefined ? len : ~~end; if (start < 0) { start += len; if (start < 0) start = 0; } else if (start > len) { start = len; } if (end < 0) { end += len; Iif (end < 0) end = 0; } else if (end > len) { end = len; } if (end < start) end = start; return binding.slice(this, start, end); }; function checkOffset(offset, ext, length) { if (offset + ext > length) throw new RangeError('index out of range'); } Buffer.prototype.readUIntLE = function(offset, byteLength, noAssert) { offset = offset >>> 0; byteLength = byteLength >>> 0; Eif (!noAssert) checkOffset(offset, byteLength, this.length); var val = this[offset]; var mul = 1; var i = 0; while (++i < byteLength && (mul *= 0x100)) val += this[offset + i] * mul; return val; }; Buffer.prototype.readUIntBE = function(offset, byteLength, noAssert) { offset = offset >>> 0; byteLength = byteLength >>> 0; Eif (!noAssert) checkOffset(offset, byteLength, this.length); var val = this[offset + --byteLength]; var mul = 1; while (byteLength > 0 && (mul *= 0x100)) val += this[offset + --byteLength] * mul; return val; }; Buffer.prototype.readUInt8 = function(offset, noAssert) { offset = offset >>> 0; Eif (!noAssert) checkOffset(offset, 1, this.length); return this[offset]; }; Buffer.prototype.readUInt16LE = function(offset, noAssert) { offset = offset >>> 0; Eif (!noAssert) checkOffset(offset, 2, this.length); return this[offset] | (this[offset + 1] << 8); }; Buffer.prototype.readUInt16BE = function(offset, noAssert) { offset = offset >>> 0; Eif (!noAssert) checkOffset(offset, 2, this.length); return (this[offset] << 8) | this[offset + 1]; }; Buffer.prototype.readUInt32LE = function(offset, noAssert) { offset = offset >>> 0; Eif (!noAssert) checkOffset(offset, 4, this.length); return ((this[offset]) | (this[offset + 1] << 8) | (this[offset + 2] << 16)) + (this[offset + 3] * 0x1000000); }; Buffer.prototype.readUInt32BE = function(offset, noAssert) { offset = offset >>> 0; Eif (!noAssert) checkOffset(offset, 4, this.length); return (this[offset] * 0x1000000) + ((this[offset + 1] << 16) | (this[offset + 2] << 8) | this[offset + 3]); }; Buffer.prototype.readIntLE = function(offset, byteLength, noAssert) { offset = offset >>> 0; byteLength = byteLength >>> 0; Eif (!noAssert) checkOffset(offset, byteLength, this.length); var val = this[offset]; var mul = 1; var i = 0; while (++i < byteLength && (mul *= 0x100)) val += this[offset + i] * mul; mul *= 0x80; if (val >= mul) val -= Math.pow(2, 8 * byteLength); return val; }; Buffer.prototype.readIntBE = function(offset, byteLength, noAssert) { offset = offset >>> 0; byteLength = byteLength >>> 0; Eif (!noAssert) checkOffset(offset, byteLength, this.length); var i = byteLength; var mul = 1; var val = this[offset + --i]; while (i > 0 && (mul *= 0x100)) val += this[offset + --i] * mul; mul *= 0x80; if (val >= mul) val -= Math.pow(2, 8 * byteLength); return val; }; Buffer.prototype.readInt8 = function(offset, noAssert) { offset = offset >>> 0; Eif (!noAssert) checkOffset(offset, 1, this.length); var val = this[offset]; return !(val & 0x80) ? val : (0xff - val + 1) * -1; }; Buffer.prototype.readInt16LE = function(offset, noAssert) { offset = offset >>> 0; Eif (!noAssert) checkOffset(offset, 2, this.length); var val = this[offset] | (this[offset + 1] << 8); return (val & 0x8000) ? val | 0xFFFF0000 : val; }; Buffer.prototype.readInt16BE = function(offset, noAssert) { offset = offset >>> 0; Eif (!noAssert) checkOffset(offset, 2, this.length); var val = this[offset + 1] | (this[offset] << 8); return (val & 0x8000) ? val | 0xFFFF0000 : val; }; Buffer.prototype.readInt32LE = function(offset, noAssert) { offset = offset >>> 0; Eif (!noAssert) checkOffset(offset, 4, this.length); return (this[offset]) | (this[offset + 1] << 8) | (this[offset + 2] << 16) | (this[offset + 3] << 24); }; Buffer.prototype.readInt32BE = function(offset, noAssert) { offset = offset >>> 0; Eif (!noAssert) checkOffset(offset, 4, this.length); return (this[offset] << 24) | (this[offset + 1] << 16) | (this[offset + 2] << 8) | (this[offset + 3]); }; Buffer.prototype.readFloatLE = function readFloatLE(offset, noAssert) { offset = offset >>> 0; Eif (!noAssert) checkOffset(offset, 4, this.length); return binding.readFloatLE(this, offset); }; Buffer.prototype.readFloatBE = function readFloatBE(offset, noAssert) { offset = offset >>> 0; Eif (!noAssert) checkOffset(offset, 4, this.length); return binding.readFloatBE(this, offset); }; Buffer.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) { offset = offset >>> 0; Eif (!noAssert) checkOffset(offset, 8, this.length); return binding.readDoubleLE(this, offset); }; Buffer.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) { offset = offset >>> 0; Eif (!noAssert) checkOffset(offset, 8, this.length); return binding.readDoubleBE(this, offset); }; function checkInt(buffer, value, offset, ext, max, min) { Iif (!(buffer instanceof Buffer)) throw new TypeError('buffer must be a Buffer instance'); if (value > max || value < min) throw new TypeError('value is out of bounds'); Iif (offset + ext > buffer.length) throw new RangeError('index out of range'); } Buffer.prototype.writeUIntLE = function(value, offset, byteLength, noAssert) { value = +value; offset = offset >>> 0; byteLength = byteLength >>> 0; Eif (!noAssert) checkInt(this, value, offset, byteLength, Math.pow(2, 8 * byteLength), 0); var mul = 1; var i = 0; this[offset] = value; while (++i < byteLength && (mul *= 0x100)) this[offset + i] = (value / mul) >>> 0; return offset + byteLength; }; Buffer.prototype.writeUIntBE = function(value, offset, byteLength, noAssert) { value = +value; offset = offset >>> 0; byteLength = byteLength >>> 0; Eif (!noAssert) checkInt(this, value, offset, byteLength, Math.pow(2, 8 * byteLength), 0); var i = byteLength - 1; var mul = 1; this[offset + i] = value; while (--i >= 0 && (mul *= 0x100)) this[offset + i] = (value / mul) >>> 0; return offset + byteLength; }; Buffer.prototype.writeUInt8 = function(value, offset, noAssert) { value = +value; offset = offset >>> 0; Eif (!noAssert) checkInt(this, value, offset, 1, 0xff, 0); this[offset] = value; return offset + 1; }; Buffer.prototype.writeUInt16LE = function(value, offset, noAssert) { value = +value; offset = offset >>> 0; Eif (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0); this[offset] = value; this[offset + 1] = (value >>> 8); return offset + 2; }; Buffer.prototype.writeUInt16BE = function(value, offset, noAssert) { value = +value; offset = offset >>> 0; Eif (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0); this[offset] = (value >>> 8); this[offset + 1] = value; return offset + 2; }; Buffer.prototype.writeUInt32LE = function(value, offset, noAssert) { value = +value; offset = offset >>> 0; Eif (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0); this[offset + 3] = (value >>> 24); this[offset + 2] = (value >>> 16); this[offset + 1] = (value >>> 8); this[offset] = value; return offset + 4; }; Buffer.prototype.writeUInt32BE = function(value, offset, noAssert) { value = +value; offset = offset >>> 0; Eif (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0); this[offset] = (value >>> 24); this[offset + 1] = (value >>> 16); this[offset + 2] = (value >>> 8); this[offset + 3] = value; return offset + 4; }; Buffer.prototype.writeIntLE = function(value, offset, byteLength, noAssert) { value = +value; offset = offset >>> 0; Eif (!noAssert) { checkInt(this, value, offset, byteLength, Math.pow(2, 8 * byteLength - 1) - 1, -Math.pow(2, 8 * byteLength - 1)); } var i = 0; var mul = 1; var sub = value < 0 ? 1 : 0; this[offset] = value; while (++i < byteLength && (mul *= 0x100)) this[offset + i] = ((value / mul) >> 0) - sub; return offset + byteLength; }; Buffer.prototype.writeIntBE = function(value, offset, byteLength, noAssert) { value = +value; offset = offset >>> 0; Eif (!noAssert) { checkInt(this, value, offset, byteLength, Math.pow(2, 8 * byteLength - 1) - 1, -Math.pow(2, 8 * byteLength - 1)); } var i = byteLength - 1; var mul = 1; var sub = value < 0 ? 1 : 0; this[offset + i] = value; while (--i >= 0 && (mul *= 0x100)) this[offset + i] = ((value / mul) >> 0) - sub; return offset + byteLength; }; Buffer.prototype.writeInt8 = function(value, offset, noAssert) { value = +value; offset = offset >>> 0; Eif (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80); this[offset] = value; return offset + 1; }; Buffer.prototype.writeInt16LE = function(value, offset, noAssert) { value = +value; offset = offset >>> 0; Eif (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000); this[offset] = value; this[offset + 1] = (value >>> 8); return offset + 2; }; Buffer.prototype.writeInt16BE = function(value, offset, noAssert) { value = +value; offset = offset >>> 0; Eif (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000); this[offset] = (value >>> 8); this[offset + 1] = value; return offset + 2; }; Buffer.prototype.writeInt32LE = function(value, offset, noAssert) { value = +value; offset = offset >>> 0; Eif (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000); this[offset] = value; this[offset + 1] = (value >>> 8); this[offset + 2] = (value >>> 16); this[offset + 3] = (value >>> 24); return offset + 4; }; Buffer.prototype.writeInt32BE = function(value, offset, noAssert) { value = +value; offset = offset >>> 0; Eif (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000); this[offset] = (value >>> 24); this[offset + 1] = (value >>> 16); this[offset + 2] = (value >>> 8); this[offset + 3] = value; return offset + 4; }; function checkFloat(buffer, value, offset, ext) { Iif (!(buffer instanceof Buffer)) throw new TypeError('buffer must be a Buffer instance'); if (offset + ext > buffer.length) throw new RangeError('index out of range'); } Buffer.prototype.writeFloatLE = function writeFloatLE(val, offset, noAssert) { val = +val; offset = offset >>> 0; Eif (!noAssert) checkFloat(this, val, offset, 4); binding.writeFloatLE(this, val, offset); return offset + 4; }; Buffer.prototype.writeFloatBE = function writeFloatBE(val, offset, noAssert) { val = +val; offset = offset >>> 0; Eif (!noAssert) checkFloat(this, val, offset, 4); binding.writeFloatBE(this, val, offset); return offset + 4; }; Buffer.prototype.writeDoubleLE = function writeDoubleLE(val, offset, noAssert) { val = +val; offset = offset >>> 0; Eif (!noAssert) checkFloat(this, val, offset, 8); binding.writeDoubleLE(this, val, offset); return offset + 8; }; Buffer.prototype.writeDoubleBE = function writeDoubleBE(val, offset, noAssert) { val = +val; offset = offset >>> 0; Eif (!noAssert) checkFloat(this, val, offset, 8); binding.writeDoubleBE(this, val, offset); return offset + 8; }; }()); |