if (Buffer.TYPED_ARRAY_SUPPORT) {
// Return an augmented `Uint8Array` instance, for best performance
array.byteLength
- that = Buffer._augment(new Uint8Array(array))
+ that = new Uint8Array(array)
+ that.__proto__ = Buffer.prototype
} else {
// Fallback: Return an object instance of the Buffer class
- that = fromTypedArray(that, new Uint8Array(array))
+ that = fromTypedArray(that, array)
}
return that
}
if (Buffer.TYPED_ARRAY_SUPPORT) {
Buffer.prototype.__proto__ = Uint8Array.prototype
+ Buffer.prototype._set = Uint8Array.prototype.set // For `copy` below.
Buffer.__proto__ = Uint8Array
} else {
// pre-set for values that may exist in the future
function allocate (that, length) {
if (Buffer.TYPED_ARRAY_SUPPORT) {
// Return an augmented `Uint8Array` instance, for best performance
- that = Buffer._augment(new Uint8Array(length))
+ that = new Uint8Array(length)
that.__proto__ = Buffer.prototype
} else {
// Fallback: Return an object instance of the Buffer class
that.length = length
- that._isBuffer = true
}
var fromPool = length !== 0 && length <= Buffer.poolSize >>> 1
}
}
+// Even though this property is private, it shouldn't be removed because it is
+// used by `is-buffer` to detect buffer instances in Safari 5-7.
+Buffer.prototype._isBuffer = true
+
Buffer.prototype.toString = function toString () {
var length = this.length | 0
if (length === 0) return ''
var newBuf
if (Buffer.TYPED_ARRAY_SUPPORT) {
- newBuf = Buffer._augment(this.subarray(start, end))
+ newBuf = this.subarray(start, end)
+ newBuf.__proto__ = Buffer.prototype
} else {
var sliceLen = end - start
newBuf = new Buffer(sliceLen, undefined)
/**
* Augment a Uint8Array *instance* (not the Uint8Array class!) with Buffer methods
+ *
+ * This function is also used externally by `typedarray-to-buffer`.
+ *
*/
Buffer._augment = function _augment (arr) {
arr.constructor = Buffer