add method

void add(
  1. Uint8List chunk, [
  2. int start = 0,
  3. int? end
])

Updates the hash with chunk[start..end).

Implementation

void add(Uint8List chunk, [int start = 0, int? end]) {
  final stop = RangeError.checkValidRange(start, end, chunk.length);
  if (_finished) {
    throw StateError('add() after finish()');
  }
  var i = start;
  _totalBytes += stop - start;
  if (_bufferLength > 0) {
    final take =
        blockSize - _bufferLength < stop - i
            ? blockSize - _bufferLength
            : stop - i;
    _buffer.setRange(_bufferLength, _bufferLength + take, chunk, i);
    _bufferLength += take;
    i += take;
    if (_bufferLength < blockSize) return;
    compress(_buffer, 0);
    _bufferLength = 0;
  }
  for (; i + blockSize <= stop; i += blockSize) {
    compress(chunk, i);
  }
  if (i < stop) {
    _buffer.setRange(0, stop - i, chunk, i);
    _bufferLength = stop - i;
  }
}