readPage method
Implementation
Future<String?> readPage(int pageIndex) async {
final String? cached = _cache.get(pageIndex);
if (cached != null) return cached;
final File? file = _file;
if (file == null) return _memory[pageIndex];
final int? offset = _offsets[pageIndex];
final int? length = _lengths[pageIndex];
if (offset == null || length == null) return null;
try {
await _writer?.flush();
final RandomAccessFile handle = await file.open();
await handle.setPosition(offset);
final Uint8List bytes = await handle.read(length);
await handle.close();
final Object? decoded = jsonDecode(utf8.decode(bytes));
if (decoded is! Map<String, Object?>) return null;
final String text = (decoded["t"] as String?) ?? "";
_cache.put(pageIndex, text);
return text;
} on Object {
return null;
}
}