Skip to content

@technobuddha > library > Binary > Hash

Class: Crc32 ​

Defined in: crc32.ts:84

Compute the CRC32 checksum of a binary object

Example ​

typescript
const crc = new Crc32();
crc.update('hello world', 'utf8');
crc.digest('hex');
// '0d4a1185'
typescript
const crc = new Crc32();
crc.update(new Uint8Array([0x72,0x69,0x4c,0x4c,0x4f]));
crc.digest('hex');
// 'c031d497'

Extends ​

Constructors ​

Constructor ​

ts
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 ​

HashBase.constructor

Methods ​

digest() ​

Call Signature ​

ts
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 ​

Uint8Array

The hash digest

Overrides ​

HashBase.digest

Call Signature ​

ts
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 ​
ParameterTypeDescription
encodingBinaryEncodingOptional. The encoding to use for the output digest (e.g., 'hex', 'base64').
Returns ​

string

An encoded string, depending on the encoding parameter.

Overrides ​

HashBase.digest


update() ​

Call Signature ​

ts
update(data: BinaryObject | ArrayLike<number>): this;

Defined in: src/crc32.ts:98

Updates the hash with the given binary data.

Parameters ​
ParameterTypeDescription
dataBinaryObject | ArrayLike<number>The data to update the hash with, as a BinaryObject.
Returns ​

this

The hash instance for method chaining.

Overrides ​

HashBase.update

Call Signature ​

ts
update(data: string, encoding?: TextEncoding): this;

Defined in: src/crc32.ts:99

Updates the hash with the given string data.

Parameters ​
ParameterTypeDescription
datastringThe string data to update the hash with.
encoding?TextEncodingOptional text encoding of the input string (e.g., 'utf8').
Returns ​

this

The hash instance for method chaining.

Overrides ​

HashBase.update