save <file> => download <file>
This commit is contained in:
parent
a918280211
commit
5f5c2d94ce
3 changed files with 44 additions and 39 deletions
42
buildroot-v86/board/v86/rootfs_overlay/root/bin/download
Executable file
42
buildroot-v86/board/v86/rootfs_overlay/root/bin/download
Executable file
|
|
@ -0,0 +1,42 @@
|
||||||
|
#!/bin/sh
|
||||||
|
source /etc/profile.sh
|
||||||
|
|
||||||
|
file(){
|
||||||
|
javascript='
|
||||||
|
|
||||||
|
filename="'$(pwd)/$1'"
|
||||||
|
res = ""
|
||||||
|
|
||||||
|
function saveUint8Array(uint8Array, filename = "download.bin", mimeType = "application/octet-stream") {
|
||||||
|
if( !uint8Array ){
|
||||||
|
console.log( res = "file not found" )
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
const blob = new Blob([uint8Array], { type: mimeType });
|
||||||
|
const url = URL.createObjectURL(blob);
|
||||||
|
|
||||||
|
const a = document.createElement("a");
|
||||||
|
a.href = url;
|
||||||
|
a.download = filename.replace(/.*\//,"");
|
||||||
|
|
||||||
|
// Programmatically trigger the click event
|
||||||
|
document.body.appendChild(a);
|
||||||
|
a.click();
|
||||||
|
document.body.removeChild(a);
|
||||||
|
|
||||||
|
// Clean up the URL object
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
let term = document.querySelector("[isoterminal]")
|
||||||
|
term.emit("read_file", [filename, (str,buf) => saveUint8Array(buf, filename) ] )
|
||||||
|
|
||||||
|
return res
|
||||||
|
'
|
||||||
|
hook save
|
||||||
|
js "$javascript"
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
|
test -n "$1" && file "$1"
|
||||||
|
echo "Usage: download [file] # pass no argument to save VM state to localStorage"
|
||||||
|
|
@ -16,43 +16,6 @@ state(){
|
||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
|
|
||||||
file(){
|
|
||||||
javascript='
|
|
||||||
|
|
||||||
filename="'$(pwd)/$1'"
|
|
||||||
res = ""
|
|
||||||
|
|
||||||
function saveUint8Array(uint8Array, filename = "download.bin", mimeType = "application/octet-stream") {
|
|
||||||
if( !uint8Array ){
|
|
||||||
console.log( res = "file not found" )
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
const blob = new Blob([uint8Array], { type: mimeType });
|
|
||||||
const url = URL.createObjectURL(blob);
|
|
||||||
|
|
||||||
const a = document.createElement("a");
|
|
||||||
a.href = url;
|
|
||||||
a.download = filename.replace(/.*\//,"");
|
|
||||||
|
|
||||||
// Programmatically trigger the click event
|
|
||||||
document.body.appendChild(a);
|
|
||||||
a.click();
|
|
||||||
document.body.removeChild(a);
|
|
||||||
|
|
||||||
// Clean up the URL object
|
|
||||||
URL.revokeObjectURL(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
let term = document.querySelector("[isoterminal]")
|
|
||||||
term.emit("read_file", [filename, (str,buf) => saveUint8Array(buf, filename) ] )
|
|
||||||
|
|
||||||
return res
|
|
||||||
'
|
|
||||||
hook save
|
|
||||||
js "$javascript"
|
|
||||||
exit
|
|
||||||
}
|
|
||||||
|
|
||||||
test -z "$1" && state
|
test -z "$1" && state
|
||||||
test -n "$1" && file "$1"
|
echo "Usage: save"
|
||||||
echo "Usage: save [file] # pass no argument to save VM state to localStorage"
|
echo "it saves VM state to localStorage"
|
||||||
|
|
|
||||||
BIN
dist/v86-linux.iso
vendored
BIN
dist/v86-linux.iso
vendored
Binary file not shown.
Loading…
Add table
Reference in a new issue