function count1Bits(bitstream, lengthBits) {
  let count = 0;
  for (let i = 0; i < lengthBits; i++) {
    const byteIndex = i >> 3;
    const bitIndex = i % 8;
    count += (bitstream[byteIndex] >> bitIndex) & 1;
  }
  return count;
}
Count the number of bits with value 1 in the bitstream. This is used for
computing availableCount if not precomputed

@param {Uint8Array} bitstream The bitstream typed array
@param {number} lengthBits How many bits are in the bitstream
@private