Skip to content

Commit

Permalink
Merge 7e437d6 into c4c6791
Browse files Browse the repository at this point in the history
  • Loading branch information
vansante committed Jun 10, 2021
2 parents c4c6791 + 7e437d6 commit fff1c3b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
8 changes: 8 additions & 0 deletions internal/magic/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ var (
Xpm = prefix([]byte{0x2F, 0x2A, 0x20, 0x58, 0x50, 0x4D, 0x20, 0x2A, 0x2F})
)

func Avif(raw []byte, limit uint32) bool {
if len(raw) < 24 {
return false
}
return bytes.Equal(raw[4:8], []byte("ftyp")) &&
bytes.Equal(raw[20:24], []byte("avif"))
}

func jpeg2k(sig []byte) Detector {
return func(raw []byte, _ uint32) bool {
if len(raw) < 24 {
Expand Down
1 change: 1 addition & 0 deletions mimetype_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var files = map[string]string{
"atom.atom": "application/atom+xml",
"au.au": "audio/basic",
"avi.avi": "video/x-msvideo",
"avif.avif": "image/avif",
"bmp.bmp": "image/bmp",
"bpg.bpg": "image/bpg",
"bz2.bz2": "application/x-bzip2",
Expand Down
Binary file added testdata/avif.avif
Binary file not shown.
3 changes: 2 additions & 1 deletion tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var root = newMIME("application/octet-stream", "",
midi, ape, musePack, amr, wav, aiff, au, mpeg, quickTime, mqv, mp4, webM,
threeGP, threeG2, avi, flv, mkv, asf, aac, voc, aMp4, m4a, m3u, m4v, rmvb,
gzip, class, swf, crx, ttf, woff, woff2, otf, eot, wasm, shx, dbf, dcm, rar,
djvu, mobi, lit, bpg, sqlite3, dwg, nes, lnk, macho, qcp, icns, heic,
djvu, mobi, lit, bpg, sqlite3, dwg, nes, lnk, macho, qcp, icns, avif, heic,
heicSeq, heif, heifSeq, hdr, mrc, mdb, accdb, zstd, cab, rpm, xz, lzip,
torrent, cpio, tzif, xcf, pat, gbr, glb,
// Keep text last because it is the slowest check
Expand Down Expand Up @@ -115,6 +115,7 @@ var (
icns = newMIME("image/x-icns", ".icns", magic.Icns)
psd = newMIME("image/vnd.adobe.photoshop", ".psd", magic.Psd).
alias("image/x-psd", "application/photoshop")
avif = newMIME("image/avif", ".avif", magic.Avif)
heic = newMIME("image/heic", ".heic", magic.Heic)
heicSeq = newMIME("image/heic-sequence", ".heic", magic.HeicSequence)
heif = newMIME("image/heif", ".heif", magic.Heif)
Expand Down

0 comments on commit fff1c3b

Please sign in to comment.