forked from external-repos/squoosh
Use createImageBitmap as hailmary
This commit is contained in:
@@ -128,16 +128,18 @@ const magicNumberToMimeType = new Map<RegExp, string>([
|
||||
[/^RIFF....WEBPVP8 /, 'image/webp'],
|
||||
]);
|
||||
|
||||
export async function sniffMimeType(blob: Blob): Promise<string | undefined> {
|
||||
const firstChunk = await blobToArrayBuffer(blob.slice(0, 1024));
|
||||
const firstChunkString = Array.from(
|
||||
new Uint8Array(firstChunk)).map(v => String.fromCodePoint(v),
|
||||
).join('');
|
||||
export async function sniffMimeType(blob: Blob): Promise<string | ''> {
|
||||
const firstChunk = await blobToArrayBuffer(blob.slice(0, 16));
|
||||
const firstChunkString =
|
||||
Array.from(new Uint8Array(firstChunk))
|
||||
.map(v => String.fromCodePoint(v))
|
||||
.join('');
|
||||
for (const [detector, mimeType] of magicNumberToMimeType.entries()) {
|
||||
if (detector.test(firstChunkString)) {
|
||||
return mimeType;
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
export function createImageBitmapPolyfill(blob: Blob): Promise<ImageBitmap> {
|
||||
|
||||
Reference in New Issue
Block a user