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.

to-buffer.js 414B

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