Skip to content

Commit

Permalink
Add zstd support
Browse files Browse the repository at this point in the history
This adds support for detecting zstd compressed files
https://en.wikipedia.org/wiki/Zstandard
  • Loading branch information
cfergeau committed Feb 1, 2021
1 parent 54ff48f commit fd9b18e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ func main() {
- **bz2** - `application/x-bzip2`
- **7z** - `application/x-7z-compressed`
- **xz** - `application/x-xz`
- **zstd** - `application/zstd`
- **pdf** - `application/pdf`
- **exe** - `application/vnd.microsoft.portable-executable`
- **swf** - `application/x-shockwave-flash`
Expand Down
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
7 changes: 5 additions & 2 deletions matchers/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,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 +40,7 @@ var Archive = Map{
TypeBz2: bytePrefixMatcher(bz2Magic),
Type7z: bytePrefixMatcher(sevenzMagic),
TypeXz: bytePrefixMatcher(xzMagic),
TypeZstd: bytePrefixMatcher(zstdMagic),
TypePdf: bytePrefixMatcher(pdfMagic),
TypeExe: bytePrefixMatcher(exeMagic),
TypeSwf: Swf,
Expand Down Expand Up @@ -83,8 +85,9 @@ var (
0x64, 0x65, 0x62, 0x69, 0x61, 0x6E, 0x2D, 0x62,
0x69, 0x6E, 0x61, 0x72, 0x79,
}
arMagic = []byte{0x21, 0x3C, 0x61, 0x72, 0x63, 0x68, 0x3E}
lzMagic = []byte{0x4C, 0x5A, 0x49, 0x50}
arMagic = []byte{0x21, 0x3C, 0x61, 0x72, 0x63, 0x68, 0x3E}
zstdMagic = []byte{0x28, 0xB5, 0x2F, 0xFD}
lzMagic = []byte{0x4C, 0x5A, 0x49, 0x50}
)

func bytePrefixMatcher(magicPattern []byte) Matcher {
Expand Down

0 comments on commit fd9b18e

Please sign in to comment.