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

Fix showing content of lazy loaded files in webR demo app editor component #320

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions tools/lzfs.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Arguments:
-h, --help Display this help message.
-o file If provided, write output to 'file' rather than stdout.
-u, --URL If provided, set a prefix for backing URLs.
-v, --verbose Verbose mode. Ouptut directory names as they are handled.
-v, --verbose Verbose mode. Output directory names as they are handled.
)")
quit(status = 1)
}
Expand Down Expand Up @@ -108,26 +108,32 @@ let loadImage = function(dir, file, src, mountpoint) {
FS.mkdirTree(dir);
let node = FS.createFile(dir, file, { isDevice: false } , true, true);

let forceLoadFile = function(obj) {
if (obj.isDevice || obj.isFolder || obj.link || obj.contents) {
let forceLoadFile = function() {
if (node.isDevice || node.isFolder || node.link || node.contents) {
return true;
}

if (ENVIRONMENT_IS_NODE) {
Module.mountImagePath(Module.locateFile(src), mountpoint)
Module.mountImagePath(Module.locateFile(src), mountpoint);

let mountNode = Module.FS.lookupPath(`${dir}/${file}`).node;
node.contents = mountNode.contents;
node.size = mountNode.size;
} else {
Module.mountImageUrl(Module.locateFile(src), mountpoint)
}
Module.mountImageUrl(Module.locateFile(src), mountpoint);

let mountNode = Module.FS.lookupPath(`${dir}/${file}`).node;
node.contents = mountNode.contents;
node.size = mountNode.size;
let mountNode = Module.FS.lookupPath(`${dir}/${file}`).node;
node.contents = new Uint8Array(
(new FileReaderSync()).readAsArrayBuffer(mountNode.contents)
);
node.size = mountNode.size;
}
}

Object.defineProperties(node, {
usedBytes: {
get: function() {
forceLoadFile(node);
forceLoadFile();
return node.size;
}
}
Expand All @@ -137,7 +143,7 @@ let loadImage = function(dir, file, src, mountpoint) {
Object.keys(node.stream_ops).forEach((key) => {
let fn = node.stream_ops[key];
stream_ops[key] = (...args) => {
forceLoadFile(node);
forceLoadFile();
return fn(...args);
};
});
Expand Down