]> zoso.dev Git - buffer.git/commit
Undo `instanceof Buffer` changes
authorFeross Aboukhadijeh <feross@feross.org>
Thu, 9 Feb 2017 22:01:59 +0000 (14:01 -0800)
committerFeross Aboukhadijeh <feross@feross.org>
Thu, 9 Feb 2017 22:01:59 +0000 (14:01 -0800)
commit6bd60293cdc41a27d098877bd68301ff67642b4f
tree114767c0ae01a0592a38d2ae83adf4eaef988368
parent051039c1e0d08476bab10f6b5d62adec229f6971
Undo `instanceof Buffer` changes

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.
index.js