Afero is a filesystem abstraction library for Go that provides a drop-in replacement for the standard os package.
Afero solves the problem of tightly coupling application code to specific storage backends. It works by defining a single Fs interface that abstracts filesystem operations, allowing developers to swap between local disk, in-memory storage, cloud services, and archive formats without changing application logic. The library mirrors the standard os package API, minimizing the effort required to adopt it in existing codebases.
Afero suits projects that need flexible storage backends or comprehensive filesystem testing. It is particularly valuable for applications requiring fast, isolated unit tests through its MemMapFs in-memory filesystem, which eliminates disk I/O and cleanup overhead. The tool also enables sophisticated architectural patterns through filesystem composition: CopyOnWriteFs for sandboxing, CacheOnReadFs for layering caches over slow backends, and BasePathFs for restricting access to subdirectories. Teams building systems that must support multiple storage targets—local filesystems, SFTP, GCS, ZIP archives, or TAR files—will find the universal API especially useful. The library maintains full compatibility with both the os package and Go's io/fs interfaces, making it accessible to developers already familiar with standard library patterns.
The project maintains steady activity with regular updates addressing bug fixes and feature enhancements. Pull requests receive timely review and integration, indicating active maintenance. The codebase shows consistent refinement of core functionality and documentation improvements over time.