A filesystem abstraction for Go with in-memory and layered backends
open sourceApache-2.0free
Afero is a filesystem abstraction library for Go that mirrors the standard os package behind one afero.Fs interface, so code can run against the real disk, a concurrency-safe in-memory filesystem for tests, ZIP and TAR archives, or remote backends without changing. Filesystems compose: a copy-on-write layer for sandboxing, a read cache over a slow backend, a base-path jail, read-only and regex-filtered views, and an adapter for serving any of them over http.FileServer. It's compatible with Go's io/fs interfaces.
Problems it solves
- test Go code that reads and writes files without touching the disk
- swap the local filesystem for an in-memory one in tests
- restrict a Go program's file access to one directory
Features
- an afero.Fs interface that mirrors the os package
- MemMapFs, a concurrency-safe in-memory filesystem for tests
- composable layers: copy-on-write, read cache, base-path jail, read-only and regex filters
- read-only ZIP and TAR archive filesystems
- compatible with Go's io/fs interfaces
Limitations
- Its Google Cloud Storage and SFTP backends are marked experimental; S3 and other cloud backends come from third parties.1
