buffer: add .read*() and .write*() methods to SlowBuffer prototype
Fixes #2138.
This commit is contained in:
parent
06d71ad457
commit
59a9a9b5b0
@ -1119,3 +1119,32 @@ Buffer.prototype.writeDoubleLE = function(value, offset, noAssert) {
|
||||
Buffer.prototype.writeDoubleBE = function(value, offset, noAssert) {
|
||||
writeDouble(this, value, offset, true, noAssert);
|
||||
};
|
||||
|
||||
SlowBuffer.prototype.readUInt8 = Buffer.prototype.readUInt8;
|
||||
SlowBuffer.prototype.readUInt16LE = Buffer.prototype.readUInt16LE;
|
||||
SlowBuffer.prototype.readUInt16BE = Buffer.prototype.readUInt16BE;
|
||||
SlowBuffer.prototype.readUInt32LE = Buffer.prototype.readUInt32LE;
|
||||
SlowBuffer.prototype.readUInt32BE = Buffer.prototype.readUInt32BE;
|
||||
SlowBuffer.prototype.readInt8 = Buffer.prototype.readInt8;
|
||||
SlowBuffer.prototype.readInt16LE = Buffer.prototype.readInt16LE;
|
||||
SlowBuffer.prototype.readInt16BE = Buffer.prototype.readInt16BE;
|
||||
SlowBuffer.prototype.readInt32LE = Buffer.prototype.readInt32LE;
|
||||
SlowBuffer.prototype.readInt32BE = Buffer.prototype.readInt32BE;
|
||||
SlowBuffer.prototype.readFloatLE = Buffer.prototype.readFloatLE;
|
||||
SlowBuffer.prototype.readFloatBE = Buffer.prototype.readFloatBE;
|
||||
SlowBuffer.prototype.readDoubleLE = Buffer.prototype.readDoubleLE;
|
||||
SlowBuffer.prototype.readDoubleBE = Buffer.prototype.readDoubleBE;
|
||||
SlowBuffer.prototype.writeUInt8 = Buffer.prototype.writeUInt8;
|
||||
SlowBuffer.prototype.writeUInt16LE = Buffer.prototype.writeUInt16LE;
|
||||
SlowBuffer.prototype.writeUInt16BE = Buffer.prototype.writeUInt16BE;
|
||||
SlowBuffer.prototype.writeUInt32LE = Buffer.prototype.writeUInt32LE;
|
||||
SlowBuffer.prototype.writeUInt32BE = Buffer.prototype.writeUInt32BE;
|
||||
SlowBuffer.prototype.writeInt8 = Buffer.prototype.writeInt8;
|
||||
SlowBuffer.prototype.writeInt16LE = Buffer.prototype.writeInt16LE;
|
||||
SlowBuffer.prototype.writeInt16BE = Buffer.prototype.writeInt16BE;
|
||||
SlowBuffer.prototype.writeInt32LE = Buffer.prototype.writeInt32LE;
|
||||
SlowBuffer.prototype.writeInt32BE = Buffer.prototype.writeInt32BE;
|
||||
SlowBuffer.prototype.writeFloatLE = Buffer.prototype.writeFloatLE;
|
||||
SlowBuffer.prototype.writeFloatBE = Buffer.prototype.writeFloatBE;
|
||||
SlowBuffer.prototype.writeDoubleLE = Buffer.prototype.writeDoubleLE;
|
||||
SlowBuffer.prototype.writeDoubleBE = Buffer.prototype.writeDoubleBE;
|
||||
|
@ -1,13 +1,14 @@
|
||||
/*
|
||||
* Tests to verify we're reading in doubles correctly
|
||||
*/
|
||||
var SlowBuffer = process.binding('buffer').SlowBuffer;
|
||||
var ASSERT = require('assert');
|
||||
|
||||
/*
|
||||
* Test (64 bit) double
|
||||
*/
|
||||
function test() {
|
||||
var buffer = new Buffer(8);
|
||||
function test(clazz) {
|
||||
var buffer = new clazz(8);
|
||||
|
||||
buffer[0] = 0x55;
|
||||
buffer[1] = 0x55;
|
||||
@ -104,4 +105,5 @@ function test() {
|
||||
}
|
||||
|
||||
|
||||
test();
|
||||
test(Buffer);
|
||||
test(SlowBuffer);
|
||||
|
@ -1,13 +1,14 @@
|
||||
/*
|
||||
* Tests to verify we're reading in floats correctly
|
||||
*/
|
||||
var SlowBuffer = process.binding('buffer').SlowBuffer;
|
||||
var ASSERT = require('assert');
|
||||
|
||||
/*
|
||||
* Test (32 bit) float
|
||||
*/
|
||||
function test() {
|
||||
var buffer = new Buffer(4);
|
||||
function test(clazz) {
|
||||
var buffer = new clazz(4);
|
||||
|
||||
buffer[0] = 0;
|
||||
buffer[1] = 0;
|
||||
@ -66,4 +67,5 @@ function test() {
|
||||
}
|
||||
|
||||
|
||||
test();
|
||||
test(Buffer);
|
||||
test(SlowBuffer);
|
||||
|
@ -1,13 +1,14 @@
|
||||
/*
|
||||
* Tests to verify we're reading in signed integers correctly
|
||||
*/
|
||||
var SlowBuffer = process.binding('buffer').SlowBuffer;
|
||||
var ASSERT = require('assert');
|
||||
|
||||
/*
|
||||
* Test 8 bit signed integers
|
||||
*/
|
||||
function test8() {
|
||||
var data = new Buffer(4);
|
||||
function test8(clazz) {
|
||||
var data = new clazz(4);
|
||||
|
||||
data[0] = 0x23;
|
||||
ASSERT.equal(0x23, data.readInt8(0));
|
||||
@ -26,8 +27,8 @@ function test8() {
|
||||
}
|
||||
|
||||
|
||||
function test16() {
|
||||
var buffer = new Buffer(6);
|
||||
function test16(clazz) {
|
||||
var buffer = new clazz(6);
|
||||
|
||||
buffer[0] = 0x16;
|
||||
buffer[1] = 0x79;
|
||||
@ -59,8 +60,8 @@ function test16() {
|
||||
}
|
||||
|
||||
|
||||
function test32() {
|
||||
var buffer = new Buffer(6);
|
||||
function test32(clazz) {
|
||||
var buffer = new clazz(6);
|
||||
|
||||
buffer[0] = 0x43;
|
||||
buffer[1] = 0x53;
|
||||
@ -91,6 +92,9 @@ function test32() {
|
||||
}
|
||||
|
||||
|
||||
test8();
|
||||
test16();
|
||||
test32();
|
||||
test8(Buffer);
|
||||
test8(SlowBuffer);
|
||||
test16(Buffer);
|
||||
test16(SlowBuffer);
|
||||
test32(Buffer);
|
||||
test32(SlowBuffer);
|
||||
|
@ -2,6 +2,7 @@
|
||||
* A battery of tests to help us read a series of uints
|
||||
*/
|
||||
|
||||
var SlowBuffer = process.binding('buffer').SlowBuffer;
|
||||
var ASSERT = require('assert');
|
||||
|
||||
/*
|
||||
@ -11,8 +12,8 @@ var ASSERT = require('assert');
|
||||
* - Correctly using the offsets
|
||||
* - Correctly interpreting values that are beyond the signed range as unsigned
|
||||
*/
|
||||
function test8() {
|
||||
var data = new Buffer(4);
|
||||
function test8(clazz) {
|
||||
var data = new clazz(4);
|
||||
|
||||
data[0] = 23;
|
||||
data[1] = 23;
|
||||
@ -36,8 +37,8 @@ function test8() {
|
||||
* - Correctly using the offsets
|
||||
* - Correctly interpreting values that are beyond the signed range as unsigned
|
||||
*/
|
||||
function test16() {
|
||||
var data = new Buffer(4);
|
||||
function test16(clazz) {
|
||||
var data = new clazz(4);
|
||||
|
||||
data[0] = 0;
|
||||
data[1] = 0x23;
|
||||
@ -64,8 +65,8 @@ function test16() {
|
||||
* - Correctly using the offsets
|
||||
* - Correctly interpreting values that are beyond the signed range as unsigned
|
||||
*/
|
||||
function test32() {
|
||||
var data = new Buffer(8);
|
||||
function test32(clazz) {
|
||||
var data = new clazz(8);
|
||||
|
||||
data[0] = 0x32;
|
||||
data[1] = 0x65;
|
||||
@ -82,6 +83,9 @@ function test32() {
|
||||
}
|
||||
|
||||
|
||||
test8();
|
||||
test16();
|
||||
test32();
|
||||
test8(Buffer);
|
||||
test8(SlowBuffer);
|
||||
test16(Buffer);
|
||||
test16(SlowBuffer);
|
||||
test32(Buffer);
|
||||
test32(SlowBuffer);
|
||||
|
@ -1,10 +1,11 @@
|
||||
/*
|
||||
* Tests to verify we're writing doubles correctly
|
||||
*/
|
||||
var SlowBuffer = process.binding('buffer').SlowBuffer;
|
||||
var ASSERT = require('assert');
|
||||
|
||||
function test() {
|
||||
var buffer = new Buffer(16);
|
||||
function test(clazz) {
|
||||
var buffer = new clazz(16);
|
||||
|
||||
buffer.writeDoubleBE(2.225073858507201e-308, 0);
|
||||
buffer.writeDoubleLE(2.225073858507201e-308, 8);
|
||||
@ -103,4 +104,5 @@ function test() {
|
||||
}
|
||||
|
||||
|
||||
test();
|
||||
test(Buffer);
|
||||
test(SlowBuffer);
|
||||
|
@ -1,10 +1,11 @@
|
||||
/*
|
||||
* Tests to verify we're writing floats correctly
|
||||
*/
|
||||
var SlowBuffer = process.binding('buffer').SlowBuffer;
|
||||
var ASSERT = require('assert');
|
||||
|
||||
function test() {
|
||||
var buffer = new Buffer(8);
|
||||
function test(clazz) {
|
||||
var buffer = new clazz(8);
|
||||
|
||||
buffer.writeFloatBE(1, 0);
|
||||
buffer.writeFloatLE(1, 4);
|
||||
@ -63,4 +64,5 @@ function test() {
|
||||
}
|
||||
|
||||
|
||||
test();
|
||||
test(Buffer);
|
||||
test(SlowBuffer);
|
||||
|
@ -1,10 +1,11 @@
|
||||
/*
|
||||
* Tests to verify we're writing signed integers correctly
|
||||
*/
|
||||
var SlowBuffer = process.binding('buffer').SlowBuffer;
|
||||
var ASSERT = require('assert');
|
||||
|
||||
function test8() {
|
||||
var buffer = new Buffer(2);
|
||||
function test8(clazz) {
|
||||
var buffer = new clazz(2);
|
||||
|
||||
buffer.writeInt8(0x23, 0);
|
||||
buffer.writeInt8(-5, 1);
|
||||
@ -35,8 +36,8 @@ function test8() {
|
||||
}
|
||||
|
||||
|
||||
function test16() {
|
||||
var buffer = new Buffer(6);
|
||||
function test16(clazz) {
|
||||
var buffer = new clazz(6);
|
||||
|
||||
buffer.writeInt16BE(0x0023, 0);
|
||||
buffer.writeInt16LE(0x0023, 2);
|
||||
@ -88,8 +89,8 @@ function test16() {
|
||||
}
|
||||
|
||||
|
||||
function test32() {
|
||||
var buffer = new Buffer(8);
|
||||
function test32(clazz) {
|
||||
var buffer = new clazz(8);
|
||||
|
||||
buffer.writeInt32BE(0x23, 0);
|
||||
buffer.writeInt32LE(0x23, 4);
|
||||
@ -161,6 +162,9 @@ function test32() {
|
||||
}
|
||||
|
||||
|
||||
test8();
|
||||
test16();
|
||||
test32();
|
||||
test8(Buffer);
|
||||
test8(SlowBuffer);
|
||||
test16(Buffer);
|
||||
test16(SlowBuffer);
|
||||
test32(Buffer);
|
||||
test32(SlowBuffer);
|
||||
|
@ -1,6 +1,7 @@
|
||||
/*
|
||||
* A battery of tests to help us read a series of uints
|
||||
*/
|
||||
var SlowBuffer = process.binding('buffer').SlowBuffer;
|
||||
var ASSERT = require('assert');
|
||||
|
||||
/*
|
||||
@ -10,8 +11,8 @@ var ASSERT = require('assert');
|
||||
* - Correctly using the offsets
|
||||
* - Correctly interpreting values that are beyond the signed range as unsigned
|
||||
*/
|
||||
function test8() {
|
||||
var data = new Buffer(4);
|
||||
function test8(clazz) {
|
||||
var data = new clazz(4);
|
||||
|
||||
data.writeUInt8(23, 0);
|
||||
data.writeUInt8(23, 1);
|
||||
@ -39,9 +40,9 @@ function test8() {
|
||||
}
|
||||
|
||||
|
||||
function test16() {
|
||||
function test16(clazz) {
|
||||
var value = 0x2343;
|
||||
var data = new Buffer(4);
|
||||
var data = new clazz(4);
|
||||
|
||||
data.writeUInt16BE(value, 0);
|
||||
ASSERT.equal(0x23, data[0]);
|
||||
@ -78,8 +79,8 @@ function test16() {
|
||||
}
|
||||
|
||||
|
||||
function test32() {
|
||||
var data = new Buffer(6);
|
||||
function test32(clazz) {
|
||||
var data = new clazz(6);
|
||||
var value = 0xe7f90a6d;
|
||||
|
||||
data.writeUInt32BE(value, 0);
|
||||
@ -120,6 +121,9 @@ function test32() {
|
||||
}
|
||||
|
||||
|
||||
test8();
|
||||
test16();
|
||||
test32();
|
||||
test8(Buffer);
|
||||
test8(SlowBuffer);
|
||||
test16(Buffer);
|
||||
test16(SlowBuffer);
|
||||
test32(Buffer);
|
||||
test32(SlowBuffer);
|
||||
|
Loading…
x
Reference in New Issue
Block a user