write method
Writes an int to the stream of length bytes
and bits
Implementation
void write(int input, {int bytes = 0, int bits = 0}) {
var len = (bytes * 8) + bits;
var all = pow(2, len).toInt() - 1;
input = input & all;
var thisByte = _bitLength ~/ 8;
var thisBit = _bitLength % 8;
while (len > 0) {
var thisLen = min(len, 8 - thisBit);
if (thisByte + 1 > _stream.length) {
_stream.add(0);
}
var shiftAmt = (8 - (thisBit + len));
_stream[thisByte] = _stream[thisByte] |
(shiftAmt > 0 ? (input << shiftAmt) : (input >> (0 - shiftAmt)));
_stream[thisByte] = 255 & _stream[thisByte];
len -= thisLen;
_bitLength += thisLen;
thisBit = 0;
thisByte++;
}
}