415gotit
This commit is contained in:
41
node_modules/msgpack-lite/lib/bufferish-array.js
generated
vendored
Normal file
41
node_modules/msgpack-lite/lib/bufferish-array.js
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
// bufferish-array.js
|
||||
|
||||
var Bufferish = require("./bufferish");
|
||||
|
||||
var exports = module.exports = alloc(0);
|
||||
|
||||
exports.alloc = alloc;
|
||||
exports.concat = Bufferish.concat;
|
||||
exports.from = from;
|
||||
|
||||
/**
|
||||
* @param size {Number}
|
||||
* @returns {Buffer|Uint8Array|Array}
|
||||
*/
|
||||
|
||||
function alloc(size) {
|
||||
return new Array(size);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value {Array|ArrayBuffer|Buffer|String}
|
||||
* @returns {Array}
|
||||
*/
|
||||
|
||||
function from(value) {
|
||||
if (!Bufferish.isBuffer(value) && Bufferish.isView(value)) {
|
||||
// TypedArray to Uint8Array
|
||||
value = Bufferish.Uint8Array.from(value);
|
||||
} else if (Bufferish.isArrayBuffer(value)) {
|
||||
// ArrayBuffer to Uint8Array
|
||||
value = new Uint8Array(value);
|
||||
} else if (typeof value === "string") {
|
||||
// String to Array
|
||||
return Bufferish.from.call(exports, value);
|
||||
} else if (typeof value === "number") {
|
||||
throw new TypeError('"value" argument must not be a number');
|
||||
}
|
||||
|
||||
// Array-like to Array
|
||||
return Array.prototype.slice.call(value);
|
||||
}
|
||||
Reference in New Issue
Block a user