else if (type === 'string')
length = Buffer.byteLength(subject, encoding)
else if (type === 'object')
- length = coerce(subject.length) // Assume object is an array
+ length = coerce(subject.length) // assume that object is array-like
else
throw new Error('First argument needs to be a number, array or string.')
}
var i
- if (Buffer._useTypedArrays && typeof Uint8Array === 'function' &&
- subject instanceof Uint8Array) {
- // Speed optimization -- use set if we're copying from a Uint8Array
+ if (Buffer._useTypedArrays && (subject instanceof Uint8Array
+ || subject instanceof Uint16Array || subject instanceof Int16Array
+ || subject instanceof Uint32Array || subject instanceof Int32Array
+ || subject instanceof Float32Array || subject instanceof Float64Array)) {
+ // Speed optimization -- use set if we're copying from a typed array
buf._set(subject)
} else if (isArrayish(subject)) {
// Treat array-ish objects as a byte array
var BP = Buffer.prototype
/**
- * Augment the Uint8Array *instance* (not the class!) with Buffer methods
+ * Augment a Uint8Array *instance* (not the Uint8Array class!) with Buffer methods
*/
Buffer._augment = function (arr) {
arr._isBuffer = true