utils/fs/fs_operations
library
Classes
-
DartFsOperations
-
Concrete filesystem implementation using dart:io.
-
Dirent
-
Directory entry with file type information.
-
FileStat
-
File stat result mirroring Node's fs.Stats.
-
FsOperations
-
Simplified filesystem operations interface based on dart:io.
Provides a subset of commonly used sync operations with type safety.
Allows abstraction for alternative implementations (e.g., mock, virtual).
-
ReadFileInRangeResult
-
Result from readFileInRange.
-
ReadFileRangeResult
-
Result of reading a file range.
-
ReadSyncResult
-
Read result for partial file reads.
-
SafeResolvePathResult
-
Result of safeResolvePath.
Functions
-
filterGeneratedFiles(List<String> files)
→ List<String>
-
Filter a list of files to exclude generated files.
-
getFsImplementation()
→ FsOperations
-
Gets the currently active filesystem implementation.
-
getPathsForPermissionCheck(String inputPath)
→ List<String>
-
Gets all paths that should be checked for permissions.
This includes the original path, all intermediate symlink targets in the chain,
and the final resolved path.
-
isDuplicatePath(FsOperations fs, String filePath, Set<String> loadedPaths)
→ bool
-
Check if a file path is a duplicate and should be skipped.
Resolves symlinks to detect duplicates pointing to the same file.
If not a duplicate, adds the resolved path to loadedPaths.
-
isGeneratedFile(String filePath)
→ bool
-
Check if a file should be excluded from attribution based on Linguist-style rules.
-
readFileInRange(String filePath, {int offset = 0, int? maxLines, int? maxBytes, bool truncateOnByteLimit = false})
→ Future<ReadFileInRangeResult>
-
Public entry point for line-oriented file reading.
-
readFileRange(String path, int offset, int maxBytes)
→ Future<ReadFileRangeResult?>
-
Read up to
maxBytes from a file starting at offset.
Returns a flat string from bytes -- no sliced string references to a
larger parent. Returns null if the file is smaller than the offset.
-
readLinesReverse(String path)
→ Stream<String>
-
Async generator that yields lines from a file in reverse order.
Reads the file backwards in chunks to avoid loading the entire file into memory.
-
resolveDeepestExistingAncestorSync(FsOperations fs, String absolutePath)
→ String?
-
Resolve the deepest existing ancestor of a path via realpathSync, walking
up until it succeeds. Detects dangling symlinks (link entry exists, target
doesn't) via lstat and resolves them via readlink.
-
safeResolvePath(FsOperations fs, String filePath)
→ SafeResolvePathResult
-
Safely resolves a file path, handling symlinks and errors gracefully.
-
setFsImplementation(FsOperations implementation)
→ void
-
Overrides the filesystem implementation.
Note: This function does not automatically update cwd.
-
setOriginalFsImplementation()
→ void
-
Resets the filesystem implementation to the default Dart implementation.
Note: This function does not automatically update cwd.
-
tailFile(String path, int maxBytes)
→ Future<ReadFileRangeResult>
-
Read the last
maxBytes of a file.
Returns the whole file if it's smaller than maxBytes.
Exceptions / Errors
-
FileTooLargeError
-
Error thrown when a file exceeds the maximum allowed size.