mirror of https://github.com/nodejs/node.git
Add example to sha1 docs
parent
3002c01f40
commit
dcc2dd5e1f
|
@ -29,6 +29,24 @@ which can be used to generate hash digests.
|
|||
of OpenSSL on the platform. Examples are `'sha1'`, `'md5'`, `'sha256'`, `'sha512'`, etc.
|
||||
On recent releases, `openssl list-message-digest-algorithms` will display the available digest algorithms.
|
||||
|
||||
Example: this program that takes the sha1 sum of a file
|
||||
|
||||
var filename = process.argv[2];
|
||||
var crypto = require('crypto');
|
||||
var fs = require('fs');
|
||||
|
||||
var shasum = crypto.createHash('sha1');
|
||||
|
||||
var s = fs.ReadStream(filename);
|
||||
s.on('data', function(d) {
|
||||
shasum.update(d);
|
||||
});
|
||||
|
||||
s.on('end', function() {
|
||||
var d = shasum.digest('hex');
|
||||
console.log(d + ' ' + filename);
|
||||
});
|
||||
|
||||
### hash.update(data)
|
||||
|
||||
Updates the hash content with the given `data`.
|
||||
|
|
Loading…
Reference in New Issue