read method

  1. @override
Future<RepoFile> read(
  1. String path, {
  2. LineRange? range,
})
override

Reads path, optionally only the lines in range.

Implementation

@override
Future<RepoFile> read(String path, {LineRange? range}) async {
  final file = File(_resolve(path));
  if (!file.existsSync()) throw RepoException('File not found: $path');
  final len = file.lengthSync();
  if (len > config.maxFileBytes) {
    throw RepoException(
      'File exceeds maxFileBytes ($len > ${config.maxFileBytes}): $path',
    );
  }
  final content = file.readAsStringSync();
  final slice = sliceLines(content, range);
  return RepoFile(
    path: normalizeRepoPath(path),
    content: slice.text,
    totalLines: slice.totalLines,
    startLine: range?.start,
    endLine: range == null ? null : (range.end ?? slice.totalLines),
  );
}