From 043dfc8cb8187352c8e07c7e9b791ceb5f051d67 Mon Sep 17 00:00:00 2001 From: Rafael Korbas Date: Wed, 28 Apr 2021 13:17:41 +0200 Subject: [PATCH] Replace instanceof with Buffer.isBuffer reason: https://github.com/feross/buffer/issues/154 --- lib/Layout.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/Layout.js b/lib/Layout.js index b6cf096..3ed160c 100644 --- a/lib/Layout.js +++ b/lib/Layout.js @@ -1765,7 +1765,7 @@ class Union extends Layout { */ getVariant(vb, offset) { let variant = vb; - if (vb instanceof Buffer) { + if (Buffer.isBuffer(vb)) { if (undefined === offset) { offset = 0; } @@ -2325,7 +2325,7 @@ class Blob extends Layout { if (this.length instanceof ExternalLayout) { span = src.length; } - if (!((src instanceof Buffer) + if (!(Buffer.isBuffer(src) && (span === src.length))) { throw new TypeError(nameWithProperty('Blob.encode', this) + ' requires (length ' + span + ') Buffer as src'); @@ -2361,7 +2361,7 @@ class CString extends Layout { /** @override */ getSpan(b, offset) { - if (!(b instanceof Buffer)) { + if (!Buffer.isBuffer(b)) { throw new TypeError('b must be a Buffer'); } if (undefined === offset) { @@ -2452,7 +2452,7 @@ class UTF8 extends Layout { /** @override */ getSpan(b, offset) { - if (!(b instanceof Buffer)) { + if (!Buffer.isBuffer(b)) { throw new TypeError('b must be a Buffer'); } if (undefined === offset) { diff --git a/package.json b/package.json index 00ba755..0f4e830 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "buffer-layout", - "version": "1.2.0", + "version": "1.2.1", "description": "Translation between JavaScript values and Buffers", "keywords": [ "Buffer",