Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jeremiah-shaulov/deno-crc32hash

Calculate crc32 hash of a string, Uint8Array, or Deno.Reader.
https://github.com/jeremiah-shaulov/deno-crc32hash

Last synced: about 2 months ago
JSON representation

Calculate crc32 hash of a string, Uint8Array, or Deno.Reader.

Awesome Lists containing this project

README

        

# crc32hash

[Documentation Index](generated-doc/README.md)

Deno module to calculate crc32 hash of a string, Uint8Array or ReadableStream.

This module exports 2 functions and 1 class:

> `function` [crc32](generated-doc/function.crc32/README.md)(data: `string` | Uint8Array): `number`

> `function` [crc32Stream](generated-doc/function.crc32Stream/README.md)(stream: ReadableStream\, bufferSize: `number`=8\*1024): Promise\<`number`>

> `class` Crc32

> {

>     📄 `get` [value](generated-doc/class.Crc32/README.md#-get-value-number)(): `number`

>     ⚙ [update](generated-doc/class.Crc32/README.md#-updatedatapart-string--uint8array-void)(dataPart: `string` | Uint8Array): `void`

>     ⚙ [valueOf](generated-doc/class.Crc32/README.md#-valueof-number)(): `number`

>     ⚙ [toString](generated-doc/class.Crc32/README.md#-tostring-string)(): `string`

> }

#### String:

```ts
import {crc32} from 'https://deno.land/x/[email protected]/mod.ts';

console.log(crc32('abc'));
```

#### Uint8Array:

```ts
import {crc32} from 'https://deno.land/x/[email protected]/mod.ts';

console.log(crc32(new Uint8Array([97, 98, 99])));
```

#### ReadableStream:

```ts
import {crc32Stream} from 'https://deno.land/x/[email protected]/mod.ts';

const fileUrl = new URL(import.meta.url);
using fp = await Deno.open(fileUrl, {read: true});
console.log(await crc32Stream(fp.readable));
```

#### Data parts

```ts
import {crc32, Crc32} from 'https://deno.land/x/[email protected]/mod.ts';
import {assertEquals} from 'jsr:@std/[email protected]/equals';

const crc = new Crc32;

crc.update('Lorem ipsum ');
assertEquals(crc.value, crc32('Lorem ipsum '));

crc.update('dolor sit amet');
assertEquals(crc.value, crc32('Lorem ipsum dolor sit amet'));
```