readAll method

Future<List<WalBinRecord>> readAll({
  1. int afterLsn = 0,
})

Implementation

Future<List<WalBinRecord>> readAll({int afterLsn = 0}) async {
  final bytes = await _vfs.readAll(path);
  if (bytes.isEmpty) return [];

  final headerLen = const Utf8Encoder().convert(_fileVersion).length;
  final result = <WalBinRecord>[];
  int offset = headerLen;

  if (bytes.length <= headerLen) return [];

  final bd = ByteData.sublistView(bytes);
  while (offset < bytes.length) {
    if (offset + 4 > bytes.length) break;
    final recordLen = bd.getUint32(offset, Endian.little);
    offset += 4;

    if (recordLen == 0 || offset + recordLen > bytes.length) break;

    final rec = WalBinRecord.decode(
        Uint8List.fromList(bytes.sublist(offset, offset + recordLen)), 0);
    if (rec == null) break;

    offset += recordLen;
    offset += 4; // trailing length field

    if (rec.lsn > afterLsn) result.add(rec);
  }

  return result;
}