I am trying to create a self-extracting archive, in the form of a single .html file (as opposed to the more traditional .exe ones). In other words a single .html file with another file (of any type) embedded in it.
Here is a very simple example of a .html file that does exactly that. It has a link which you click to generate generate and download a .png file from a base 64 encoded string which is hard-coded in the source. This could be extended fairly easily to work with any kind of file.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Self-Extracting Archive</title>
</head>
<body>
<a href="data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="
download>Save File</a>
</body>
</html>
The problem is that base 64 is not very efficient. Is it possible to encode the file as plain binary? I know if it is possible that it will probably be hacky. That is fine, as long as it can be made compatible with all major browsers.
I think something like File.getAsBinary()
might work. If it were available (but it isn't), you could append the binary to the end of the .html file and then somehow convince the browser not to parse into that part of the file.