crc32hash
Deno module to calculate crc32 hash of a string, Uint8Array or ReadableStream.
This module exports 2 functions and 1 class:
function
crc32(data:string
| Uint8Array):number
function
crc32Stream(stream: ReadableStream<Uint8Array>, bufferSize:number
=8*1024): Promise<number
>
class
Crc32
{
📄get
value():number
⚙ update(dataPart:string
| Uint8Array):void
⚙ valueOf():number
⚙ toString():string
}
String:
import {crc32} from 'https://deno.land/x/crc32hash@v2.0.1/mod.ts';
console.log(crc32('abc'));
Uint8Array:
import {crc32} from 'https://deno.land/x/crc32hash@v2.0.1/mod.ts';
console.log(crc32(new Uint8Array([97, 98, 99])));
ReadableStream:
import {crc32Stream} from 'https://deno.land/x/crc32hash@v2.0.1/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
import {crc32, Crc32} from 'https://deno.land/x/crc32hash@v2.0.1/mod.ts';
import {assertEquals} from 'jsr:@std/assert@1.0.7/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'));