Repository: gabriel-vasile/mimetype (go)

Issue:
pzstd file is not detected as zstd
**Attach the file for which the detection is inaccurate**
[test.zip](https://github.com/user-attachments/files/18141160/test.zip)
test.txt.zst uses zstd
test2.txt.zst uses pzstd

**Expected MIME type**
`application/zstd`

**Returned MIME type**
`application/octet-stream`

**Version of the library you are using**
`v1.4.7`

**Output of `go version`**
`go version go1.23.4 linux/amd64`

**Additional context**
https://github.com/facebook/zstd
Files created using pzstd are not detection correctly, if use `file` command both will be detected as `application/zstd`

Pull request description:
zstd: check for skippable frames as well; fix #619
Previous detection was not working for skippable frames: https://github.com/facebook/zstd/blob/dev/doc/zstd_compression_format.md#skippable-frames

Patch:
diff --git a/internal/magic/archive.go b/internal/magic/archive.go
index b59042c..068d00f 100644
--- a/internal/magic/archive.go
+++ b/internal/magic/archive.go
@@ -52,10 +52,15 @@ func InstallShieldCab(raw []byte, _ uint32) bool {
 }
 
 // Zstd matches a Zstandard archive file.
+// https://github.com/facebook/zstd/blob/dev/doc/zstd_compression_format.md
 func Zstd(raw []byte, limit uint32) bool {
-	return len(raw) >= 4 &&
-		(0x22 <= raw[0] && raw[0] <= 0x28 || raw[0] == 0x1E) && // Different Zstandard versions.
-		bytes.HasPrefix(raw[1:], []byte{0xB5, 0x2F, 0xFD})
+	if len(raw) < 4 {
+		return false
+	}
+	sig := binary.LittleEndian.Uint32(raw)
+	// Check for Zstandard frames and skippable frames.
+	return (sig >= 0xFD2FB522 && sig <= 0xFD2FB528) ||
+		(sig >= 0x184D2A50 && sig <= 0x184D2A5F)
 }
 
 // CRX matches a Chrome extension file: a zip archive prepended by a package header.


Test patch:
diff --git a/mimetype_test.go b/mimetype_test.go
index 75d777f..32a26a2 100644
--- a/mimetype_test.go
+++ b/mimetype_test.go
@@ -262,6 +262,7 @@ var testcases = []testcase{
 	{"xz", "\xfd7zXZ\x00", "application/x-xz", true},
 	{"zip", "PK\x03\x04", "application/zip", true},
 	{"zst", "(\xb5/\xfd", "application/zstd", true},
+	{"zst skippable frame", "\x50\x2A\x4D\x18", "application/zstd", false},
 }
 
 func TestDetect(t *testing.T) {