Posted February 24, 2020
Here is a task, and I am wondering if I can do this in JavaScript.
The basic idea is simple: The program reads in a binary file, chosen by the user, modifies it in some way (for example, XORing every byte with 0xcc, but it could be something more complex, like image processing or (de)compression), and then returns the result to the user (perhaps as a file that would then be downloaded).
Here is where it gets interesting. The program needs to be able to run:
* In a modern-ish web browser, completely on the client (in other words, must run with networking disabled).
* On the server, with JavaScript disabled on the client, ideally using the same form as the client-side example.
* As a stand-alone command from the command line. Ideally, the filename should be specifiable over the command line, and the program should also have the option to work with standard input and output (so it can be used in a pipeline on the shell).
I would like as much code to be shared between these versions. In particular, I would like to share the code for input and output, as well as all the logic involved in the transformation done to the file, with the only differences being how the user chooses what file to process.
Is JavaScript suitable for this task, or should I look into something like WebAssembly (which would have the advantage of maybe also being portable to embedded)?
Now, as for browser support requirements:
* All current LTS versions of major browsers, as well as more recent versions. Ideally, it should work on future versions as well (so no relying on deprecated features).
* The versions of firefox and chromium in debian stable. (At least I'm not requiring the oldest supported version of RHEL.)
* The server-side program should work with browsers that do not support JavaScript, such as lynx.
* For the command-line version, it's reasonable to require the user to install node,js and some npm libraries, as long as those libraries are well-maintained and under a permissive open source license.
The basic idea is simple: The program reads in a binary file, chosen by the user, modifies it in some way (for example, XORing every byte with 0xcc, but it could be something more complex, like image processing or (de)compression), and then returns the result to the user (perhaps as a file that would then be downloaded).
Here is where it gets interesting. The program needs to be able to run:
* In a modern-ish web browser, completely on the client (in other words, must run with networking disabled).
* On the server, with JavaScript disabled on the client, ideally using the same form as the client-side example.
* As a stand-alone command from the command line. Ideally, the filename should be specifiable over the command line, and the program should also have the option to work with standard input and output (so it can be used in a pipeline on the shell).
I would like as much code to be shared between these versions. In particular, I would like to share the code for input and output, as well as all the logic involved in the transformation done to the file, with the only differences being how the user chooses what file to process.
Is JavaScript suitable for this task, or should I look into something like WebAssembly (which would have the advantage of maybe also being portable to embedded)?
Now, as for browser support requirements:
* All current LTS versions of major browsers, as well as more recent versions. Ideally, it should work on future versions as well (so no relying on deprecated features).
* The versions of firefox and chromium in debian stable. (At least I'm not requiring the oldest supported version of RHEL.)
* The server-side program should work with browsers that do not support JavaScript, such as lynx.
* For the command-line version, it's reasonable to require the user to install node,js and some npm libraries, as long as those libraries are well-maintained and under a permissive open source license.