read<T> method
Creates a source to read path
, executes block
to read it, and then closes the
source. This is a compact way to read the contents of a file.
Implementation
Future<T> read<T>(
String path, FutureOr<T> Function(BufferedSource source) block,
[int? start, int? end]) {
return source(path, start, end).buffered().then((e) async {
try {
return await block(e);
} finally {
try {
await e.close();
} catch (_) {}
}
});
}