Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

3 Commits

Repository files navigation

RWFS - In-Memory Read-Write File System

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.

Features

  • 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.

Installation

To install RWFS, use the following command:

go get github.com/DanielcoderX/rwfs

Usage

Creating and Initializing the File System

package 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)
}

Core Functions

CreateDir

Creates a new directory in the current working directory.

func (fs*MemFileSystem) CreateDir(namestring) error

RemoveDir

Removes a directory from the current working directory.

func (fs*MemFileSystem) RemoveDir(namestring) error

ChangeDir

Changes the current working directory.

func (fs*MemFileSystem) ChangeDir(namestring) error

CreateFile

Creates a new file in the current working directory.

func (fs*MemFileSystem) CreateFile(name, ownerstring, permissionsFilePermission) (File, error)

OpenFile

Opens a file in the current working directory.

func (fs*MemFileSystem) OpenFile(namestring) (File, error)

RemoveFile

Removes a file from the current working directory.

func (fs*MemFileSystem) RemoveFile(namestring) error

ListFiles

Lists all files in the current working directory.

func (fs*MemFileSystem) ListFiles() ([]string, error)

ListDirContents

Lists the contents of the current working directory (both files and directories).

func (fs*MemFileSystem) ListDirContents() ([]DirEntry, error)

Additional Utilities

GetDirectoryContents

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() DirectoryContents

Example

Here 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
}
}

License

This project is licensed under the GPL License. See the LICENSE file for details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.

Contact

Just open an issue :)

About

Go library for an in-memory file system with optional persistence to disk and compression and many features.

Resources

Stars

4 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages