Delegate SignatureMatcher
Returns whether the first bytes of a file belong to a format.
public delegate bool SignatureMatcher(ReadOnlySpan<byte> header)
Parameters
headerReadOnlySpan<byte>The first bytes of the data, up to the longest SignatureLength of all registered formats. It is shorter only if the data itself is shorter.
Returns
Examples
// Every built-in format, with its name, extensions and MIME types; Raster.Save picks one by extension.
foreach (FormatInfo format in new[] { PngFormat.Info, JpegFormat.Info, GifFormat.Info, BmpFormat.Info, TgaFormat.Info, QoiFormat.Info, PnmFormat.Info })
{
Console.WriteLine($"{format.Name}: {string.Join(", ", format.Extensions)} ({string.Join(", ", format.MimeTypes)})");
}
// A SignatureMatcher decides from the first SignatureLength bytes whether a file is in the format.
SignatureMatcher isPng = PngFormat.Info.Matches;
bool png = isPng(File.ReadAllBytes("duck.png").AsSpan(0, PngFormat.Info.SignatureLength));