finish method

Bytes finish()

Writes the header and optional checksum, returning the finished block.

The returned view shares the writer's buffer; reset allocates a new one.

Implementation

Bytes finish() {
  if (_finished) throw StateError('finish() has already been called');
  _finished = true;
  _buffer[0] = blockMagic;
  _buffer[1] = blockVersion;
  _buffer[2] = checksum ? blockFlagCrc32c : 0;
  _buffer[3] = 0;
  if (checksum) {
    _ensure(_pos + 4);
    final crc = VxsCrc32c.compute(_buffer, blockHeaderSize, _pos);
    VxsLe.w32(_buffer, _pos, crc);
    _pos += 4;
  }
  return Bytes.view(_buffer, 0, _pos);
}