Skip to content

Commit

Permalink
Add support for CAD DWG format.
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-vasile committed May 28, 2019
1 parent 4ae3509 commit a10569c
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 2 deletions.
32 changes: 32 additions & 0 deletions internal/matchers/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,35 @@ func Tiff(in []byte) bool {
func Bpg(in []byte) bool {
return bytes.HasPrefix(in, []byte{0x42, 0x50, 0x47, 0xFB})
}

// Dwg matches a CAD drawing file.
func Dwg(in []byte) bool {
if in[0] != 0x41 || in[1] != 0x43 || len(in) < 6 {
return false
}
dwgVersions := [][]byte{
{0x31, 0x2E, 0x34, 0x30},
{0x31, 0x2E, 0x35, 0x30},
{0x32, 0x2E, 0x31, 0x30},
{0x31, 0x30, 0x30, 0x32},
{0x31, 0x30, 0x30, 0x33},
{0x31, 0x30, 0x30, 0x34},
{0x31, 0x30, 0x30, 0x36},
{0x31, 0x30, 0x30, 0x39},
{0x31, 0x30, 0x31, 0x32},
{0x31, 0x30, 0x31, 0x34},
{0x31, 0x30, 0x31, 0x35},
{0x31, 0x30, 0x31, 0x38},
{0x31, 0x30, 0x32, 0x31},
{0x31, 0x30, 0x32, 0x34},
{0x31, 0x30, 0x33, 0x32},
}

for _, d := range dwgVersions {
if bytes.Equal(in[2:6], d) {
return true
}
}

return false
}
2 changes: 2 additions & 0 deletions mime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ var files = map[string]*node{
"dbf.dbf": dbf,

"sqlite3.sqlite3": sqlite3,
"dwg.dwg": dwg,
"dwg.1.dwg": dwg,
}

func TestMatching(t *testing.T) {
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 @@
## 104 Supported MIME types
## 105 Supported MIME types
This file is automatically generated when running tests. Do not edit manually.

Extension | MIME type
Expand Down Expand Up @@ -107,3 +107,4 @@ Extension | MIME type
**lit** | application/x-ms-reader
**bpg** | image/bpg
**sqlite** | application/x-sqlite3
**dwg** | image/vnd.dwg
Binary file added testdata/dwg.1.dwg
Binary file not shown.
Binary file added testdata/dwg.dwg
Binary file not shown.
3 changes: 2 additions & 1 deletion tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var root = newNode("application/octet-stream", "", matchers.True,
ar, tar, xar, bz2, fits, tiff, bmp, ico, mp3, flac, midi, ape, musePack, amr,
wav, aiff, au, mpeg, quickTime, mqv, mp4, webM, threeGP, threeG2, avi, flv,
mkv, asf, aMp4, m4a, txt, gzip, class, swf, crx, woff, woff2, wasm, shx, dbf,
dcm, rar, djvu, mobi, lit, bpg, sqlite3,
dcm, rar, djvu, mobi, lit, bpg, sqlite3, dwg,
)

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

0 comments on commit a10569c

Please sign in to comment.