File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -122,6 +122,32 @@ console.log(h.digest());
122
122
console .log (j .digest ());
123
123
```
124
124
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
+
125
151
Known issues
126
152
---
127
153
You can’t perform that action at this time.
0 commit comments