function chunkCrc
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.

Examples

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

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);

Parameters

Return Type

number

The CRC32 checksum as a number

chunkCrc(chunk: { type: Uint8Array; data: Uint8Array; }): number

Parameters

chunk: { type: Uint8Array; data: Uint8Array; }

Return Type

number