chunkCrc(bytes: Uint8Array): number
Calculates the CRC32 checksum for PNG chunk data.
This function can accept either raw bytes or a chunk object containing type and data fields. When given a chunk object, it concatenates the type and data fields before calculating the CRC.
Calculating CRC for raw bytes
Calculating CRC for raw bytes
import { assertEquals } from "@std/assert"; import { chunkCrc } from "@binstruct/png"; const data = new Uint8Array([73, 72, 68, 82, 0, 0, 0, 1, 0, 0, 0, 1, 8, 2, 0, 0, 0]); const crc = chunkCrc(data); assertEquals(typeof crc, "number"); assertEquals(crc >= 0, true);
Calculating CRC for chunk object
Calculating CRC for chunk object
import { assertEquals } from "@std/assert"; import { chunkCrc } from "@binstruct/png"; const chunk = { type: new Uint8Array([73, 72, 68, 82]), // "IHDR" data: new Uint8Array([0, 0, 0, 1, 0, 0, 0, 1, 8, 2, 0, 0, 0]), }; const crc = chunkCrc(chunk); assertEquals(typeof crc, "number"); assertEquals(crc >= 0, true);
bytes: Uint8Array
chunkCrc(chunk: { type: Uint8Array; data: Uint8Array; }): number
chunk: { type: Uint8Array; data: Uint8Array; }