From: Feross Aboukhadijeh Date: Thu, 8 May 2014 00:24:52 +0000 (-0700) Subject: return offset for end of last write (parity with 0.11) X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=398ce7e4d69adc741de6818cdd23c537ed87431b;p=buffer.git return offset for end of last write (parity with 0.11) --- diff --git a/index.js b/index.js index 90e3099..b1375ff 100644 --- a/index.js +++ b/index.js @@ -704,6 +704,7 @@ Buffer.prototype.writeUInt8 = function (value, offset, noAssert) { if (offset >= this.length) return this[offset] = value + return offset + 1 } function writeUInt16 (buf, value, offset, littleEndian, noAssert) { @@ -724,14 +725,15 @@ function writeUInt16 (buf, value, offset, littleEndian, noAssert) { (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>> (littleEndian ? i : 1 - i) * 8 } + return offset + 2 } Buffer.prototype.writeUInt16LE = function (value, offset, noAssert) { - writeUInt16(this, value, offset, true, noAssert) + return writeUInt16(this, value, offset, true, noAssert) } Buffer.prototype.writeUInt16BE = function (value, offset, noAssert) { - writeUInt16(this, value, offset, false, noAssert) + return writeUInt16(this, value, offset, false, noAssert) } function writeUInt32 (buf, value, offset, littleEndian, noAssert) { @@ -751,14 +753,15 @@ function writeUInt32 (buf, value, offset, littleEndian, noAssert) { buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff } + return offset + 4 } Buffer.prototype.writeUInt32LE = function (value, offset, noAssert) { - writeUInt32(this, value, offset, true, noAssert) + return writeUInt32(this, value, offset, true, noAssert) } Buffer.prototype.writeUInt32BE = function (value, offset, noAssert) { - writeUInt32(this, value, offset, false, noAssert) + return writeUInt32(this, value, offset, false, noAssert) } Buffer.prototype.writeInt8 = function (value, offset, noAssert) { @@ -776,6 +779,7 @@ Buffer.prototype.writeInt8 = function (value, offset, noAssert) { this.writeUInt8(value, offset, noAssert) else this.writeUInt8(0xff + value + 1, offset, noAssert) + return offset + 1 } function writeInt16 (buf, value, offset, littleEndian, noAssert) { @@ -795,14 +799,15 @@ function writeInt16 (buf, value, offset, littleEndian, noAssert) { writeUInt16(buf, value, offset, littleEndian, noAssert) else writeUInt16(buf, 0xffff + value + 1, offset, littleEndian, noAssert) + return offset + 2 } Buffer.prototype.writeInt16LE = function (value, offset, noAssert) { - writeInt16(this, value, offset, true, noAssert) + return writeInt16(this, value, offset, true, noAssert) } Buffer.prototype.writeInt16BE = function (value, offset, noAssert) { - writeInt16(this, value, offset, false, noAssert) + return writeInt16(this, value, offset, false, noAssert) } function writeInt32 (buf, value, offset, littleEndian, noAssert) { @@ -822,14 +827,15 @@ function writeInt32 (buf, value, offset, littleEndian, noAssert) { writeUInt32(buf, value, offset, littleEndian, noAssert) else writeUInt32(buf, 0xffffffff + value + 1, offset, littleEndian, noAssert) + return offset + 4 } Buffer.prototype.writeInt32LE = function (value, offset, noAssert) { - writeInt32(this, value, offset, true, noAssert) + return writeInt32(this, value, offset, true, noAssert) } Buffer.prototype.writeInt32BE = function (value, offset, noAssert) { - writeInt32(this, value, offset, false, noAssert) + return writeInt32(this, value, offset, false, noAssert) } function writeFloat (buf, value, offset, littleEndian, noAssert) { @@ -846,14 +852,15 @@ function writeFloat (buf, value, offset, littleEndian, noAssert) { return ieee754.write(buf, value, offset, littleEndian, 23, 4) + return offset + 4 } Buffer.prototype.writeFloatLE = function (value, offset, noAssert) { - writeFloat(this, value, offset, true, noAssert) + return writeFloat(this, value, offset, true, noAssert) } Buffer.prototype.writeFloatBE = function (value, offset, noAssert) { - writeFloat(this, value, offset, false, noAssert) + return writeFloat(this, value, offset, false, noAssert) } function writeDouble (buf, value, offset, littleEndian, noAssert) { @@ -871,14 +878,15 @@ function writeDouble (buf, value, offset, littleEndian, noAssert) { return ieee754.write(buf, value, offset, littleEndian, 52, 8) + return offset + 8 } Buffer.prototype.writeDoubleLE = function (value, offset, noAssert) { - writeDouble(this, value, offset, true, noAssert) + return writeDouble(this, value, offset, true, noAssert) } Buffer.prototype.writeDoubleBE = function (value, offset, noAssert) { - writeDouble(this, value, offset, false, noAssert) + return writeDouble(this, value, offset, false, noAssert) } // fill(value, start=0, end=buffer.length)