This extension will allow users to create a virtual file system (VFS) inside the app. Instead of writing files to the actual storage, it will keep them in memory and simulate a real filesystem
Download Now:
com.bbl.virtualfilesystem.aix (5.5 KB)
Features:
Create, read, delete, and check for files in a virtual storage system
Encrypt and decrypt virtual files using Base64
Export and import the entire virtual file system as a single encoded string
Purpose: Creates a virtual file in the system with the given path
and content
.
Purpose: Reads and returns the content of a file stored in the virtual file system.
Purpose: Deletes a file from the virtual file system.
Purpose: Checks if a file exists in the virtual file system.
Purpose: Encrypts a file’s content using Base64 encoding.
Purpose: Decrypts a previously encrypted file.
Purpose: Converts the entire virtual file system into a Base64-encoded string.
Purpose: Restores the virtual file system from an exported Base64 string.
Thanks for getting bored by reading these
Made by Aman
package com.bbl.virtualfilesystem;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.ComponentContainer;
import com.google.appinventor.components.runtime.errors.YailRuntimeError;
import com.google.appinventor.components.runtime.util.YailList;
import java.util.HashMap;
import java.util.Map;
import android.util.Base64;
import com.google.appinventor.components.annotations.*;
import com.google.appinventor.components.runtime.*;
import java.nio.charset.StandardCharsets;
public class VirtualFileSystem extends AndroidNonvisibleComponent {
private final Map<String, String> vfs = new HashMap<>();
public VirtualFileSystem(ComponentContainer container) {
super(container.$form());
}
@SimpleFunction
public void CreateFile(String path, String content) {
vfs.put(path, content);
}
@SimpleFunction
public String ReadFile(String path) {
return vfs.getOrDefault(path, "File not found");
}
@SimpleFunction
public void DeleteFile(String path) {
vfs.remove(path);
}
@SimpleFunction
public boolean FileExists(String path) {
return vfs.containsKey(path);
}
@SimpleFunction
public void EncryptFile(String path) {
if (vfs.containsKey(path)) {
String content = vfs.get(path);
String encrypted = Base64.encodeToString(content.getBytes(StandardCharsets.UTF_8), Base64.DEFAULT);
vfs.put(path, encrypted);
}
}
@SimpleFunction
public void DecryptFile(String path) {
if (vfs.containsKey(path)) {
try {
String encrypted = vfs.get(path);
byte[] decodedBytes = Base64.decode(encrypted, Base64.DEFAULT);
String decrypted = new String(decodedBytes, StandardCharsets.UTF_8);
vfs.put(path, decrypted);
} catch (Exception e) {
vfs.put(path, "Decryption failed");
}
}
}
@SimpleFunction
public String ExportVFS() {
return Base64.encodeToString(vfs.toString().getBytes(StandardCharsets.UTF_8), Base64.DEFAULT);
}
@SimpleFunction
public void ImportVFS(String encodedData) {
try {
byte[] decodedBytes = Base64.decode(encodedData, Base64.DEFAULT);
String decodedString = new String(decodedBytes, StandardCharsets.UTF_8);
vfs.clear();
for (String entry : decodedString.substring(1, decodedString.length() - 1).split(", ")) {
String[] keyValue = entry.split("=");
if (keyValue.length == 2) {
vfs.put(keyValue[0], keyValue[1]);
}
}
} catch (Exception e) {
vfs.clear();
}
}
}