(data: ArrayBuffer | $ArrayBufferView)
| 14 | const base64 = require('base64-js'); |
| 15 | |
| 16 | function binaryToBase64(data: ArrayBuffer | $ArrayBufferView) { |
| 17 | if (data instanceof ArrayBuffer) { |
| 18 | data = new Uint8Array(data); |
| 19 | } |
| 20 | if (data instanceof Uint8Array) { |
| 21 | return base64.fromByteArray(data); |
| 22 | } |
| 23 | if (!ArrayBuffer.isView(data)) { |
| 24 | throw new Error('data must be ArrayBuffer or typed array'); |
| 25 | } |
| 26 | const {buffer, byteOffset, byteLength} = data; |
| 27 | return base64.fromByteArray(new Uint8Array(buffer, byteOffset, byteLength)); |
| 28 | } |
| 29 | |
| 30 | module.exports = binaryToBase64; |
no outgoing calls
no test coverage detected
searching dependent graphs…