Skip to content

Instantly share code, notes, and snippets.

@dangdennis
Last active June 15, 2022 18:46
Show Gist options
  • Save dangdennis/03d46c16ba85c225ffd6a6c916608b55 to your computer and use it in GitHub Desktop.
Save dangdennis/03d46c16ba85c225ffd6a6c916608b55 to your computer and use it in GitHub Desktop.
sha1 hash some files with Node
/**
* package.json
* { "type": "module" }
*/
import fs from 'fs/promises'
import path from 'path'
import { promisify } from 'util'
import { exec as cbExec } from 'child_process'
const exec = promisify(cbExec);
async function main(dirPath) {
const files = await fs.readdir(dirPath, "utf-8")
const fileHashes = {}
for (const f of files) {
const filePath = path.join(dirPath, f)
const { stdout } = await exec(`openssl sha1 ${filePath}`)
const hash = stdout.split("=")[1].slice(0, -1)
fileHashes[f] = hash
}
console.log(fileHashes)
}
main("your directory path")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment