Skip to content

Commit

Permalink
Merge pull request #75 from QwertygidQ/master
Browse files Browse the repository at this point in the history
Added Zstandard support
  • Loading branch information
gabriel-vasile authored Nov 27, 2019
2 parents 51f7646 + 2236a0a commit 22c2461
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 2 deletions.
7 changes: 7 additions & 0 deletions internal/matchers/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,10 @@ func Rar(in []byte) bool {
func Warc(in []byte) bool {
return bytes.HasPrefix(in, []byte("WARC/"))
}

// Zstd matches a Zstandard archive file.
func Zstd(in []byte) bool {
return len(in) >= 4 &&
(0x22 <= in[0] && in[0] <= 0x28 || in[0] == 0x1E) && // Different Zstandard versions.
bytes.HasPrefix(in[1:], []byte{0xB5, 0x2F, 0xFD})
}
1 change: 1 addition & 0 deletions mime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ var files = map[string]*node{
"mobi.mobi": mobi,
"lit.lit": lit,
"warc.warc": warc,
"zst.zst": zstd,

// images
"png.png": png,
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 @@
## 135 Supported MIME types
## 136 Supported MIME types
This file is automatically generated when running tests. Do not edit manually.

Extension | MIME type
Expand Down Expand Up @@ -138,3 +138,4 @@ Extension | MIME type
**mrc** | application/marc
**mdb** | application/x-msaccess
**accdb** | application/x-msaccess
**zst** | application/zstd
Binary file added testdata/zst.zst
Binary file not shown.
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, mrc, mdb, accdb,
qcp, icns, heic, heicSeq, heif, heifSeq, mrc, mdb, accdb, zstd,
)

// The list of nodes appended to the root node
Expand Down Expand Up @@ -150,4 +150,5 @@ var (
mrc = newNode("application/marc", "mrc", matchers.Marc)
mdb = newNode("application/x-msaccess", "mdb", matchers.MsAccessMdb)
accdb = newNode("application/x-msaccess", "accdb", matchers.MsAccessAce)
zstd = newNode("application/zstd", "zst", matchers.Zstd)
)

0 comments on commit 22c2461

Please sign in to comment.