Guest User

Untitled

a guest
Jun 22nd, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. const _fromCharCode = String.fromCharCode
  2. export function pack_base64(arr) {
  3. let res=''
  4. const u8 = new Uint8Array(arr.buffer || arr)
  5. const len = u8.byteLength
  6. for (let i=0; i<len; i++)
  7. res += _fromCharCode(u8[i])
  8. return window.btoa(res)
  9. }
  10.  
  11. const _charCodeAt = ''.charCodeAt
  12. export function unpack_base64(str_b64) {
  13. const sz = window.atob(str_b64)
  14. const len = sz.length
  15. const res = new Uint8Array(len)
  16. for (let i=0; i<len; i++)
  17. res[i] = _charCodeAt.call(sz, i)
  18. return res
  19. }
Add Comment
Please, Sign In to add comment