Skip to content

Commit de4a12a

Browse files
haadcodedignifiedquire
authored andcommitted
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.
1 parent 8344834 commit de4a12a

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ function zlibBuffer(engine, buffer, callback) {
231231
function zlibBufferSync(engine, buffer) {
232232
if (typeof buffer === 'string')
233233
buffer = Buffer.from(buffer);
234-
if (!(buffer instanceof Buffer))
234+
235+
if (!Buffer.isBuffer(buffer))
235236
throw new TypeError('Not a string or buffer');
236237

237238
var flushFlag = engine._finishFlushFlag;
@@ -352,7 +353,7 @@ function Zlib(opts, mode) {
352353
}
353354

354355
if (opts.dictionary) {
355-
if (!(opts.dictionary instanceof Buffer)) {
356+
if (!Buffer.isBuffer(opts.dictionary)) {
356357
throw new Error('Invalid dictionary: it should be a Buffer instance');
357358
}
358359
}
@@ -492,7 +493,7 @@ Zlib.prototype._transform = function(chunk, encoding, cb) {
492493
var ending = ws.ending || ws.ended;
493494
var last = ending && (!chunk || ws.length === chunk.length);
494495

495-
if (chunk !== null && !(chunk instanceof Buffer))
496+
if (chunk !== null && !Buffer.isBuffer(chunk))
496497
return cb(new Error('invalid input'));
497498

498499
if (!this._handle)

0 commit comments

Comments
 (0)