feat: add random
This commit is contained in:
@@ -87,6 +87,15 @@
|
||||
"publish_time": 1737272626140,
|
||||
"update_time": 1750472965159
|
||||
},
|
||||
"random.ts": {
|
||||
"script_name": "random.ts",
|
||||
"script_length": 780,
|
||||
"script_sha256": "71a282b63f97e0f6d0c5dd93bf1e71a395233e73ece741ec59b5f559ce9e82b1",
|
||||
"script_full_url": "https://git.hatter.ink/hatter/ts-scripts/raw/branch/main/single-scripts/random.ts",
|
||||
"single_script_file": true,
|
||||
"publish_time": 1758211365931,
|
||||
"update_time": 1758211365931
|
||||
},
|
||||
"sigstore-verify.ts": {
|
||||
"script_name": "sigstore-verify.ts",
|
||||
"script_length": 3676,
|
||||
|
||||
31
single-scripts/random.ts
Executable file
31
single-scripts/random.ts
Executable file
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env runts -- --allow-read
|
||||
|
||||
import { parseArgs } from "jsr:@std/cli/parse-args";
|
||||
|
||||
const flags = parseArgs(Deno.args, {
|
||||
boolean: ["help"],
|
||||
string: ["length"],
|
||||
});
|
||||
|
||||
if (flags.help) {
|
||||
console.log("random.ts [--post-message] [--length <length>]");
|
||||
Deno.exit(0);
|
||||
}
|
||||
|
||||
const len = parseInt(flags.length || "12", 10);
|
||||
|
||||
const buffer = new Uint8Array(len);
|
||||
const file = await Deno.open("/dev/random", { read: true });
|
||||
try {
|
||||
const nread = await file.read(buffer);
|
||||
if (nread == null) {
|
||||
throw "Read from /dev/random failed";
|
||||
}
|
||||
} finally {
|
||||
file.close();
|
||||
}
|
||||
|
||||
Deno.stdout.write(buffer);
|
||||
|
||||
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20250919T000056+08:00.MEUCIQD0uwOh8xr+8Oog7x6s
|
||||
// cUutQYrO4oFkS+SU1mZogTFuwAIgE7PWbiDvzAKFUSCc0byrdwWkXrcJp+7CDWr3+e83Zy4=
|
||||
Reference in New Issue
Block a user