You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It turns out that it's not possible to use `instanceof Buffer` safely,
like I thought.
It's not possible to use `instanceof Buffer` reliably in a browserify
context because there could be multiple different copies of the
'buffer' package in use.
This previous method (checking `buf._isBuffer`) works even for Buffer
instances that were created from another copy of the `buffer` package.
NOTE: It's possible to have two different "instances" of the 'buffer'
package, even if the 'buffer' package appears only once in the bundled
code. This can happen if you require 'buffer' in different ways, for
example:
`require('buffer')` vs. `require('buffer/')` vs. using the implicit
`Buffer` global.
You can confirm this by browserifying this code:
```js
console.log(require('buffer').Buffer === require('buffer/').Buffer) //
will be false
```
So, for this reason, `instanceof` won't work.
0 commit comments