1 | var Buffer = require('safe-buffer').Buffer
|
2 |
|
3 | module.exports = function (thing, encoding, name) {
|
4 | if (Buffer.isBuffer(thing)) {
|
5 | return thing
|
6 | } else if (typeof thing === 'string') {
|
7 | return Buffer.from(thing, encoding)
|
8 | } else if (ArrayBuffer.isView(thing)) {
|
9 | return Buffer.from(thing.buffer)
|
10 | } else {
|
11 | throw new TypeError(name + ' must be a string, a Buffer, a typed array or a DataView')
|
12 | }
|
13 | }
|