From 050fb09e57c825b57919b59934c070162fb8931c Mon Sep 17 00:00:00 2001 From: Matthew McEachen Date: Tue, 11 Jun 2019 09:33:46 -0700 Subject: [PATCH 1/2] Add more RAW image fixtures and more detection patterns. Fixes #219. --- fixture/fixture.tif | Bin 0 -> 128 bytes fixture/fixture2.arw | Bin 0 -> 128 bytes fixture/fixture2.dng | Bin 0 -> 128 bytes fixture/fixture2.nef | Bin 0 -> 128 bytes fixture/fixture3.arw | Bin 0 -> 128 bytes fixture/fixture3.nef | Bin 0 -> 128 bytes fixture/fixture4.arw | Bin 0 -> 128 bytes index.js | 16 +++++++++++++--- test.js | 14 ++++++++++++++ 9 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 fixture/fixture.tif create mode 100644 fixture/fixture2.arw create mode 100644 fixture/fixture2.dng create mode 100644 fixture/fixture2.nef create mode 100644 fixture/fixture3.arw create mode 100644 fixture/fixture3.nef create mode 100644 fixture/fixture4.arw diff --git a/fixture/fixture.tif b/fixture/fixture.tif new file mode 100644 index 0000000000000000000000000000000000000000..52404e667c9a54ea28f5438673ab7834d6a8ad73 GIT binary patch literal 128 zcmV-`0Du2UNh$!yMgRc+|357a2Z7Tp6U>I-5FB#BAr~BSxd^(ucJ)Gz!-dR`40oA0 z%#1FArGFRtMNsj>3{aGwu(Z0wfVKU2f(`C_;R(xeKTI6fM#>M*IoRfM*Z_{YG)zzAf4Faslmy#U07vMYdWCProkW+43tsE8TJhN)+RvYCK# h{ESQtazOeOP*MQM76G!kfD(dGa~@PNF$lr+0s!W32Jip? literal 0 HcmV?d00001 diff --git a/fixture/fixture2.nef b/fixture/fixture2.nef new file mode 100644 index 0000000000000000000000000000000000000000..dcbc88ff9b9a7d580a286bd8f15644b3e925fd51 GIT binary patch literal 128 zcmebD)MDUZU|^78_{YG)zzAf4Faslmy#U07vMYdWCProkW+0saRKyHq!_>1u*-St= genut+At0RrloSB6xq<8&AX^Y>PK^>XgAiOV0H*i_f&c&j literal 0 HcmV?d00001 diff --git a/fixture/fixture3.arw b/fixture/fixture3.arw new file mode 100644 index 0000000000000000000000000000000000000000..b408d4ebb0fae3e9e9efd5b5a575dd7cadce8168 GIT binary patch literal 128 zcmXYoISzm@5X5E^u7*RQLC~a(sNfm=|0g^E;Y2A`_DY`TIW1u*-St= genut+At0RrloSB6xq<8&AX^Y>j)oyKgAiOV0HY%XJpcdz literal 0 HcmV?d00001 diff --git a/fixture/fixture4.arw b/fixture/fixture4.arw new file mode 100644 index 0000000000000000000000000000000000000000..b5ed4981c3a80b085b092caa8340e2674737ac16 GIT binary patch literal 128 zcmXYpF$#b%5Cr#(5fRal!a_l;MC^P<{{IJ`Ax=VyWrkz-Qo7Ykiu%;bupDQuu)`;7 lbikL)xQ893fDibH$J)=IR`X@MaNnx$_*FX%ori6Jr~P=q1bP4f literal 0 HcmV?d00001 diff --git a/index.js b/index.js index da729de2..7ca23a76 100644 --- a/index.js +++ b/index.js @@ -92,21 +92,31 @@ const fileType = input => { }; } - if (check([0x49, 0x49, 0x2A, 0x00, 0x10, 0xFB, 0x86, 0x01])) { + if (check([0x49, 0x49, 0x2A, 0x00]) && + (check([0x10, 0xFB, 0x86, 0x01], {offset: 4}) || + check([0x08, 0x00, 0x00, 0x00, 0x13, 0x00], {offset: 4}) || + check([0x08, 0x00, 0x00, 0x00, 0x12, 0x00], {offset: 4}))) { return { ext: 'arw', mime: 'image/x-sony-arw' }; } - if (check([0x49, 0x49, 0x2A, 0x00, 0x08, 0x00, 0x00, 0x00, 0x2D])) { + if ( + check([0x49, 0x49, 0x2A, 0x00, 0x08, 0x00, 0x00, 0x00]) && + (check([0x2D, 0x00, 0xFE, 0x00], {offset: 8}) || + check([0x27, 0x00, 0xFE, 0x00], {offset: 8})) + ) { return { ext: 'dng', mime: 'image/x-adobe-dng' }; } - if (check([0x49, 0x49, 0x2A, 0x00, 0x30, 0x3D, 0x72, 0x01, 0x1C])) { + if ( + check([0x49, 0x49, 0x2A, 0x00]) && + check([0x1C, 0x00, 0xFE, 0x00], {offset: 8}) + ) { return { ext: 'nef', mime: 'image/x-nikon-nef' diff --git a/test.js b/test.js index b797058b..c8274bea 100644 --- a/test.js +++ b/test.js @@ -122,6 +122,20 @@ const types = [ // Define an entry here only if the fixture has a different // name than `fixture` or if you want multiple fixtures const names = { + arw: [ + 'fixture', + 'fixture2', + 'fixture3', + 'fixture4' + ], + dng: [ + 'fixture', + 'fixture2' + ], + nef: [ + 'fixture', + 'fixture2' + ], '3gp': [ 'fixture', 'fixture2' From 625700978d39dbc42848b63dbb5240df3b01932a Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Thu, 13 Jun 2019 00:46:26 +0700 Subject: [PATCH 2/2] Update index.js --- index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 7ca23a76..880a3d2b 100644 --- a/index.js +++ b/index.js @@ -92,10 +92,12 @@ const fileType = input => { }; } - if (check([0x49, 0x49, 0x2A, 0x00]) && + if ( + check([0x49, 0x49, 0x2A, 0x00]) && (check([0x10, 0xFB, 0x86, 0x01], {offset: 4}) || check([0x08, 0x00, 0x00, 0x00, 0x13, 0x00], {offset: 4}) || - check([0x08, 0x00, 0x00, 0x00, 0x12, 0x00], {offset: 4}))) { + check([0x08, 0x00, 0x00, 0x00, 0x12, 0x00], {offset: 4})) + ) { return { ext: 'arw', mime: 'image/x-sony-arw'