root-file-viewer icon indicating copy to clipboard operation
root-file-viewer copied to clipboard

Use JSROOT FileProxy to access files from WebView

Open linev opened this issue 3 years ago • 9 comments

I introduce FileProxy class in JSROOT and will try to use it here. Idea that binary data from the file can be read though such proxy.

That I am missing - how node modules can be used on Code side? You see commented lines:

    // let btoa = require('btoa');   // this should be "btoa" module
    // let fs = require('fs');       // this is native "fs" module
    // let fd = fs.openSync(filename, 'r');
    // if (fd) {
    // let stats = fs.statSync(filename.uri);
    //  filesize = stats.size;
    // }

I need standard "fs" module and "btoa" module from node. Also would be nice if you could help to produce filename which can be used to read file content.

linev avatar Jul 05 '22 11:07 linev

Now it is working, using JSROOT from master branch.

I found a way to correctly use fs - was relatively easy. It can be merged if you like

linev avatar Jul 07 '22 16:07 linev

Hey @linev!

All your work here is incredible!! Thank you so much!

I don't have much time now to go through everything, but I'll try to get to it as soon as possible. Would you mind if I split all the different changes in different PRs when I have the time?

AlbertoPdRF avatar Jul 10 '22 14:07 AlbertoPdRF

I've finally been able to take a look at the PR! For these changes to also work when the extension runs in remote environments, vscode.workspace.fs should be used instead of regular fs. However, I believe this wouldn't allow us to read ROOT files in chunks as of now (see https://github.com/microsoft/vscode/issues/84515#issuecomment-1205111291.) Let's wait and see what the VS Code people reply.

Meanwhile, I've extracted the part that allows the PNG screenshots to be saved in 48e321b91d363b6a94551c5d4bb5354775654a6e.

Thanks for all your help @linev!

AlbertoPdRF avatar Aug 04 '22 13:08 AlbertoPdRF

For these changes to also work when the extension runs in remote environments, vscode.workspace.fs should be used instead of regular fs.

What kind of remote environments? Reading of local files works ok.

However, I believe this wouldn't allow us to read ROOT files in chunks as of now

As I understand, it is limitation of vscode.workspace.fs. Probably, one can use it when it provides right functionality.

linev avatar Aug 09 '22 11:08 linev

For these changes to also work when the extension runs in remote environments, vscode.workspace.fs should be used instead of regular fs.

What kind of remote environments? Reading of local files works ok.

When VS Code runs on the browser, through SSH, or things like that.

However, I believe this wouldn't allow us to read ROOT files in chunks as of now

As I understand, it is limitation of vscode.workspace.fs. Probably, one can use it when it provides right functionality.

Yes, exactly! And it seems like the right functionality is already implemented, it's just that it's not exposed yet for extensions to use.

AlbertoPdRF avatar Aug 09 '22 12:08 AlbertoPdRF

Probably, one can detect such remote environment? And if it runs on web server - may be file URL will be also with http? In such case one could use standard JSROOT file I/O which involves http requests.

linev avatar Aug 09 '22 12:08 linev

Yes, I believe one should be able to detect the remote environment. However, I don't think one could use http requests like you can do when JSROOT runs in the browser standalone, as VS Code mounts a virtual file system and everything runs in more or less the same way (WebView restrictions, etc.)

AlbertoPdRF avatar Aug 09 '22 12:08 AlbertoPdRF

Then one have to use vscode.workspace.fs - but only when it is ready for such use.

linev avatar Aug 09 '22 12:08 linev

Yep! Let's see if the people from VS Code reply, and then we can see how to move forward :slightly_smiling_face:

AlbertoPdRF avatar Aug 09 '22 13:08 AlbertoPdRF