encode = uint8Array => {
  const length = uint8Array.length

  let str = ''
  let z = 0
  let numZBits = 0

  for (let i = 0; i < length; i++) {
    const uint8 = uint8Array[i]

    // Take most significant bit first
    for (let j = BITS_PER_BYTE - 1; j >= 0; j--) {
      const bit = (uint8 >> j) & 1

      z = (z << 1) + bit
      numZBits++

      if (numZBits === BITS_PER_CHAR) {
        str += lookupE[numZBits][z]
        z = 0
        numZBits = 0
      }
    }
  }

  if (numZBits !== 0) {
    // Final bits require special treatment.

    // Some encodings require padding at this point, but not Base65536 because
    // it's a 16-bit encoding for an 8-bit input and 8 divides 16 :D
    /*
      while (!(numZBits in lookupE)) {
        z = (z << 1) + 1
        numZBits++
      }
    */

    str += lookupE[numZBits][z]
  }

  return str
}
Routines for converting binary data into text data which can be sent safely
through 'Unicode-clean' text systems without information being lost. Analogous
to Base64 with a significantly larger character repertoire enabling the
encoding of 2.00 bytes per character (for comparison, Base64 manages 0.75 bytes
per character).