[PATCH v2 6/7] coreutils: Import from packages feed
Petr Štetiar
ynezz at true.cz
Mon Jan 9 06:35:56 PST 2023
Petr Štetiar <ynezz at true.cz> [2023-01-09 11:50:37]:
Hi,
> BTW ucode has `b64dec()`[1] so perhaps another viable option.
>
> 1. https://github.com/jow-/ucode#663-b64decstr
wanted to refresh my ucode brain cells, so I've explored feasibility of that
suggestion and it seems to work just fine:
#!/usr/bin/ucode
import { stdin, open, error } from 'fs';
if (length(ARGV) == 0 && stdin.isatty()) {
warn("usage: b64decode [stdin|path]\n");
exit(1);
}
let fp = stdin;
let source = ARGV[0];
if (source) {
fp = open(source);
if (!fp) {
warn(`b64decode: unable to open ${source}: ${error()}\n`);
exit(1);
}
}
print(b64dec(fp.read("all")));
fp.close();
exit(0);
BTW it needs recent ucode with fs.stdin.isatty() support[1].
Thanks Jo for helping me making above script more idiomatic. IMO it looks more
human readable, portable and maintanable then that awk based solution.
1. https://github.com/jow-/ucode/commit/be30472bfdbbb410e8934b48a56d26c5c630d0f1
Cheers,
Petr
More information about the openwrt-devel
mailing list