INNER CODE UNIT · TypeScript
byteLength
mongodb/js-bson · src/binary.ts:489
const byteLength = (bits.length + 7) >>> 3; // ceil(bits.length / 8)
const bytes = new Uint8Array(byteLength + 2);
bytes[0] = Binary.VECTOR_TYPE.PackedBit;
const remainder = bits.length % 8;
bytes[1] = remainder === 0 ? 0 : 8 - remainder;
for (let bitOffset = 0; bitOffset < bits.length; bitOffset++) {
const byteOffset = bitOffset >>> 3; // floor(bitOffset / 8)
const bit = bits[bitOffset];
if (bit !== 0 && bit !== 1) {
throw new BSONError(
`Invalid bit value at ${bitOffset}: must be 0 or 1, found ${bits[bitOffset]}`
);
}
if (bit === 0) continue;