|
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 | }; |
0 commit comments