Skip to content

Commit 4ff5e17

Browse files
committed
Document restoreState/saveState
1 parent 8591c23 commit 4ff5e17

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,32 @@ console.log(h.digest());
122122
console.log(j.digest());
123123
```
124124

125+
### Storing and restoring the hash state
126+
127+
In case you need to continue with a partial hash later on, the `.saveState()` and `.restoreState()` methods are for you!
128+
129+
```js
130+
var blake2 = require('blake2');
131+
var h = blake2.createHash('blake2b');
132+
h.update(new Buffer("test"));
133+
134+
// Call .saveState() before .digest(), because .digest() finalizes internal state
135+
var state = h.saveState();
136+
137+
h.update(new Buffer("more"));
138+
console.log(h.digest());
139+
140+
// Much, MUCH later, in another process in another galaxy
141+
var j = blake2.createHash('blake2b');
142+
j.restoreState(state);
143+
144+
// h is unaffected by updates to j
145+
j.update(new Buffer("more"));
146+
147+
// This will be the same as h.digest()
148+
console.log(j.digest());
149+
```
150+
125151
Known issues
126152
---
127153

0 commit comments

Comments
 (0)