@technobuddha > library > Binary > Hash
Class: Crc32
Defined in: crc32.ts:84
Compute the CRC32 checksum of a binary object
Example
const crc = new Crc32();
crc.update('hello world', 'utf8');
crc.digest('hex');
// '0d4a1185'const crc = new Crc32();
crc.update(new Uint8Array([0x72,0x69,0x4c,0x4c,0x4f]));
crc.digest('hex');
// 'c031d497'Extends
Constructors
Constructor
new Crc32(): Crc32;Defined in: src/crc32.ts:93
Creates a new CRC32 hash instance and initializes its internal state.
Returns
Crc32
Remarks
The CRC value is initialized to -1, as required by the CRC32 algorithm specification. Use update to process data and digest to obtain the final hash value.
Overrides
Methods
digest()
Call Signature
digest(): Uint8Array;Defined in: src/crc32.ts:116
Finalizes the hash computation and returns the resulting hash digest. This method performs any necessary padding and processes the final block of data according to the hash algorithm's specification.
Returns
The hash digest
Overrides
Call Signature
digest(encoding: BinaryEncoding): string;Defined in: src/crc32.ts:117
Finalizes the hash computation and returns the resulting hash digest. This method performs any necessary padding and processes the final block of data according to the hash algorithm's specification.
Parameters
| Parameter | Type | Description |
|---|---|---|
encoding | BinaryEncoding | Optional. The encoding to use for the output digest (e.g., 'hex', 'base64'). |
Returns
string
An encoded string, depending on the encoding parameter.
Overrides
update()
Call Signature
update(data: BinaryObject | ArrayLike<number>): this;Defined in: src/crc32.ts:98
Updates the hash with the given binary data.
Parameters
| Parameter | Type | Description |
|---|---|---|
data | BinaryObject | ArrayLike<number> | The data to update the hash with, as a BinaryObject. |
Returns
this
The hash instance for method chaining.
Overrides
Call Signature
update(data: string, encoding?: TextEncoding): this;Defined in: src/crc32.ts:99
Updates the hash with the given string data.
Parameters
| Parameter | Type | Description |
|---|---|---|
data | string | The string data to update the hash with. |
encoding? | TextEncoding | Optional text encoding of the input string (e.g., 'utf8'). |
Returns
this
The hash instance for method chaining.