export file command

This commit is contained in:
b1ek 2023-03-17 16:24:18 +10:00
parent 33b23ec1ad
commit a9cf2a1d21
Signed by: blek
GPG Key ID: 14546221E3595D0C
3 changed files with 45 additions and 0 deletions

View File

@ -21,6 +21,7 @@
"dependencies": { "dependencies": {
"@parcel/fs": "^2.8.3", "@parcel/fs": "^2.8.3",
"copy-to-clipboard": "^3.3.3", "copy-to-clipboard": "^3.3.3",
"file-saver": "^2.0.5",
"memfs": "^3.4.13", "memfs": "^3.4.13",
"react": "^18.2.0", "react": "^18.2.0",
"react-dom": "^18.2.0", "react-dom": "^18.2.0",

View File

@ -0,0 +1,43 @@
import { Terminal } from 'xterm';
import { saveAs } from 'file-saver';
const fs = require('../fs');
/**
*
* @param { string[] } argv
* @param { Terminal } terminal
*/
module.exports = (argv, terminal) => {
if (argv.indexOf('--help') != -1 || argv.length == 1) {
terminal.write(
`Usage: ${argv[0]} [FILES] [-z]
Export file from filesystem to your device.
-z Compress in zip format (not supported)`);
return;
}
let files = [...argv];
files.shift();
if (argv.indexOf('-z') != -1) {
terminal.write(`${argv[0]}: cannot zip '${files.join(' ').replace('\'', "\\'")}': not supported\n`);
return;
}
try {
var isFileSaverSupported = !!new Blob;
} catch (e) {}
if (!isFileSaverSupported) {
terminal.write(`${argv[0]}: Your browser does not support this feature.`);
return;
}
if (!fs.existsSync(argv[1])) {
terminal.write(`${argv[0]}: cannot open ${argv[1]}: no such file or directory\n`);
return;
}
saveAs(new Blob([fs.readFileSync(argv[1])]), argv[1]);
}

View File

@ -7,6 +7,7 @@ let cmds = {
'skills': require('./skills'), 'skills': require('./skills'),
'mkdir': require('./mkdir'), 'mkdir': require('./mkdir'),
'wget': require('./wget'), 'wget': require('./wget'),
'export_file': require('./export_file'),
// alias l='ls -l' // alias l='ls -l'
'l': (a,t) => {require('./ls')([...a, '-l'], t)}, 'l': (a,t) => {require('./ls')([...a, '-l'], t)},