import { crc32 } from 'crc';

export async function computeCRC32Base64(file: File): Promise<string> {
  const arrayBuffer = await file.arrayBuffer();

  // Pass arrayBuffer directly to crc32
  let crc = crc32(arrayBuffer);
  crc >>>= 0;

  // Convert to 4-byte big-endian
  const buffer = new ArrayBuffer(4);
  const view = new DataView(buffer);
  view.setUint32(0, crc, false);

  // Base64 encode
  return btoa(String.fromCharCode(...new Uint8Array(buffer)));
}
