wget can write to file

This commit is contained in:
b1ek 2023-03-17 16:09:14 +10:00
parent 34aaa678b1
commit b41f37efa7
Signed by: blek
GPG Key ID: 14546221E3595D0C
1 changed files with 8 additions and 6 deletions

View File

@ -26,8 +26,7 @@ Usage: ${argv[0]} [URL] [-O out.file] [-V] [-Q] [-s]
terminal.writeln(`${argv[0]}: missing output file`);
return;
}
filepath = argv[argv.indexOf('-O') + 1]
return;
filepath = argv[argv.indexOf('-O') + 1];
}
function progress(p) {
@ -35,11 +34,15 @@ Usage: ${argv[0]} [URL] [-O out.file] [-V] [-Q] [-s]
if (total == 0)
total = '?'
terminal.write(`\rDownloading... ${p.loaded}/${total}`);
// terminal.write(`\rDownloading... ${p.loaded}/${total}`);
}
function write(file) {
if (filepath == '-') {
terminal.write(file);
} else {
fs.writeFileSync(filepath, file);
}
}
let file;
@ -50,8 +53,7 @@ Usage: ${argv[0]} [URL] [-O out.file] [-V] [-Q] [-s]
req.onprogress = progress;
req.onload = (e) => {
if (e.type == 'load') {
let enc = new TextDecoder("utf-8");
terminal.write(enc.decode(req.response));
write(e.response);
}
};
req.send();