Crypto
hash.copy()
Clones unfinished hash state, useful when deriving fingerprints for several suffixes of a common prefix. Copy before digest finalizes the state. Tested on Node.js 22.16.0. Example output (one line per entry): ["true true"].
Formal Syntax & Structure
nodejs syntaxnodejs
hash.copy([options])Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| options | object | Stream options. |
Return Value
Hash
Independent copy.
Working Example
Example Snippetnodejs
import { createHash } from 'node:crypto';const prefix = createHash('sha256').update('book:');const a = prefix.copy().update('1').digest('hex');const b = prefix.update('2').digest('hex');console.log(a !== b, a === createHash('sha256').update('book:1').digest('hex'));