Skip to content

Commit

Permalink
Add zstd support
Browse files Browse the repository at this point in the history
  • Loading branch information
cfergeau committed Jan 28, 2021
1 parent dc27b90 commit a3ad0ec
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
Binary file added fixtures/sample.zst
Binary file not shown.
1 change: 1 addition & 0 deletions match_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func TestMatchFile(t *testing.T) {
{"mov"},
{"wasm"},
{"dwg"},
{"zst"},
}

for _, test := range cases {
Expand Down
11 changes: 11 additions & 0 deletions matchers/archive.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package matchers

import "bytes"

var (
TypeEpub = newType("epub", "application/epub+zip")
TypeZip = newType("zip", "application/zip")
Expand All @@ -9,6 +11,7 @@ var (
TypeBz2 = newType("bz2", "application/x-bzip2")
Type7z = newType("7z", "application/x-7z-compressed")
TypeXz = newType("xz", "application/x-xz")
TypeZstd = newType("zst", "application/zstd")
TypePdf = newType("pdf", "application/pdf")
TypeExe = newType("exe", "application/vnd.microsoft.portable-executable")
TypeSwf = newType("swf", "application/x-shockwave-flash")
Expand Down Expand Up @@ -39,6 +42,7 @@ var Archive = Map{
TypeBz2: Bz2,
Type7z: SevenZ,
TypeXz: Xz,
TypeZstd: Zstd,
TypePdf: Pdf,
TypeExe: Exe,
TypeSwf: Swf,
Expand Down Expand Up @@ -244,3 +248,10 @@ func MachO(buf []byte) bool {
(buf[0] == 0xCE && buf[1] == 0xFA && buf[2] == 0xED && buf[3] == 0xFE) ||
(buf[0] == 0xCA && buf[1] == 0xFE && buf[2] == 0xBA && buf[3] == 0xBE))
}

func Zstd(data []byte) bool {
/* magic value from shared-mime-info */
var zstdMagic = []byte{0x28, 0xB5, 0x2F, 0xFD}

return bytes.HasPrefix(data, zstdMagic)
}

0 comments on commit a3ad0ec

Please sign in to comment.