UNPKG

bops

Version:
37 lines (27 loc) 569 B
module.exports = to var base64 = require('base64-js') , toutf8 = require('to-utf8') var encoders = { hex: to_hex , utf8: to_utf , base64: to_base64 } function to(buf, encoding) { return encoders[encoding || 'utf8'](buf) } function to_hex(buf) { var str = '' , byt for(var i = 0, len = buf.length; i < len; ++i) { byt = buf[i] str += ((byt & 0xF0) >>> 4).toString(16) str += (byt & 0x0F).toString(16) } return str } function to_utf(buf) { return toutf8(buf) } function to_base64(buf) { return base64.fromByteArray(buf) }