Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

13 lines
414 B

var Buffer = require('safe-buffer').Buffer
module.exports = function (thing, encoding, name) {
if (Buffer.isBuffer(thing)) {
return thing
} else if (typeof thing === 'string') {
return Buffer.from(thing, encoding)
} else if (ArrayBuffer.isView(thing)) {
return Buffer.from(thing.buffer)
} else {
throw new TypeError(name + ' must be a string, a Buffer, a typed array or a DataView')
}
}