-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
22 lines (16 loc) · 780 Bytes
/
example.js
File metadata and controls
22 lines (16 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
var fs = require('fs'),
treehash = require('./lib/treehash.js');
console.info('\n\nLoading the entire README.md into memory...');
var buf = require('fs').readFileSync('README.md');
console.info("The treehash for file README.md:\n" + treehash.getTreeHashFromBuffer(buf));
var thStream = treehash.createTreeHashStream ();
console.info('\n\nLoading README.md as a stream...');
var readStream = fs.createReadStream('README.md');
readStream.on('data', function(chunk) {
console.info('Updating treehash...');
thStream.update(chunk);
});
readStream.on('end', function (){
console.info("The treehash for file README.md:\n" + thStream.digest());
// console.info("The treehash for file README.md:\n" + thStream.digest()); // Exception from a second digestion.
});