From: Volker Mische Date: Sun, 21 Jan 2018 00:34:50 +0000 (+0100) Subject: Add .offset property X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=7d18659634e3c44db3692f03a4e84a37e3bcc426;p=buffer.git Add .offset property --- diff --git a/index.js b/index.js index f8f5184..c4576d7 100644 --- a/index.js +++ b/index.js @@ -53,6 +53,16 @@ function typedArraySupport () { } } +Object.defineProperty(Buffer.prototype, 'offset', { + enumerable: true, + get () { + if (!(this instanceof Buffer)) { + return undefined + } + return this.byteOffset + } +}) + function createBuffer (length) { if (length > K_MAX_LENGTH) { throw new RangeError('Invalid typed array length') diff --git a/test/node/test-buffer-alloc.js b/test/node/test-buffer-alloc.js index bbba135..9802b52 100644 --- a/test/node/test-buffer-alloc.js +++ b/test/node/test-buffer-alloc.js @@ -32,7 +32,7 @@ assert.strictEqual(0, d.length); var b = Buffer.alloc(128); assert.strictEqual(128, b.length); assert.strictEqual(0, b.byteOffset); - //assert.strictEqual(0, b.offset); + assert.strictEqual(0, b.offset); } // Test creating a Buffer from a Uint32Array