File system abstraction with access management.
API provides common file operations for some folder on local drive. Any operations outside of the folder will be blocked. Also, it possible to configure a custom policy for read/write operations.
Can be used as backend for Webix File Manager https://webix.com/filemanager
import (
"github.com/xbsoftware/wfs-local"
)
fs, err:=wfs.NewLocalDrive("./sandbox", nil)//get files in a folderfiles, err:=fs.List("/subfolder");
//get files in a folder and subfolders as plain listfiles, err=fs.List("/subfolder", &wfs.ListConfig{ SubFolders: true });
//get files in a folder and subfolders as nested structurefiles, err=fs.List("/subfolder", &wfs.ListConfig{ SubFolders: true, Nested:true });
//get folder onlyfiles, err=fs.List("/subfolder", &wfs.ListConfig{ SkipFiles: true });
//get files that match a maskfiles, err=fs.List("/subfolder", &wfs.ListConfig{
Include: func(filestring) bool { returnstrings.HasSufix(file, ".txt") },
});
//ignore some filesfiles, err=fs.List("/subfolder", &wfs.ListConfig{
Exclude: func(filestring) bool { returnfile==".git" },
});
//get info about a single fileinfo, err=fs.Info("some.txt");
//check if file existscheck:=fs.Exists("some.txt");//make folderfs.Make("/", "sub2", true);
//make filefs.Make("/", "my.txt", false);
//removefs.Remove("some.txt");
//copyfs.Copy("some.txt", "/sub/", "");
//copy asfs.Copy("some.txt", "/sub/", "other.txt");
//movefs.Move("some.txt", "/data/", "");
//renamefs.Move("some.txt", "", "some-data.txt");
//readreader, err:=fs.Read("some.txt");
//writefs.Write("some.txt", writer)// Access policies// ForceRoot policy is added automaticallyfs, err:=wfs.NewLocalDrive("./sandbox", &wfs.DriveConfig{
Policy: &ReadOnlyPolicy{},
})
// Loggingfs, err:=wfs.NewLocalDrive("./sandbox", &wfs.DriveConfig{
Verbose:true
})
// Exec operation with different configpath, err:=fs.WithOperationConfig(&OperationConfig{
PreventNameCollision:true,
}).Make("/", "some", true)MIT