View Source MimeSniff.Signatures.MaskedSignature (mime_sniff v0.1.1)
It represent the signature in MIME sniff
table that all bytes in Pattern Mask
are not FF Leading Bytes to Be Ignored
is None.
e.g., For webp type
- Byte Pattern: 52 49 46 46 00 00 00 00 57 45 42 50 56 50
- Pattern Mask: FF FF FF FF 00 00 00 00 FF FF FF FF FF FF
- Leading Bytes to Be Ignored: None.
- Image MIME Type: image/webp
can be represent as
%MaskedSignature{
byte_pattern: <<0x52, 0x49, 0x46, 0x46, 0x00, 0x00, 0x00, 0x00, 0x57, 0x45, 0x42, 0x50, 0x56, 0x50>>,
pattern_mask: <<0xFF ,0xFF ,0xFF ,0xFF ,0x00 ,0x00 ,0x00 ,0x00 ,0xFF ,0xFF ,0xFF ,0xFF ,0xFF ,0xFF>>,
mime_type: "image/webp"
}
The MaskedSignature 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.MaskedSignature
webp_sig = %MaskedSignature{
byte_pattern: <<0x52, 0x49, 0x46, 0x46, 0x00, 0x00, 0x00, 0x00, 0x57, 0x45, 0x42, 0x50, 0x56, 0x50>>,
pattern_mask: <<0xFF ,0xFF ,0xFF ,0xFF ,0x00 ,0x00 ,0x00 ,0x00 ,0xFF ,0xFF ,0xFF ,0xFF ,0xFF ,0xFF>>,
mime_type: "image/webp"
}
# webp signature is "The string 'RIFF' followed by four bytes followed by the string 'WEBPVP'"
test_data = "RIFFdataWEBPVPdata"
Signature.match(webp_sig, test_data) # {:ok, "image/webp"}