Skip to content

Commit a10569c

Browse files
Add support for CAD DWG format.
1 parent 4ae3509 commit a10569c

File tree

6 files changed

+38
-2
lines changed

6 files changed

+38
-2
lines changed

internal/matchers/image.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,35 @@ func Tiff(in []byte) bool {
5959
func Bpg(in []byte) bool {
6060
return bytes.HasPrefix(in, []byte{0x42, 0x50, 0x47, 0xFB})
6161
}
62+
63+
// Dwg matches a CAD drawing file.
64+
func Dwg(in []byte) bool {
65+
if in[0] != 0x41 || in[1] != 0x43 || len(in) < 6 {
66+
return false
67+
}
68+
dwgVersions := [][]byte{
69+
{0x31, 0x2E, 0x34, 0x30},
70+
{0x31, 0x2E, 0x35, 0x30},
71+
{0x32, 0x2E, 0x31, 0x30},
72+
{0x31, 0x30, 0x30, 0x32},
73+
{0x31, 0x30, 0x30, 0x33},
74+
{0x31, 0x30, 0x30, 0x34},
75+
{0x31, 0x30, 0x30, 0x36},
76+
{0x31, 0x30, 0x30, 0x39},
77+
{0x31, 0x30, 0x31, 0x32},
78+
{0x31, 0x30, 0x31, 0x34},
79+
{0x31, 0x30, 0x31, 0x35},
80+
{0x31, 0x30, 0x31, 0x38},
81+
{0x31, 0x30, 0x32, 0x31},
82+
{0x31, 0x30, 0x32, 0x34},
83+
{0x31, 0x30, 0x33, 0x32},
84+
}
85+
86+
for _, d := range dwgVersions {
87+
if bytes.Equal(in[2:6], d) {
88+
return true
89+
}
90+
}
91+
92+
return false
93+
}

mime_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ var files = map[string]*node{
135135
"dbf.dbf": dbf,
136136

137137
"sqlite3.sqlite3": sqlite3,
138+
"dwg.dwg": dwg,
139+
"dwg.1.dwg": dwg,
138140
}
139141

140142
func TestMatching(t *testing.T) {

supported_mimes.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## 104 Supported MIME types
1+
## 105 Supported MIME types
22
This file is automatically generated when running tests. Do not edit manually.
33

44
Extension | MIME type
@@ -107,3 +107,4 @@ Extension | MIME type
107107
**lit** | application/x-ms-reader
108108
**bpg** | image/bpg
109109
**sqlite** | application/x-sqlite3
110+
**dwg** | image/vnd.dwg

testdata/dwg.1.dwg

57.1 KB
Binary file not shown.

testdata/dwg.dwg

540 KB
Binary file not shown.

tree.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var root = newNode("application/octet-stream", "", matchers.True,
1010
ar, tar, xar, bz2, fits, tiff, bmp, ico, mp3, flac, midi, ape, musePack, amr,
1111
wav, aiff, au, mpeg, quickTime, mqv, mp4, webM, threeGP, threeG2, avi, flv,
1212
mkv, asf, aMp4, m4a, txt, gzip, class, swf, crx, woff, woff2, wasm, shx, dbf,
13-
dcm, rar, djvu, mobi, lit, bpg, sqlite3,
13+
dcm, rar, djvu, mobi, lit, bpg, sqlite3, dwg,
1414
)
1515

1616
// The list of nodes appended to the root node
@@ -118,4 +118,5 @@ var (
118118
mobi = newNode("application/x-mobipocket-ebook", "mobi", matchers.Mobi)
119119
lit = newNode("application/x-ms-reader", "lit", matchers.Lit)
120120
sqlite3 = newNode("application/x-sqlite3", "sqlite", matchers.Sqlite)
121+
dwg = newNode("image/vnd.dwg", "dwg", matchers.Dwg)
121122
)

0 commit comments

Comments
 (0)