Skip to content

Instantly share code, notes, and snippets.

@craigpatten
Created April 13, 2016 02:53
Show Gist options
  • Select an option

  • Save craigpatten/a71f596748b62434231592b72c82d00d to your computer and use it in GitHub Desktop.

Select an option

Save craigpatten/a71f596748b62434231592b72c82d00d to your computer and use it in GitHub Desktop.
Hashing a filesystem hierarchy.
#!/usr/bin/env node
const fs = require("fs");
const crypto = require("crypto");
const walk = require("walk");
const concat = require("concat-stream");
const walker = walk.walk("/usr/share/man");
const hashes = {};
walker.on("file", function(root, stats, next) {
const fullName = root + "/" + stats.name;
const hash = crypto.createHash("sha256");
hash.setEncoding("hex");
const input = fs.createReadStream(fullName);
const output = concat(function(data) {
hashes[fullName] = data;
});
input.pipe(hash).pipe(output);
next();
});
walker.on("end", function() {
console.log(hashes);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment