vvfs
v1.1.0
Published
Virtual File System for browser
Maintainers
Readme
Volcam Virtual File System (VVFS)
VVFS is a lightweight JavaScript class for handling a virtual in-memory file system using ArrayBuffer and Blob.
It is designed for browser-based environments such as IDEs, editors, or sandbox tools.
Features
- In-memory file storage
- Folder and file manipulation
- Text ↔ ArrayBuffer conversion
- Easy serialization and loading (export/import)
- No dependencies
Methods
File & Directory Management
| Method | Description |
|--------|-------------|
| mkdir(path) | Create directories recursively |
| writeFile(path, buffer) | Write or overwrite a file with an ArrayBuffer |
| delete(path) | Delete files or directories (recursive for folders) |
| rename(oldPath, newPath) | Move or rename files and directories |
| copy(srcPath, destPath) | Copy files or directories to a new location |
Reading Data
| Method | Description |
|--------|-------------|
| readFile(path) | Read file content and return an ArrayBuffer |
| listDir(path) | List all files and folders inside a directory |
| getTree(path) | Get the full directory tree structure |
Utilities
| Method | Description |
|--------|-------------|
| exists(path) | Check if a path exists |
| isFile(path) | Check if a path is a file |
| isDir(path) | Check if a path is a directory |
Serialization
| Method | Description |
|--------|-------------|
| serialize() | Export the entire file system as JSON |
| load(json) | Load a file system from a JSON object |
Text Conversion (Static)
| Method | Description |
|--------|-------------|
| vvfs.toBuffer(text) | Convert text to ArrayBuffer |
| vvfs.fromBuffer(buffer) | Convert ArrayBuffer back to text |
Usage Example
// Create VVFS instance
const vfs = new vvfs();
// Create a file
vfs.writeFile('/docs/readme.txt', vvfs.toBuffer('Hello World'));
// Read a file
const content = vvfs.fromBuffer(vfs.readFile('/docs/readme.txt'));
console.log(content); // Output: Hello World
// List directory content
console.log(vfs.listDir('/docs')); // ['readme.txt']