✨ Add Base32 encoding support and enhance caching logic
This commit is contained in:
45
single-scripts/get-rfc.ts
Executable file
45
single-scripts/get-rfc.ts
Executable file
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env -S deno run -A
|
||||
|
||||
import { parseArgs } from "jsr:@std/cli/parse-args";
|
||||
import {
|
||||
args,
|
||||
exit,
|
||||
fetchFileWithCache,
|
||||
readFileToString,
|
||||
} from "https://global.hatter.ink/script/get/@62/deno-commons-mod.ts";
|
||||
|
||||
const flags = parseArgs(args(), {
|
||||
boolean: ["help"],
|
||||
string: ["id"],
|
||||
});
|
||||
|
||||
function printHelp() {
|
||||
console.log("get-rfc.ts --id <RFC ID>");
|
||||
}
|
||||
|
||||
if (flags.help) {
|
||||
printHelp();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (flags.id) {
|
||||
const rfcId = parseInt(flags.id, 10);
|
||||
if (isNaN(rfcId)) {
|
||||
console.error("Invalid RFC id");
|
||||
exit(1);
|
||||
}
|
||||
await getAndPrintRfc(rfcId);
|
||||
} else {
|
||||
printHelp();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
async function getAndPrintRfc(rfcId: number): Promise<void> {
|
||||
const url = `https://play.hatter.me/ietf/rfc${rfcId}.txt`;
|
||||
const fileMeta = await fetchFileWithCache(url, {
|
||||
base32Filename: true,
|
||||
hierarchicalCacheDir: true,
|
||||
});
|
||||
const content = await readFileToString(fileMeta.cache_full_path);
|
||||
console.log(content);
|
||||
}
|
||||
Reference in New Issue
Block a user