├── README.md └── sha384 /README.md: -------------------------------------------------------------------------------- 1 | # deno-scripts 2 | A bunch of scripts written in Deno 3 | -------------------------------------------------------------------------------- /sha384: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env deno 2 | 3 | import "https://github.com/emn178/js-sha512/raw/v0.8.0/build/sha512.min.js"; 4 | 5 | const CHUNKSIZE = 128; 6 | 7 | async function main() { 8 | 9 | let files = []; 10 | 11 | if (Deno.args.length > 1) { 12 | files.push(...await Promise.all( 13 | Deno.args.slice(1).map(async path => ({ 14 | path, 15 | file: await Deno.open(path, "r"), 16 | })) 17 | )); 18 | } else { 19 | files.push({ 20 | path: "-", 21 | file: Deno.stdin, 22 | }); 23 | } 24 | 25 | const hashes = await Promise.all( 26 | files.map(async file => { 27 | const hash = sha384.create(); 28 | const buf = new Uint8Array(CHUNKSIZE); 29 | 30 | let read = 0; 31 | while (true) { 32 | read = await file.file.read(buf); 33 | hash.update(buf.slice(0, read)); 34 | if (read === Deno.EOF) { 35 | break; 36 | } 37 | } 38 | 39 | return { 40 | ...file, 41 | hash: hash.hex(), 42 | }; 43 | }) 44 | ); 45 | 46 | for (const file of hashes) { 47 | console.log(`${file.hash} ${file.path}`); 48 | } 49 | 50 | } 51 | 52 | main(); 53 | --------------------------------------------------------------------------------