}
function fromObject (obj) {
- if (Buffer.isBuffer(obj)) {
+ if (obj instanceof Buffer) {
var len = checked(obj.length) | 0
var buf = createBuffer(len)
}
Buffer.isBuffer = function isBuffer (b) {
- return !!(b != null && b._isBuffer)
+ return b instanceof Buffer
}
Buffer.compare = function compare (a, b) {
- if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
+ if (!(a instanceof Buffer) || !(b instanceof Buffer)) {
throw new TypeError('Arguments must be Buffers')
}
var pos = 0
for (i = 0; i < list.length; ++i) {
var buf = list[i]
- if (!Buffer.isBuffer(buf)) {
+ if (!(buf instanceof Buffer)) {
throw new TypeError('"list" argument must be an Array of Buffers')
}
buf.copy(buffer, pos)
}
function byteLength (string, encoding) {
- if (Buffer.isBuffer(string)) {
+ if (string instanceof Buffer) {
return string.length
}
if (ArrayBuffer.isView(string) || string instanceof ArrayBuffer) {
}
}
-// The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect
-// Buffer instances.
+// The property is used by the `is-buffer` npm package to detect Buffer instances
+// in Safari 5-7. Remove this eventually.
Buffer.prototype._isBuffer = true
function swap (b, n, m) {
}
Buffer.prototype.equals = function equals (b) {
- if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
+ if (!(b instanceof Buffer)) throw new TypeError('Argument must be a Buffer')
if (this === b) return true
return Buffer.compare(this, b) === 0
}
}
Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
- if (!Buffer.isBuffer(target)) {
+ if (!(target instanceof Buffer)) {
throw new TypeError('Argument must be a Buffer')
}
}
// Finally, search either indexOf (if dir is true) or lastIndexOf
- if (Buffer.isBuffer(val)) {
+ if (val instanceof Buffer) {
// Special case: looking for empty string/buffer always fails
if (val.length === 0) {
return -1
}
function checkInt (buf, value, offset, ext, max, min) {
- if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
+ if (!(buf instanceof Buffer)) throw new TypeError('"buffer" argument must be a Buffer instance')
if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
if (offset + ext > buf.length) throw new RangeError('Index out of range')
}
this[i] = val
}
} else {
- var bytes = Buffer.isBuffer(val)
+ var bytes = val instanceof Buffer
? val
: new Buffer(val, encoding)
var len = bytes.length