Can I read files from the disk by using Webassembly? (re-evaluated) - rust

what's currently possible in webassembly running in the browser regarding accessing the local file system? There's an older question that says it's not possible due to security restrictions. But some places (e.g. https://fjolt.com/article/javascript-new-file-system-api) say that there's a new file system API available in some browsers that would allow that.
a) what needs to be done to be able to use that api?
b) can I use it from rust with webassembly - and how?
Thank you for any useful pointer.
Tobias

The current web APIs (https://developer.mozilla.org/en-US/docs/Web/API) only lets you access files in the local files system by prompting the user to open or save files.
These APIs are not (yet) accesible from webassembly directly. So what you have to do is
Use javascript to prompt the user to open a file (or directory)
Grab the contents of the file and pass it to your webassembly code
Process the contents with webassembly (or in your case rust compiled to webassembly)
Pass the processed content back to javascript that can prompt the user to save the file.
or some variation of the theme above.
Read more about webassmbly usage here
https://developer.mozilla.org/en-US/docs/WebAssembly/Using_the_JavaScript_API
and Rust and webassembly e.g. here
https://developer.mozilla.org/en-US/docs/WebAssembly/Rust_to_wasm

Related

Is there anyway to access the base path of an uploaded file with Rust WASM?

Does WebAssembly have the same issue as native JS(for very valid security reasons) that it cannot access the base/root path of any given uploaded file or selected folder? I want to write a Rust UI app with seed and using rfd (or its previous iterations nfd/nfd2) that users can indicate a file path so the application can install certain files in the correct place.
Otherwise can seed compile to a local .exe instead of a web based app, and therefore have proper access to the file system?
Thanks

How should I access the file system of the VSCode's user?

So I am making a VSCode extension. It should read and modify files of user's file system. Should I do it with node's fs or should I use some VSCode's interface/API for this?
If the latter is correct then what is the API namespace I need (workspace or something)?
If the former is okay, how can I really use fs? What if the user does not have node.js installed? Or is it always installed with VSCode?
It depends.
In general use vscode's TextDocument api for:
Reading text files from the workspace. This api ensures that you always read the current state of the file (even if it has not been saved to disk yet).
Modifying text file content in the workspace. You can also use save to write a modified file back to disk.
Reading resources from file system providers
Use fs for:
Reading and writing files that are outside of the workspace.
Reading and writing files that should not be tracked by VS Code. Opening a TextDocument can cause VS Code and its extension to try processing the file.
Reading and writing binary files.
This api proposal would also be of interest for you. It would enable more low level file reading/writing directly using VS Code.
(Also, you can always safely use node since VS Code includes a copy for extensions to use)

Need help in developing a custom WebDav client using node.js

I am developing an open source application which should mount webdav share to local drive letter just like NETDRIVE and WEBDRIVE using node.js and electron-js, so in my application at present I am downloading all files from webdav share which takes a lot of time and not reliable for heavy data. Is there any other approach so that whenever user access a file, only that particular file should be fetched from webdav share, I’ve tried to display files meta data(dummy) structure in directory and kept that directory under file-watcher. So that when user tries to open a file then watcher should capture file open event to get which file was user trying to access, so that in background of application a service will triggered to fetch that particular file using file-path as reference, but none of them are unable to capture file open event. Is there any other approach to do so, correct me if I am in wrong direction.
Thank's
I think you want virtual file-system and recommend Dokan library.
Dokan is the start point of Windows virtual file-system application.
Open Source : Dokan (https://en.wikipedia.org/wiki/Dokan_Library)
Commercial: EldoS CBFS (https://www.eldos.com/cbfs)
Google, Naver use Dokan and NetDrive, RaiDrive(mine) use CBFS.

Using DirectXTK to save screenshots in Windows Store app (Metro)

I'm working on a C++ Windows Store DirectX app and I'm trying to save screenshots to disk every so often.
I am using the DirectX Tool Kit (DirectXTK) and the function SaveDDSTextureToFile which returns an HRESULT.
The problem is that the returned HRESULT is always:
E_ACCESSDENIED General access denied error.
I assume this is some permissions/capabilities thing (it being a windows store app) but I can't find what I need to ask for permission for to be able to save files to disk.
The DirectX ToolKit says it is for Windows store applications as well as desktop applications but I can't find any information on their codeplex either.
Does anyone know what I need to have permission to do for this to work?
Thanks for your time.
Windows Store apps are sandboxed and have fewer permissions than desktop apps, especially when it comes to file access. By default, apps only have access to write to the local storage directory, which isn't easily accessible from the shell. If you want to save to the Pictures or Documents library, you will need to specify this access in the package manifest. Additionally, you will need to use the WinRT file APIs to write the DDS files. To do this, use SaveDDSTextureToMemory, then write the resulting raw DDS data to the StorageFile. Check out the File access sample for more info on the WinRT APIs involved in writing this data as a file.
I've managed to find a way to do it. Basically as MooseBoys says you cannot save to anywhere because the app is sandboxed.
You can however save to the TempState folder of your apps package in AppData, which is all I need because I'm using this feature for debugging.
So the line I call is:
DirectX::SaveWICTextureToFile(deviceContext, texture2D, GUID_ContainerFormatPng, L"C:\\Users\\USERNAME\\AppData\\Local\\Packages\\PACKAGENAME\\TempState\\test.png");
And this works great.

JavaFx 2 - Self Contained Applications and their preferences, database, etc

Let say i have a cross-platform runnable application
This application create then read/write some data and preference in external files
Bundle hierarchy is as follow:
ApplicationFolder/application.jar
ApplicationFolder/database.odb
ApplicationFolder/config.xml
Whether it's on a Mac, Windows or Linux, the application knows that everything is next to her (ie: /database.odb or /config.xml)
Now comes the Self Contained Application feature provided by JavaFx 2
The application is embedded in .exe on Windows, .app on Mac and don't know yet about Linux...
As a Mac user i've tested it on Mac and saw that database.odb and config.xml are now created at the user root path
I thus agree that i should think of a cross-platform mechanism to save/read my application preferences regarding the operating system
But i'm not quite sure of what to do and how to do it (can't find any googling help either..)
On windows, the .exe is installed in a folder, so i guess i can keep the same behavior
On Mac, the .app is a folder and i should keep everything inside (how to get the .app path ?!)
Isn't there a built-in mechanism in Java/JavaFx ?
Thanks a lot for any comment, advice, documentation or else that you could give me
Badisi
There are many ways to do this. I have listed some of them here in no particular order. The recommended approach depends on the type of data being stored.
Java provides a couple of mechanisms (e.g. the properties API and the preferences API) for maintaining application preferences.
If your application is sophisticated enough to benefit from an database, then you might want to use Java EE or Spring, both of which have their own configuration mechanisms.
For read-only configuration, you can bundle the relevant files inside your application jar.
To store customized application configuration files or client application wide databases in relative to the application jar, write the required files at runtime. See How do I get the directory that the currently executing jar file is in?.
For user specific configuration, use System.getProperty("user.home") to retrieve the user's home directory, then create a subdirectory for your preference storage (for example "{$user.dir}/.myapp") with hidden file attributes so that it doesn't show up on a standard file directory list.
If your app relies on internet connectivity, then you can store some of this information server side rather than the client and make use of it from the client using internet protocols. An advantage of this approach is that user configuration and data is automatically ported across client machines.

Resources