Skip to content

Commit

Permalink
Add support for AutoDesk DWG format (#572)
Browse files Browse the repository at this point in the history
  • Loading branch information
Borewit authored Jan 11, 2023
1 parent ec3ba33 commit 47aa221
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 3 deletions.
6 changes: 4 additions & 2 deletions core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ export type FileExtension =
| 'jxl'
| 'vcf'
| 'jls'
| 'pst';
| 'pst'
| 'dwg';

export type MimeType =
| 'image/jpeg'
Expand Down Expand Up @@ -280,7 +281,8 @@ export type MimeType =
| 'image/jxl'
| 'application/zstd'
| 'image/jls'
| 'application/vnd.ms-outlook';
| 'application/vnd.ms-outlook'
| 'image/vnd.dwg';

export type FileTypeResult = {
/**
Expand Down
10 changes: 10 additions & 0 deletions core.js
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,16 @@ class FileTypeParser {
};
}

if (this.checkString('AC')) {
const version = this.buffer.toString('binary', 2, 6);
if (version.match('^d*') && version >= 1000 && version <= 1050) {
return {
ext: 'dwg',
mime: 'image/vnd.dwg',
};
}
}

// -- 7-byte signatures --

if (this.checkString('BLENDER')) {
Expand Down
Binary file added fixture/fixture-line-weights.dwg
Binary file not shown.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@
"jxl",
"vcf",
"jls",
"pst"
"pst",
"dwg"
],
"dependencies": {
"readable-web-to-node-stream": "^3.0.2",
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ Returns a `Set<string>` of supported MIME types.
- [`dng`](https://en.wikipedia.org/wiki/Digital_Negative) - Adobe Digital Negative image file
- [`docx`](https://en.wikipedia.org/wiki/Office_Open_XML) - Microsoft Word
- [`dsf`](https://dsd-guide.com/sites/default/files/white-papers/DSFFileFormatSpec_E.pdf) - Sony DSD Stream File (DSF)
- [`dwg`](https://en.wikipedia.org/wiki/.dwg) - Autodesk CAD file
- [`elf`](https://en.wikipedia.org/wiki/Executable_and_Linkable_Format) - Unix Executable and Linkable Format
- [`eot`](https://en.wikipedia.org/wiki/Embedded_OpenType) - Embedded OpenType font
- [`eps`](https://en.wikipedia.org/wiki/Encapsulated_PostScript) - Encapsulated PostScript
Expand Down
2 changes: 2 additions & 0 deletions supported.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export const extensions = [
'vcf',
'jls',
'pst',
'dwg',
];

export const mimeTypes = [
Expand Down Expand Up @@ -279,4 +280,5 @@ export const mimeTypes = [
'application/zstd',
'image/jls',
'application/vnd.ms-outlook',
'image/vnd.dwg',
];
3 changes: 3 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ const names = {
pst: [
'fixture-sample',
],
dwg: [
'fixture-line-weights',
],
};

// Define an entry here only if the file type has potential
Expand Down

0 comments on commit 47aa221

Please sign in to comment.