export file command
This commit is contained in:
parent
33b23ec1ad
commit
a9cf2a1d21
|
@ -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",
|
||||||
|
|
|
@ -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]);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -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)},
|
||||||
|
|
Loading…
Reference in New Issue