@@ -167,12 +167,16 @@ const AVIF = "image/avif";
167
167
const WEBP = "image/webp" ;
168
168
const PNG = "image/png" ;
169
169
const JPEG = "image/jpeg" ;
170
+ const JXL = "image/jxl" ;
171
+ const JP2 = "image/jp2" ;
172
+ const HEIC = "image/heic" ;
170
173
const GIF = "image/gif" ;
171
174
const SVG = "image/svg+xml" ;
172
175
const ICO = "image/x-icon" ;
173
176
const ICNS = "image/x-icns" ;
174
177
const TIFF = "image/tiff" ;
175
178
const BMP = "image/bmp" ;
179
+ const PDF = "application/pdf" ;
176
180
177
181
/**
178
182
* Detects the content type by looking at the first few bytes of a file
@@ -216,6 +220,25 @@ export function detectContentType(buffer: Uint8Array) {
216
220
if ( [ 0x42 , 0x4d ] . every ( ( b , i ) => buffer [ i ] === b ) ) {
217
221
return BMP ;
218
222
}
223
+ if ( [ 0xff , 0x0a ] . every ( ( b , i ) => buffer [ i ] === b ) ) {
224
+ return JXL ;
225
+ }
226
+ if (
227
+ [ 0x00 , 0x00 , 0x00 , 0x0c , 0x4a , 0x58 , 0x4c , 0x20 , 0x0d , 0x0a , 0x87 , 0x0a ] . every ( ( b , i ) => buffer [ i ] === b )
228
+ ) {
229
+ return JXL ;
230
+ }
231
+ if ( [ 0 , 0 , 0 , 0 , 0x66 , 0x74 , 0x79 , 0x70 , 0x68 , 0x65 , 0x69 , 0x63 ] . every ( ( b , i ) => ! b || buffer [ i ] === b ) ) {
232
+ return HEIC ;
233
+ }
234
+ if ( [ 0x25 , 0x50 , 0x44 , 0x46 , 0x2d ] . every ( ( b , i ) => buffer [ i ] === b ) ) {
235
+ return PDF ;
236
+ }
237
+ if (
238
+ [ 0x00 , 0x00 , 0x00 , 0x0c , 0x6a , 0x50 , 0x20 , 0x20 , 0x0d , 0x0a , 0x87 , 0x0a ] . every ( ( b , i ) => buffer [ i ] === b )
239
+ ) {
240
+ return JP2 ;
241
+ }
219
242
}
220
243
221
244
declare global {
0 commit comments