| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 255f017 commit eacc151
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,21 +36,7 @@ const { | |||
| 36 | 36 | swap64: _swap64, | |
| 37 | 37 | kMaxLength, | |
| 38 | 38 | kStringMaxLength, | |
| 39 | - zeroFill: bindingZeroFill, | ||
| 40 | - | ||
| 41 | - // Additional Buffer methods | ||
| 42 | - asciiSlice, | ||
| 43 | - base64Slice, | ||
| 44 | - latin1Slice, | ||
| 45 | - hexSlice, | ||
| 46 | - ucs2Slice, | ||
| 47 | - utf8Slice, | ||
| 48 | - asciiWrite, | ||
| 49 | - base64Write, | ||
| 50 | - latin1Write, | ||
| 51 | - hexWrite, | ||
| 52 | - ucs2Write, | ||
| 53 | - utf8Write | ||
| 39 | + zeroFill: bindingZeroFill | ||
| 54 | 40 | } = internalBinding('buffer'); | |
| 55 | 41 | const { | |
| 56 | 42 | getOwnNonIndexProperties, | |
@@ -88,30 +74,14 @@ const { | |||
| 88 | 74 | } = require('internal/errors').codes; | |
| 89 | 75 | const { validateString } = require('internal/validators'); | |
| 90 | 76 | ||
| 91 | - const internalBuffer = require('internal/buffer'); | ||
| 77 | + const { | ||
| 78 | + FastBuffer, | ||
| 79 | + addBufferPrototypeMethods | ||
| 80 | + } = require('internal/buffer'); | ||
| 92 | 81 | ||
| 93 | - class FastBuffer extends Uint8Array {} | ||
| 94 | 82 | FastBuffer.prototype.constructor = Buffer; | |
| 95 | - internalBuffer.FastBuffer = FastBuffer; | ||
| 96 | - | ||
| 97 | 83 | Buffer.prototype = FastBuffer.prototype; | |
| 98 | - | ||
| 99 | - for (const [name, method] of Object.entries(internalBuffer.readWrites)) { | ||
| 100 | - Buffer.prototype[name] = method; | ||
| 101 | - } | ||
| 102 | - | ||
| 103 | - Buffer.prototype.asciiSlice = asciiSlice; | ||
| 104 | - Buffer.prototype.base64Slice = base64Slice; | ||
| 105 | - Buffer.prototype.latin1Slice = latin1Slice; | ||
| 106 | - Buffer.prototype.hexSlice = hexSlice; | ||
| 107 | - Buffer.prototype.ucs2Slice = ucs2Slice; | ||
| 108 | - Buffer.prototype.utf8Slice = utf8Slice; | ||
| 109 | - Buffer.prototype.asciiWrite = asciiWrite; | ||
| 110 | - Buffer.prototype.base64Write = base64Write; | ||
| 111 | - Buffer.prototype.latin1Write = latin1Write; | ||
| 112 | - Buffer.prototype.hexWrite = hexWrite; | ||
| 113 | - Buffer.prototype.ucs2Write = ucs2Write; | ||
| 114 | - Buffer.prototype.utf8Write = utf8Write; | ||
| 84 | + addBufferPrototypeMethods(Buffer.prototype); | ||
| 115 | 85 | ||
| 116 | 86 | const constants = Object.defineProperties({}, { | |
| 117 | 87 | MAX_LENGTH: { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,6 +6,20 @@ const { | |||
| 6 | 6 | ERR_OUT_OF_RANGE | |
| 7 | 7 | } = require('internal/errors').codes; | |
| 8 | 8 | const { validateNumber } = require('internal/validators'); | |
| 9 | + const { | ||
| 10 | + asciiSlice, | ||
| 11 | + base64Slice, | ||
| 12 | + latin1Slice, | ||
| 13 | + hexSlice, | ||
| 14 | + ucs2Slice, | ||
| 15 | + utf8Slice, | ||
| 16 | + asciiWrite, | ||
| 17 | + base64Write, | ||
| 18 | + latin1Write, | ||
| 19 | + hexWrite, | ||
| 20 | + ucs2Write, | ||
| 21 | + utf8Write | ||
| 22 | + } = internalBinding('buffer'); | ||
| 9 | 23 | ||
| 10 | 24 | // Temporary buffers to convert numbers. | |
| 11 | 25 | const float32Array = new Float32Array(1); | |
@@ -771,45 +785,63 @@ function writeFloatBackwards(val, offset = 0) { | |||
| 771 | 785 | return offset; | |
| 772 | 786 | } | |
| 773 | 787 | ||
| 774 | - // FastBuffer wil be inserted here by lib/buffer.js | ||
| 788 | + class FastBuffer extends Uint8Array {} | ||
| 789 | + | ||
| 790 | + function addBufferPrototypeMethods(proto) { | ||
| 791 | + proto.readUIntLE = readUIntLE; | ||
| 792 | + proto.readUInt32LE = readUInt32LE; | ||
| 793 | + proto.readUInt16LE = readUInt16LE; | ||
| 794 | + proto.readUInt8 = readUInt8; | ||
| 795 | + proto.readUIntBE = readUIntBE; | ||
| 796 | + proto.readUInt32BE = readUInt32BE; | ||
| 797 | + proto.readUInt16BE = readUInt16BE; | ||
| 798 | + proto.readIntLE = readIntLE; | ||
| 799 | + proto.readInt32LE = readInt32LE; | ||
| 800 | + proto.readInt16LE = readInt16LE; | ||
| 801 | + proto.readInt8 = readInt8; | ||
| 802 | + proto.readIntBE = readIntBE; | ||
| 803 | + proto.readInt32BE = readInt32BE; | ||
| 804 | + proto.readInt16BE = readInt16BE; | ||
| 805 | + | ||
| 806 | + proto.writeUIntLE = writeUIntLE; | ||
| 807 | + proto.writeUInt32LE = writeUInt32LE; | ||
| 808 | + proto.writeUInt16LE = writeUInt16LE; | ||
| 809 | + proto.writeUInt8 = writeUInt8; | ||
| 810 | + proto.writeUIntBE = writeUIntBE; | ||
| 811 | + proto.writeUInt32BE = writeUInt32BE; | ||
| 812 | + proto.writeUInt16BE = writeUInt16BE; | ||
| 813 | + proto.writeIntLE = writeIntLE; | ||
| 814 | + proto.writeInt32LE = writeInt32LE; | ||
| 815 | + proto.writeInt16LE = writeInt16LE; | ||
| 816 | + proto.writeInt8 = writeInt8; | ||
| 817 | + proto.writeIntBE = writeIntBE; | ||
| 818 | + proto.writeInt32BE = writeInt32BE; | ||
| 819 | + proto.writeInt16BE = writeInt16BE; | ||
| 820 | + | ||
| 821 | + proto.readFloatLE = bigEndian ? readFloatBackwards : readFloatForwards; | ||
| 822 | + proto.readFloatBE = bigEndian ? readFloatForwards : readFloatBackwards; | ||
| 823 | + proto.readDoubleLE = bigEndian ? readDoubleBackwards : readDoubleForwards; | ||
| 824 | + proto.readDoubleBE = bigEndian ? readDoubleForwards : readDoubleBackwards; | ||
| 825 | + proto.writeFloatLE = bigEndian ? writeFloatBackwards : writeFloatForwards; | ||
| 826 | + proto.writeFloatBE = bigEndian ? writeFloatForwards : writeFloatBackwards; | ||
| 827 | + proto.writeDoubleLE = bigEndian ? writeDoubleBackwards : writeDoubleForwards; | ||
| 828 | + proto.writeDoubleBE = bigEndian ? writeDoubleForwards : writeDoubleBackwards; | ||
| 829 | + | ||
| 830 | + proto.asciiSlice = asciiSlice; | ||
| 831 | + proto.base64Slice = base64Slice; | ||
| 832 | + proto.latin1Slice = latin1Slice; | ||
| 833 | + proto.hexSlice = hexSlice; | ||
| 834 | + proto.ucs2Slice = ucs2Slice; | ||
| 835 | + proto.utf8Slice = utf8Slice; | ||
| 836 | + proto.asciiWrite = asciiWrite; | ||
| 837 | + proto.base64Write = base64Write; | ||
| 838 | + proto.latin1Write = latin1Write; | ||
| 839 | + proto.hexWrite = hexWrite; | ||
| 840 | + proto.ucs2Write = ucs2Write; | ||
| 841 | + proto.utf8Write = utf8Write; | ||
| 842 | + } | ||
| 843 | + | ||
| 775 | 844 | module.exports = { | |
| 776 | - // Container to export all read write functions. | ||
| 777 | - readWrites: { | ||
| 778 | - readUIntLE, | ||
| 779 | - readUInt32LE, | ||
| 780 | - readUInt16LE, | ||
| 781 | - readUInt8, | ||
| 782 | - readUIntBE, | ||
| 783 | - readUInt32BE, | ||
| 784 | - readUInt16BE, | ||
| 785 | - readIntLE, | ||
| 786 | - readInt32LE, | ||
| 787 | - readInt16LE, | ||
| 788 | - readInt8, | ||
| 789 | - readIntBE, | ||
| 790 | - readInt32BE, | ||
| 791 | - readInt16BE, | ||
| 792 | - writeUIntLE, | ||
| 793 | - writeUInt32LE, | ||
| 794 | - writeUInt16LE, | ||
| 795 | - writeUInt8, | ||
| 796 | - writeUIntBE, | ||
| 797 | - writeUInt32BE, | ||
| 798 | - writeUInt16BE, | ||
| 799 | - writeIntLE, | ||
| 800 | - writeInt32LE, | ||
| 801 | - writeInt16LE, | ||
| 802 | - writeInt8, | ||
| 803 | - writeIntBE, | ||
| 804 | - writeInt32BE, | ||
| 805 | - writeInt16BE, | ||
| 806 | - readFloatLE: bigEndian ? readFloatBackwards : readFloatForwards, | ||
| 807 | - readFloatBE: bigEndian ? readFloatForwards : readFloatBackwards, | ||
| 808 | - readDoubleLE: bigEndian ? readDoubleBackwards : readDoubleForwards, | ||
| 809 | - readDoubleBE: bigEndian ? readDoubleForwards : readDoubleBackwards, | ||
| 810 | - writeFloatLE: bigEndian ? writeFloatBackwards : writeFloatForwards, | ||
| 811 | - writeFloatBE: bigEndian ? writeFloatForwards : writeFloatBackwards, | ||
| 812 | - writeDoubleLE: bigEndian ? writeDoubleBackwards : writeDoubleForwards, | ||
| 813 | - writeDoubleBE: bigEndian ? writeDoubleForwards : writeDoubleBackwards | ||
| 814 | - } | ||
| 845 | + FastBuffer, | ||
| 846 | + addBufferPrototypeMethods | ||
| 815 | 847 | }; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments