From 0291c3096f5d1c2b7b32a994da3d9722133a1591 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Tue, 15 Oct 2019 12:22:13 +0200 Subject: [PATCH] fixup! add example --- doc/api/crypto.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/doc/api/crypto.md b/doc/api/crypto.md index fe5ddad29367ac..bc8d0d83d84ecc 100644 --- a/doc/api/crypto.md +++ b/doc/api/crypto.md @@ -1061,6 +1061,23 @@ specify the desired output length in bytes. An error is thrown when an attempt is made to copy the `Hash` object after its [`hash.digest()`][] method has been called. +```js +// Calculate a rolling hash. +const crypto = require('crypto'); +const hash = crypto.createHash('sha256'); + +hash.update('one'); +console.log(hash.copy().digest('hex')); + +hash.update('two'); +console.log(hash.copy().digest('hex')); + +hash.update('three'); +console.log(hash.copy().digest('hex')); + +// Etc. +``` + ### hash.digest(\[encoding\])