GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||
GeezerVison is showing github.com — Undo `instanceof Buffer` changes by feross · Pull Request #155 · feross/buffer Conversation
Owner
It turns out that it's not possible to use It's not possible to use This previous method (checking 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:
You can confirm this by browserifying this code: console.log(require('buffer').Buffer === require('buffer/').Buffer) // will be false So, for this reason, Fixes: #154
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsIt 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.
Owner
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
dcousens
reviewed
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perfect
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
|
There was an error while loading. Please reload this page.
|
LGTM, nice work @feross. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Live and learn! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.