Skip to content

Commit

Permalink
Add support for CR3 (#292)
Browse files Browse the repository at this point in the history
Co-authored-by: LuttyYang <[email protected]>
  • Loading branch information
2 people authored and sindresorhus committed Jan 7, 2020
1 parent 4210ddb commit 204599a
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 16 deletions.
2 changes: 2 additions & 0 deletions core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ declare namespace core {
| 'webp'
| 'flif'
| 'cr2'
| 'cr3'
| 'orf'
| 'arw'
| 'dng'
Expand Down Expand Up @@ -132,6 +133,7 @@ declare namespace core {
| 'image/webp'
| 'image/flif'
| 'image/x-canon-cr2'
| 'image/x-canon-cr3'
| 'image/tiff'
| 'image/bmp'
| 'image/vnd.ms-photo'
Expand Down
26 changes: 10 additions & 16 deletions core.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@ async function fromTokenizer(tokenizer) {
return {ext: 'f4a', mime: 'audio/mp4'};
case 'F4B':
return {ext: 'f4b', mime: 'audio/mp4'};
case 'crx':
return {ext: 'cr3', mime: 'image/x-canon-cr3'};
default:
if (brandMajor.startsWith('3g')) {
if (brandMajor.startsWith('3g2')) {
Expand Down Expand Up @@ -538,23 +540,15 @@ async function fromTokenizer(tokenizer) {
};
}

// `cr2`, `orf`, and `arw` need to be before `tif` check
if (
(check([0x49, 0x49, 0x2A, 0x0]) || check([0x4D, 0x4D, 0x0, 0x2A])) &&
check([0x43, 0x52], {offset: 8})
) {
return {
ext: 'cr2',
mime: 'image/x-canon-cr2'
};
}
if (check([0x49, 0x49, 0x2A, 0x0] || [0x4D, 0x4D, 0x0, 0x2A])) {
if (checkString('CR', {offset: 8})) {
return {
ext: 'cr2',
mime: 'image/x-canon-cr2'
};
}

if (
check([0x49, 0x49, 0x2A, 0x0])
) {
if (
check([0x1C, 0x00, 0xFE, 0x00], {offset: 8})
) {
if (check([0x1C, 0x00, 0xFE, 0x00], {offset: 8})) {
return {
ext: 'nef',
mime: 'image/x-nikon-nef'
Expand Down
Binary file added fixture/fixture.cr3
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"webp",
"flif",
"cr2",
"cr3",
"orf",
"arw",
"dng",
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ Returns a set of supported MIME types.
- [`webp`](https://en.wikipedia.org/wiki/WebP)
- [`flif`](https://en.wikipedia.org/wiki/Free_Lossless_Image_Format)
- [`cr2`](https://fileinfo.com/extension/cr2) - Canon Raw image file (v2)
- [`cr3`](https://fileinfo.com/extension/cr3) - Canon Raw image file (v3)
- [`orf`](https://en.wikipedia.org/wiki/ORF_format) - Olympus Raw image file
- [`arw`](https://en.wikipedia.org/wiki/Raw_image_format#ARW) - Sony Alpha Raw image file
- [`dng`](https://en.wikipedia.org/wiki/Digital_Negative) - Adobe Digital Negative image file
Expand Down
2 changes: 2 additions & 0 deletions supported.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = {
'webp',
'flif',
'cr2',
'cr3',
'orf',
'arw',
'dng',
Expand Down Expand Up @@ -130,6 +131,7 @@ module.exports = {
'image/webp',
'image/flif',
'image/x-canon-cr2',
'image/x-canon-cr3',
'image/tiff',
'image/bmp',
'image/vnd.ms-photo',
Expand Down
3 changes: 3 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ const names = {
'fixture4',
'fixture5'
],
cr3: [
'fixture'
],
dng: [
'fixture',
'fixture2'
Expand Down

0 comments on commit 204599a

Please sign in to comment.