Skip to content

Commit

Permalink
Add support for Encapsulated PostScript (EPS) (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
beaulac authored May 4, 2020
1 parent 9623ab5 commit 070c4c1
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 3 deletions.
4 changes: 3 additions & 1 deletion core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ declare namespace core {
| 'xm'
| 'ai'
| 'skp'
| 'avif';
| 'avif'
| 'eps';

type MimeType =
| 'image/jpeg'
Expand Down Expand Up @@ -195,6 +196,7 @@ declare namespace core {
| 'image/x-icon'
| 'video/x-flv'
| 'application/postscript'
| 'application/eps'
| 'application/x-xz'
| 'application/x-sqlite3'
| 'application/x-nintendo-nes-rom'
Expand Down
17 changes: 17 additions & 0 deletions core.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@ async function _fromTokenizer(tokenizer) {
}

if (check([0x25, 0x21])) {
await tokenizer.peekBuffer(buffer, {length: 24, mayBeLess: true});

if (checkString('PS-Adobe-', {offset: 2}) &&
checkString(' EPSF-', {offset: 14})) {
return {
ext: 'eps',
mime: 'application/eps'
};
}

return {
ext: 'ps',
mime: 'application/postscript'
Expand Down Expand Up @@ -768,6 +778,13 @@ async function _fromTokenizer(tokenizer) {
};
}

if (check([0xC5, 0xD0, 0xD3, 0xC6])) {
return {
ext: 'eps',
mime: 'application/eps'
};
}

// -- 5-byte signatures --

if (check([0x4F, 0x54, 0x54, 0x4F, 0x00])) {
Expand Down
Binary file added fixture/fixture.eps
Binary file not shown.
1 change: 1 addition & 0 deletions fixture/fixture2.eps

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@
"xm",
"ai",
"skp",
"avif"
"avif",
"eps"
],
"devDependencies": {
"@types/node": "^13.1.4",
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ Returns a set of supported MIME types.
- [`ai`](https://en.wikipedia.org/wiki/Adobe_Illustrator_Artwork) - Adobe Illustrator Artwork
- [`skp`](https://en.wikipedia.org/wiki/SketchUp) - SketchUp
- [`avif`](https://en.wikipedia.org/wiki/AV1#AV1_Image_File_Format_(AVIF)) - AV1 Image File Format
- [`eps`](https://en.wikipedia.org/wiki/Encapsulated_PostScript) - Encapsulated PostScript

*Pull requests are welcome for additional commonly used file types.*

Expand Down
4 changes: 3 additions & 1 deletion supported.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ module.exports = {
'xm',
'ai',
'skp',
'avif'
'avif',
'eps'
],
mimeTypes: [
'image/jpeg',
Expand Down Expand Up @@ -194,6 +195,7 @@ module.exports = {
'image/x-icon',
'video/x-flv',
'application/postscript',
'application/eps',
'application/x-xz',
'application/x-sqlite3',
'application/x-nintendo-nes-rom',
Expand Down
4 changes: 4 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ const names = {
],
avif: [
'fixture-yuv420-8bit' // Multiple bit-depths and/or subsamplings
],
eps: [
'fixture',
'fixture2'
]
};

Expand Down

0 comments on commit 070c4c1

Please sign in to comment.