Documentation ¶
Overview ¶
Package dirsnap simplifies reading and writing snapshots of directories and their contents.
Here is an example of how to use this package during testing:
import ( "testing" "github.com/echocrow/fsnap/dirsnap" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) type fsd = dirsnap.Dirs func TestMyFilesPurge(t *testing.T) { dir := t.TempDir() // Source dirs snapshot. require.NoError(t, fsd{ "file": nil, "dir": fsd{ "subfile": nil, "subdir": fsd{}, }, }.Write(dir)) // Expected dirs snapshot. want := fsd{ "dir": fsd{ "subdir": fsd{}, }, } err := MyFilesPurge(dir) assert.NoError(t, err) // Actual dirs snapshot. got, err := dirsnap.Read(dir, -1) require.NoError(t, err) assert.Equal(t, want, got) }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dirs ¶
Dirs represents a nested snapshot of directory contents.
Keys represent the name of a file or folder. Files are represented by a nil value and subfolders by a nested Dirs instance.
func Read ¶
Read scans a directory and returs a Dirs tree of its files and folders.
If n < 0, Read will scan all subdirectories.
If n >= 0, Read will descend at most n directory levels below directory dir.
Click to show internal directories.
Click to hide internal directories.