From 7d18659634e3c44db3692f03a4e84a37e3bcc426 Mon Sep 17 00:00:00 2001 From: Volker Mische Date: Sun, 21 Jan 2018 01:34:50 +0100 Subject: [PATCH] Add .offset property --- index.js | 10 ++++++++++ test/node/test-buffer-alloc.js | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) 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 -- 2.34.1