Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VirtualFS not storing files correctly. #34

Closed
JKincorperated opened this issue Apr 20, 2024 · 6 comments
Closed

VirtualFS not storing files correctly. #34

JKincorperated opened this issue Apr 20, 2024 · 6 comments

Comments

@JKincorperated
Copy link

VirtualFS reacts badly to files that are not UTF-8 encoded.

Example:

Upload a file containing one byte 0x98.
Download the file again and view in hex editor.
The file now contains 0xEFBFBD

@harshitsuthar77731
Copy link

It appears that VirtualFS encounters issues with non-UTF-8 encoding. As a result, it replaces such files with UTF-8 replacement characters, represented as 0xEF 0xBF 0xBD in hexadecimal. To address this, it's advisable to first convert these files to UTF-8 encoding before uploading them to VirtualFS.

@datkat21
Copy link
Member

datkat21 commented Apr 20, 2024

VirtualFS should be used for storing text as it uses JSON strings for file content. Please use UTF-8 as per the JSON string requirements. Large files will use Blobs to store binary content which is how the file system handles larger binary files such as images, audio, and video. Large binary files should store fine if they are saved as a Blob.

pluto/pkgs/lib/VirtualFS.js

Lines 197 to 208 in 43ac095

// if file is bigger than 8kb then put it into the special bin
if (contents.length > 8192) {
const vfsImportPath = Math.random().toString(36).substring(2);
if (vfsImportPath === "fs") return "vfsImportError:not-allowed";
// save link to file
await localforage.setItem(vfsImportPath, contents);
current[filename] = `vfsImport:${vfsImportPath}`;
} else {
// save normally
current[filename] = contents;
}

@JKincorperated
Copy link
Author

A potential solution could be in the file manager when uploading files, checking if the MIME type is not text other than checking if it is an image, video, etc.

if (
file.type.startsWith("image") ||
file.type.startsWith("audio") ||
file.type.startsWith("video")
) {

@datkat21
Copy link
Member

Binary file upload was only originally intended for uploading those file types, as binary files were never tested

@JKincorperated
Copy link
Author

I'll give it a test locally.

@JKincorperated
Copy link
Author

Check #35 for info on changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants