Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/pippo/mimetype into pippo…
Browse files Browse the repository at this point in the history
…-master
  • Loading branch information
gabriel-vasile committed Oct 27, 2019
2 parents 9961812 + d908678 commit d2922e7
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
27 changes: 27 additions & 0 deletions internal/matchers/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,30 @@ func Dcm(in []byte) bool {
func Nes(in []byte) bool {
return bytes.HasPrefix(in, []byte{0x4E, 0x45, 0x53, 0x1A})
}

// Marc matches a MARC21 (MAchine-Readable Cataloging) file.
func Marc(in []byte) bool {
// File is at least 24 bytes ("leader" field size)
if len(in) < 24 {
return false
}

// Fixed bytes at offset 20
if !bytes.Equal(in[20:24], []byte("4500")) {
return false
}

// First 5 bytes are ASCII digits
for i := 0; i < 5; i++ {
if in[i] < '0' || in[i] > '9' {
return false
}
}

// Field terminator is present
if !bytes.Contains(in, []byte{0x1E}) {
return false
}

return true
}
1 change: 1 addition & 0 deletions mime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ var files = map[string]*node{
"mach.o": macho,
"sample32": macho,
"sample64": macho,
"mrc.mrc": mrc,

// fonts
"woff.woff": woff,
Expand Down
3 changes: 2 additions & 1 deletion supported_mimes.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 131 Supported MIME types
## 132 Supported MIME types
This file is automatically generated when running tests. Do not edit manually.

Extension | MIME type
Expand Down Expand Up @@ -134,3 +134,4 @@ Extension | MIME type
**.heic** | image/heic-sequence
**.heif** | image/heif
**.heif** | image/heif-sequence
**mrc** | application/marc
1 change: 1 addition & 0 deletions testdata/mrc.mrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
00057 2200037 450024500190000001aTest MARC file
3 changes: 2 additions & 1 deletion tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var root = newNode("application/octet-stream", "", matchers.True,
wav, aiff, au, mpeg, quickTime, mqv, mp4, webM, threeGP, threeG2, avi, flv,
mkv, asf, aac, voc, aMp4, m4a, txt, gzip, class, swf, crx, woff, woff2, otf,
eot, wasm, shx, dbf, dcm, rar, djvu, mobi, lit, bpg, sqlite3, dwg, nes, macho,
qcp, icns, heic, heicSeq, heif, heifSeq,
qcp, icns, heic, heicSeq, heif, heifSeq, mrc,
)

// The list of nodes appended to the root node
Expand Down Expand Up @@ -146,4 +146,5 @@ var (
nes = newNode("application/vnd.nintendo.snes.rom", "nes", matchers.Nes)
macho = newNode("application/x-mach-binary", "macho", matchers.MachO)
qcp = newNode("audio/qcelp", "qcp", matchers.Qcp)
mrc = newNode("application/marc", "mrc", matchers.Marc)
)

0 comments on commit d2922e7

Please sign in to comment.