big-data.js 591 B

12345678910111213141516171819202122232425
  1. var test = require('tape')
  2. var b64 = require('../')
  3. test('convert big data to base64', function (t) {
  4. var b64str, arr, i, length
  5. var big = new Uint8Array(64 * 1024 * 1024)
  6. for (i = 0, length = big.length; i < length; ++i) {
  7. big[i] = i % 256
  8. }
  9. b64str = b64.fromByteArray(big)
  10. arr = b64.toByteArray(b64str)
  11. t.ok(equal(arr, big))
  12. t.equal(b64.byteLength(b64str), arr.length)
  13. t.end()
  14. })
  15. function equal (a, b) {
  16. var i
  17. var length = a.length
  18. if (length !== b.length) return false
  19. for (i = 0; i < length; ++i) {
  20. if (a[i] !== b[i]) return false
  21. }
  22. return true
  23. }