RWFS is a Go-based in-memory read-write file system that supports various features like directory support, file permissions, memory caching, compression, security, and more. It is designed to provide a simple and efficient way to simulate file system operations in memory.
- Directory Support: Create, delete, and navigate directories.
- File and Directory Search: Search files and directories by name or patterns.
- Permissions and Access Control: Manage read, write, and execute permissions for files and directories.
- Caching: Memory caching of files for improved read performance.
- Compression: Support for file compression to save space.
- File Metadata: Manage extended metadata for files.
- Concurrency Support: Concurrent access to files and directories with support for read-write locks.
- Error Handling: Custom error handling for file system operations.
- Security Features: Implement security measures like encryption and access control lists.
- Local File System Integration: Integration with the local file system for seamless data storage.
To install RWFS, use the following command:
go get github.com/DanielcoderX/rwfspackage main
import (
"fmt""github.com/DanielcoderX/rwfs"
)
funcmain() {
// Initialize the in-memory file systemfs:=rwfs.NewMemFileSystem()
// Create a new directoryerr:=fs.CreateDir("example_dir")
iferr!=nil {
fmt.Println("Error creating directory:", err)
return
}
// Change to the new directoryerr=fs.ChangeDir("example_dir")
iferr!=nil {
fmt.Println("Error changing directory:", err)
return
}
// Create a new file in the current directory_, err=fs.CreateFile("example_file.txt", "owner1", rwfs.FilePermission{Read: true, Write: true})
iferr!=nil {
fmt.Println("Error creating file:", err)
return
}
// List the contents of the current directorycontents:=fs.CWD.GetDirectoryContents()
fmt.Println("Current directory contents:", contents)
}Creates a new directory in the current working directory.
func (fs*MemFileSystem) CreateDir(namestring) errorRemoves a directory from the current working directory.
func (fs*MemFileSystem) RemoveDir(namestring) errorChanges the current working directory.
func (fs*MemFileSystem) ChangeDir(namestring) errorCreates a new file in the current working directory.
func (fs*MemFileSystem) CreateFile(name, ownerstring, permissionsFilePermission) (File, error)Opens a file in the current working directory.
func (fs*MemFileSystem) OpenFile(namestring) (File, error)Removes a file from the current working directory.
func (fs*MemFileSystem) RemoveFile(namestring) errorLists all files in the current working directory.
func (fs*MemFileSystem) ListFiles() ([]string, error)Lists the contents of the current working directory (both files and directories).
func (fs*MemFileSystem) ListDirContents() ([]DirEntry, error)Returns the contents of a directory in a structured format.
// DirectoryContents represents the contents of a directorytypeDirectoryContentsstruct {
DirectoryNamestringFiles []stringSubdirectories []string
}
// GetDirectoryContents returns the contents of the directory in a structured formatfunc (dir*MemDirectory) GetDirectoryContents() DirectoryContentsHere is an example to demonstrate basic operations like creating directories, changing directories, and listing directory contents:
package main
import (
"fmt""github.com/DanielcoderX/rwfs"
)
funcmain() {
// Define the file system configurationconfig:= rwfs.FileSystemConfig{
Filepath: "data.rwfs",
Compression: true,
CompressLevel: 9,
Encryption: false,
}
// Initialize a new local file systemfs, err:=rwfs.NewLocalFileSystem(config)
iferr!=nil {
fmt.Println("Error initializing file system:", err)
return
}
// Create and navigate directorieserr:=fs.CreateDir("dir1")
iferr!=nil {
fmt.Println("Error creating directory:", err)
return
}
err=fs.ChangeDir("dir1")
iferr!=nil {
fmt.Println("Error changing directory:", err)
return
}
err=fs.CreateDir("subdir1")
iferr!=nil {
fmt.Println("Error creating subdirectory:", err)
return
}
// Create a file_, err=fs.CreateFile("file1.txt", "owner1", rwfs.FilePermission{Read: true, Write: true})
iferr!=nil {
fmt.Println("Error creating file:", err)
return
}
// Get contents of current directorycontents:=fs.CWD.GetDirectoryContents()
fmt.Println("Current directory contents:", contents)
// Remove a directoryerr=fs.ChangeDir("/")
iferr!=nil {
fmt.Println("Error changing directory:", err)
return
}
err=fs.RemoveDir("dir1")
iferr!=nil {
fmt.Println("Error removing directory:", err)
return
}
}This project is licensed under the GPL License. See the LICENSE file for details.
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
Just open an issue :)