omni-compress - v2.3.1
    Preparing search index...

    Function detectFormat

    • Detects the media format of a file from its magic bytes (file signature).

      Returns a lowercase format string (e.g. 'webp', 'mp3') or null if the signature is not recognised. Requires at least 12 bytes.

      Use this to validate that a file's actual content matches its extension, or to detect the format when the extension is missing or untrusted.

      Supported: jpeg, png, gif, webp, avif, mp3, wav, flac, ogg, aac

      Parameters

      • buffer: ArrayBuffer

      Returns string | null

      const buffer = await file.arrayBuffer();
      const format = detectFormat(buffer); // e.g. 'webp'