1
0
Fork 0

Add a simple SHA384 generator

master
Ambrose Chua 2019-10-06 17:48:10 +08:00
parent 162f58f0c4
commit 2affbf89a0
Signed by: ambrose
GPG Key ID: BC367D33F140B5C2
1 changed files with 52 additions and 0 deletions

52
sha384 Executable file
View File

@ -0,0 +1,52 @@
#!/usr/bin/env deno
import "https://github.com/emn178/js-sha512/raw/v0.8.0/build/sha512.min.js";
const CHUNKSIZE = 128;
async function main() {
let files = [];
if (Deno.args.length > 1) {
files.push(...await Promise.all(
Deno.args.slice(1).map(async path => ({
path,
file: await Deno.open(path, "r"),
}))
));
} else {
files.push({
path: "-",
file: Deno.stdin,
});
}
const hashes = await Promise.all(
files.map(async file => {
const hash = sha384.create();
const buf = new Uint8Array(CHUNKSIZE);
let read = 0;
while (true) {
read = await file.file.read(buf);
hash.update(buf.slice(0, read));
if (read === Deno.EOF) {
break;
}
}
return {
...file,
hash: hash.hex(),
};
})
);
for (const file of hashes) {
console.log(`${file.hash} ${file.path}`);
}
}
main();