Memory
The memory driver stores files in a map[string][]byte guarded by a
sync.RWMutex. Nothing touches the disk. Ideal for unit tests, fixtures,
caches, and any place you want a real FileSystem without setup.
When to use it
Section titled “When to use it”- Tests that need a real filekit backend without temp dirs.
- Short-lived caches that should disappear with the process.
- Fuzz harnesses and example programs in docs.
Install
Section titled “Install”go get github.com/gobeaver/filekit/driver/memoryConstruct
Section titled “Construct”import ( "context" "strings"
"github.com/gobeaver/filekit/driver/memory")
fs := memory.New()
ctx := context.Background()_, _ = fs.Write(ctx, "test.txt", strings.NewReader("hi"))With a size cap (bytes):
fs := memory.New(memory.Config{ MaxSize: 100 * 1024 * 1024, // 100 MiB ceiling})Config
Section titled “Config”type Config struct { MaxSize int64 // 0 = unlimited}When MaxSize is non-zero and a write would push total stored bytes over the
limit, the write returns an error rather than evicting anything.
Capabilities
Section titled “Capabilities”| Interface | Implemented | Notes |
|---|---|---|
FileSystem | yes | |
CanCopy | yes | byte-slice copy |
CanMove | yes | rename + delete |
CanChecksum | yes | hashes the in-memory bytes |
CanWatch | yes | native — callbacks fire synchronously on every matching write/delete |
CanSignURL | no | |
CanReadRange | no | |
ChunkedUploader | no |
Quirks
Section titled “Quirks”- The watcher uses an internal callback list rather than polling, so
ActiveChangeCallbacks()returns true. Callbacks run inline on the writing goroutine — keep them fast. CreatedAtis tracked internally and is always populated.- Glob patterns for
Watchusegithub.com/gobwas/glob, not stdlibpath/filepath.Match, so**is supported.