@@ -65,6 +65,7 @@ describe('FileTypeDetector', () => {
6565 } ) ;
6666
6767 it ( 'should detect MP4 files with offset' , async ( ) => {
68+ // ftyp + "isom" brand = generic MP4
6869 const mp4Buffer = Buffer . from ( [
6970 0x00 , 0x00 , 0x00 , 0x20 , 0x66 , 0x74 , 0x79 , 0x70 ,
7071 0x69 , 0x73 , 0x6F , 0x6D , 0x00 , 0x00 , 0x02 , 0x00
@@ -77,6 +78,34 @@ describe('FileTypeDetector', () => {
7778 expect ( result ?. extensions ) . toContain ( 'mp4' ) ;
7879 } ) ;
7980
81+ it ( 'should detect HEIC files (not misidentify as MP4)' , async ( ) => {
82+ // ftyp + "heic" brand = HEIC image
83+ const heicBuffer = Buffer . from ( [
84+ 0x00 , 0x00 , 0x00 , 0x20 , 0x66 , 0x74 , 0x79 , 0x70 ,
85+ 0x68 , 0x65 , 0x69 , 0x63 , 0x00 , 0x00 , 0x00 , 0x00
86+ ] ) ;
87+
88+ const result = await detector . detectFromBuffer ( heicBuffer ) ;
89+ expect ( result ) . toBeDefined ( ) ;
90+ expect ( result ?. name ) . toBe ( 'heic' ) ;
91+ expect ( result ?. mimeType ) . toBe ( 'image/heic' ) ;
92+ expect ( result ?. extensions ) . toContain ( 'heic' ) ;
93+ } ) ;
94+
95+ it ( 'should detect HEIF files (not misidentify as MP4)' , async ( ) => {
96+ // ftyp + "mif1" brand = HEIF image
97+ const heifBuffer = Buffer . from ( [
98+ 0x00 , 0x00 , 0x00 , 0x20 , 0x66 , 0x74 , 0x79 , 0x70 ,
99+ 0x6D , 0x69 , 0x66 , 0x31 , 0x00 , 0x00 , 0x00 , 0x00
100+ ] ) ;
101+
102+ const result = await detector . detectFromBuffer ( heifBuffer ) ;
103+ expect ( result ) . toBeDefined ( ) ;
104+ expect ( result ?. name ) . toBe ( 'heif' ) ;
105+ expect ( result ?. mimeType ) . toBe ( 'image/heif' ) ;
106+ expect ( result ?. extensions ) . toContain ( 'heif' ) ;
107+ } ) ;
108+
80109 it ( 'should detect UTF-8 BOM' , async ( ) => {
81110 const utf8Buffer = Buffer . from ( [
82111 0xEF , 0xBB , 0xBF , 0x48 , 0x65 , 0x6C , 0x6C , 0x6F
0 commit comments