truncate method

Future<void> truncate()

Implementation

Future<void> truncate() async {
  if (_closed) return;
  await _flush();

  _lsn++;
  final checkpointRecord = WalBinRecord(
    lsn: _lsn, txnId: 0, prevLsn: 0,
    op: WalBinOp.checkpoint, flags: 0, tableId: 0, rowId: 0,
    ddlPayload: {'lsn': _lsn, 'ts': DateTime.now().millisecondsSinceEpoch},
  );
  final encoded = checkpointRecord.encode();
  final lenBuf  = Uint8List(4);
  ByteData.sublistView(lenBuf).setUint32(0, encoded.length, Endian.little);

  final headerBytes = Uint8List.fromList(
      const Utf8Encoder().convert(_fileVersion));
  final content = Uint8List(
      headerBytes.length + 4 + encoded.length + 4);
  int off = 0;
  content.setAll(off, headerBytes); off += headerBytes.length;
  content.setAll(off, lenBuf);      off += 4;
  content.setAll(off, encoded);     off += encoded.length;
  content.setAll(off, lenBuf);

  await _vfs.writeAll(path, content);

  _flushedLsn = _lsn;
  _txnLastLsn.clear();
}