diff --git a/CHANGELOG.md b/CHANGELOG.md index b469ac5..ce58aac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Change Log +## [1.2.1] - 2021-04-29 + +* Improve [browser compatibility][pr#24] by using `Buffer.isBuffer` instead of + `instanceof` to confirm Buffer types. + ## [1.2.0] - 2018-03-14 * **API** Add [UTF8][doc:UTF8] to encode UTF strings in a possibly @@ -131,6 +136,7 @@ * Initial release. +[1.2.1]: https://github.com/pabigot/buffer-layout/compare/v1.2.0...v1.2.1 [1.2.0]: https://github.com/pabigot/buffer-layout/compare/v1.1.0...v1.2.0 [1.1.0]: https://github.com/pabigot/buffer-layout/compare/v1.0.0...v1.1.0 [1.0.0]: https://github.com/pabigot/buffer-layout/compare/v0.13.0...v1.0.0 @@ -193,6 +199,7 @@ [issue#19]: https://github.com/pabigot/buffer-layout/issues/19 [issue#20]: https://github.com/pabigot/buffer-layout/issues/20 [issue#21]: https://github.com/pabigot/buffer-layout/issues/21 +[pr#24]: https://github.com/pabigot/buffer-layout/pull/24 [ci:travis]: https://travis-ci.org/pabigot/buffer-layout [ci:coveralls]: https://coveralls.io/github/pabigot/buffer-layout [node:issue#3992]: https://github.com/nodejs/node/issues/3992 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",