file_providers library

Provides abstractions for file system operations with change tracking and composite file providers.

This library implements file provider abstractions inspired by Microsoft.Extensions.FileProviders, enabling unified access to files from various sources (physical disk, embedded resources, etc.) with change notification support.

Physical File Provider

Access files from the physical file system:

final provider = PhysicalFileProvider('/path/to/files');

final fileInfo = provider.getFileInfo('config.json');
if (fileInfo.exists) {
  final contents = await fileInfo.readAsString();
}

Watch for Changes

React to file system changes:

final changeToken = provider.watch('**/*.json');
changeToken.registerChangeCallback(() {
  print('JSON files changed!');
});

Composite File Provider

Combine multiple file providers:

final composite = CompositeFileProvider([
  PhysicalFileProvider('/app/files'),
  PhysicalFileProvider('/shared/files'),
]);

// Searches all providers for the file
final file = composite.getFileInfo('config.json');

Directory Enumeration

List directory contents:

final contents = provider.getDirectoryContents('/configs');
for (final item in contents) {
  print('${item.name} - ${item.isDirectory}');
}

Classes

CompositeFileProvider
Aggregates multiple file providers into a single provider.
CrossFileTestOverrides
Overrides some functions of CrossFile for testing purposes
Directory
A reference to a directory on the file system.
DirectoryContents
Represents a directory's content in the file provider.
ErrorCodes
Operating system error codes.
File
A reference to a file on the file system.
FileInfo
FileLock
Type of lock when requesting a lock on a file.
FileMode
The modes in which a File can be opened.
FileProvider
A read-only file provider abstraction.
FileStat
The result of calling the POSIX stat() function on a file system object.
FileSystem
A generic representation of a file system.
FileSystemEntity
The common super class for io.File, io.Directory, and io.Link objects.
FileSystemEntityType
The type of an entity on the file system, such as a file, directory, or link.
FileSystemEvent
Base event class emitted by FileSystemEntity.watch.
ForwardingFileSystem
A file system that forwards all methods and properties to a delegate.
ForwardingFileSystemEntity<T extends FileSystemEntity, D extends FileSystemEntity>
A file system entity that forwards all methods and properties to a delegate.
IOSink
A combined byte and text output.
A reference to a symbolic link on the file system.
NotFoundDirectoryContents
Represents a non-existing directory
NotFoundFileInfo
Represents a non-existing file.
NullChangeToken
An empty change token that doesn't raise any change callbacks.
NullFileProvider
An empty file provider with no contents.
PhysicalDirectoryContents
Represents the contents of a physical file directory
PhysicalDirectoryInfo
Represents a directory on a physical filesystem
PhysicalFileInfo
Represents a file on a physical filesystem
PhysicalFileProvider
Looks up files using the on-disk file system.
PhysicalFileProviderOptions
Options for a PhysicalFileProvider.
PhysicalFilesWatcher
A file watcher that watches a physical filesystem for changes.
PollingFileChangeToken
A change token that polls for file changes.
PollingWildcardChangeToken
A change token that polls for file changes matching a wildcard pattern.
RandomAccessFile
Random access to the data in a file.
Test
XFile
A CrossFile is a cross-platform, simplified File abstraction.
XFileInfo
Represents a file using cross_file's XFile for cross-platform support.

Enums

ExclusionFilters
Specifies filtering behavior for files or directories.

Mixins

ForwardingDirectory<T extends Directory>
A directory that forwards all methods and properties to a delegate.
ForwardingFile
A file that forwards all methods and properties to a delegate.
A link that forwards all methods and properties to a delegate.
ForwardingRandomAccessFile
A RandomAccessFile implementation that forwards all methods and properties to a delegate.

Exceptions / Errors

FileNotFoundException
FileSystemException
Exception thrown when a file operation fails.
IOException
Base class for all IO related exceptions.
OSError
An Exception holding information about an error from the operating system.