Skip to content

Commit dcc2dd5

Browse files
committed
Add example to sha1 docs
1 parent 3002c01 commit dcc2dd5

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

doc/api/crypto.markdown

+18
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,24 @@ which can be used to generate hash digests.
2929
of OpenSSL on the platform. Examples are `'sha1'`, `'md5'`, `'sha256'`, `'sha512'`, etc.
3030
On recent releases, `openssl list-message-digest-algorithms` will display the available digest algorithms.
3131

32+
Example: this program that takes the sha1 sum of a file
33+
34+
var filename = process.argv[2];
35+
var crypto = require('crypto');
36+
var fs = require('fs');
37+
38+
var shasum = crypto.createHash('sha1');
39+
40+
var s = fs.ReadStream(filename);
41+
s.on('data', function(d) {
42+
shasum.update(d);
43+
});
44+
45+
s.on('end', function() {
46+
var d = shasum.digest('hex');
47+
console.log(d + ' ' + filename);
48+
});
49+
3250
### hash.update(data)
3351

3452
Updates the hash content with the given `data`.

0 commit comments

Comments
 (0)