Unverified Commit f5d616b7 authored by Steven's avatar Steven Committed by GitHub

chore: add detection for image more types (#67112)

These image types aren't optimized but we can still detect them to
bypass optimization earlier.
parent f9ea3a89
...@@ -32,6 +32,8 @@ const JPEG = 'image/jpeg' ...@@ -32,6 +32,8 @@ const JPEG = 'image/jpeg'
const GIF = 'image/gif' const GIF = 'image/gif'
const SVG = 'image/svg+xml' const SVG = 'image/svg+xml'
const ICO = 'image/x-icon' const ICO = 'image/x-icon'
const TIFF = 'image/tiff'
const BMP = 'image/bmp'
const CACHE_VERSION = 3 const CACHE_VERSION = 3
const ANIMATABLE_TYPES = [WEBP, PNG, GIF] const ANIMATABLE_TYPES = [WEBP, PNG, GIF]
const VECTOR_TYPES = [SVG] const VECTOR_TYPES = [SVG]
...@@ -158,6 +160,12 @@ export function detectContentType(buffer: Buffer) { ...@@ -158,6 +160,12 @@ export function detectContentType(buffer: Buffer) {
if ([0x00, 0x00, 0x01, 0x00].every((b, i) => buffer[i] === b)) { if ([0x00, 0x00, 0x01, 0x00].every((b, i) => buffer[i] === b)) {
return ICO return ICO
} }
if ([0x49, 0x49, 0x2a, 0x00].every((b, i) => buffer[i] === b)) {
return TIFF
}
if ([0x42, 0x4d].every((b, i) => buffer[i] === b)) {
return BMP
}
return null return null
} }
......
...@@ -34,4 +34,12 @@ describe('detectContentType', () => { ...@@ -34,4 +34,12 @@ describe('detectContentType', () => {
const buffer = await getImage('./images/test.ico') const buffer = await getImage('./images/test.ico')
expect(detectContentType(buffer)).toBe('image/x-icon') expect(detectContentType(buffer)).toBe('image/x-icon')
}) })
it('should return tiff', async () => {
const buffer = await getImage('./images/test.tiff')
expect(detectContentType(buffer)).toBe('image/tiff')
})
it('should return bmp', async () => {
const buffer = await getImage('./images/test.bmp')
expect(detectContentType(buffer)).toBe('image/bmp')
})
}) })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment