Created
April 13, 2016 02:53
-
-
Save craigpatten/a71f596748b62434231592b72c82d00d to your computer and use it in GitHub Desktop.
Hashing a filesystem hierarchy.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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