View Source MimeSniff.Signatures.ExactSignature (mime_sniff v0.1.1)

It represent the signature in MIME sniff table that all bytes in Pattern Mask are FF.

e.g., For PNG type

  • Byte Pattern: 89 50 4E 47 0D 0A 1A 0A
  • Pattern Mask: FF FF FF FF FF FF FF FF
  • Leading Bytes to Be Ignored: None.
  • Image MIME Type: image/png

can be represent as

%ExactSignature{
  byte_pattern: <<0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A>>,
  ignored_ws_leading_bytes: false,
  mime_type: "image/png"
}

The ExactSignature struct implement MimeSniff.Signatures.Signature protocol, so it can be use with to do MIME sniffing

examples

Examples

alias MimeSniff.Signatures.Signature
alias MimeSniff.Signatures.ExactSignature

png_sig = %ExactSignature{
  byte_pattern: <<0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A>>,
  ignored_ws_leading_bytes: false,
  mime_type: "image/png"
}

# png signature is "An error-checking byte followed by the string 'PNG' followed by CR LF SUB LF, the PNG signature"
test_data = <<137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13>> # data strip from png file

Signature.match(png_sig, test_data) # {:ok, "image/png"}

Link to this section Summary

Link to this section Types

@type t() :: %MimeSniff.Signatures.ExactSignature{
  byte_pattern: binary(),
  ignored_ws_leading_bytes: boolean(),
  mime_type: String.t()
}