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

These image types aren't optimized but we can still detect them to
bypass optimization earlier.
This commit is contained in:
Steven 2024-06-23 04:04:46 -04:00 committed by GitHub
parent f9ea3a89f1
commit f5d616b77e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 16 additions and 0 deletions

View file

@ -32,6 +32,8 @@ const JPEG = 'image/jpeg'
const GIF = 'image/gif'
const SVG = 'image/svg+xml'
const ICO = 'image/x-icon'
const TIFF = 'image/tiff'
const BMP = 'image/bmp'
const CACHE_VERSION = 3
const ANIMATABLE_TYPES = [WEBP, PNG, GIF]
const VECTOR_TYPES = [SVG]
@ -158,6 +160,12 @@ export function detectContentType(buffer: Buffer) {
if ([0x00, 0x00, 0x01, 0x00].every((b, i) => buffer[i] === b)) {
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
}

View file

@ -34,4 +34,12 @@ describe('detectContentType', () => {
const buffer = await getImage('./images/test.ico')
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')
})
})

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.