[Pkg-javascript-commits] [node-browserify-zlib] 37/50: fix: use `Buffer.isBuffer` instead of `instanceof`
Bastien Roucariès
rouca at moszumanska.debian.org
Fri Dec 15 13:09:41 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch master
in repository node-browserify-zlib.
commit de4a12ae601284653a5387f6c58eb0af5c081bfb
Author: Haad <haadcode at users.noreply.github.com>
Date: Mon Jan 23 12:32:01 2017 +0200
fix: use `Buffer.isBuffer` instead of `instanceof`
In the browser different versions of the `Buffer` package can be around, making it impossible
to rely on `instanceof` checks.
---
src/index.js | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/index.js b/src/index.js
index f827585..12f1ad0 100644
--- a/src/index.js
+++ b/src/index.js
@@ -231,7 +231,8 @@ function zlibBuffer(engine, buffer, callback) {
function zlibBufferSync(engine, buffer) {
if (typeof buffer === 'string')
buffer = Buffer.from(buffer);
- if (!(buffer instanceof Buffer))
+
+ if (!Buffer.isBuffer(buffer))
throw new TypeError('Not a string or buffer');
var flushFlag = engine._finishFlushFlag;
@@ -352,7 +353,7 @@ function Zlib(opts, mode) {
}
if (opts.dictionary) {
- if (!(opts.dictionary instanceof Buffer)) {
+ if (!Buffer.isBuffer(opts.dictionary)) {
throw new Error('Invalid dictionary: it should be a Buffer instance');
}
}
@@ -492,7 +493,7 @@ Zlib.prototype._transform = function(chunk, encoding, cb) {
var ending = ws.ending || ws.ended;
var last = ending && (!chunk || ws.length === chunk.length);
- if (chunk !== null && !(chunk instanceof Buffer))
+ if (chunk !== null && !Buffer.isBuffer(chunk))
return cb(new Error('invalid input'));
if (!this._handle)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-browserify-zlib.git
More information about the Pkg-javascript-commits
mailing list