throw new TypeError('must start with number, buffer, array or string')
}
- if (typeof ArrayBuffer !== 'undefined' && object.buffer instanceof ArrayBuffer) {
- return fromTypedArray(that, object)
+ if (typeof ArrayBuffer !== 'undefined') {
+ if (object.buffer instanceof ArrayBuffer) {
+ return fromTypedArray(that, object)
+ }
+ if (object instanceof ArrayBuffer) {
+ return fromArrayBuffer(that, object)
+ }
}
if (object.length) return fromArrayLike(that, object)
return that
}
+function fromArrayBuffer (that, array) {
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
+ // Return an augmented `Uint8Array` instance, for best performance
+ array.byteLength
+ that = Buffer._augment(new Uint8Array(array))
+ } else {
+ // Fallback: Return an object instance of the Buffer class
+ that = fromTypedArray(that, new Uint8Array(array))
+ }
+ return that
+}
+
function fromArrayLike (that, array) {
var length = checked(array.length) | 0
that = allocate(that, length)
throw new TypeError('val must be string, number or Buffer')
}
-// `get` will be removed in Node 0.13+
+// `get` is deprecated
Buffer.prototype.get = function get (offset) {
console.log('.get() is deprecated. Access using array indexes instead.')
return this.readUInt8(offset)
}
-// `set` will be removed in Node 0.13+
+// `set` is deprecated
Buffer.prototype.set = function set (v, offset) {
console.log('.set() is deprecated. Access using array indexes instead.')
return this.writeUInt8(v, offset)
// save reference to original Uint8Array set method before overwriting
arr._set = arr.set
- // deprecated, will be removed in node 0.13+
+ // deprecated
arr.get = BP.get
arr.set = BP.set