forked from external-repos/squoosh
Nits by Jake
This commit is contained in:
@@ -1,9 +1,8 @@
|
|||||||
import { canDecodeImage, createImageBitmapPolyfill } from '../../lib/util';
|
import { canDecodeImage, createImageBitmapPolyfill } from '../../lib/util';
|
||||||
|
|
||||||
export const name = 'Browser WebP Decoder';
|
export const name = 'Browser WebP Decoder';
|
||||||
export const supportedMimeTypes = ['image/webp'];
|
export async function decode(blob: Blob): Promise<ImageBitmap> {
|
||||||
export async function decode(file: File): Promise<ImageBitmap> {
|
return createImageBitmapPolyfill(blob);
|
||||||
return createImageBitmapPolyfill(file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// tslint:disable-next-line:max-line-length It’s a data URL. Whatcha gonna do?
|
// tslint:disable-next-line:max-line-length It’s a data URL. Whatcha gonna do?
|
||||||
@@ -13,6 +12,7 @@ export function isSupported(): Promise<boolean> {
|
|||||||
return canDecodeImage(webpFile);
|
return canDecodeImage(webpFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const supportedMimeTypes = ['image/webp'];
|
||||||
export function canHandleMimeType(mimeType: string): boolean {
|
export function canHandleMimeType(mimeType: string): boolean {
|
||||||
return supportedMimeTypes.includes(mimeType);
|
return supportedMimeTypes.includes(mimeType);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,9 @@ import { blobToArrayBuffer, imageDataToBitmap } from '../../lib/util';
|
|||||||
import DecoderWorker from './Decoder.worker';
|
import DecoderWorker from './Decoder.worker';
|
||||||
|
|
||||||
export const name = 'WASM WebP Decoder';
|
export const name = 'WASM WebP Decoder';
|
||||||
export const supportedMimeTypes = ['image/webp'];
|
export async function decode(blob: Blob): Promise<ImageBitmap> {
|
||||||
export async function decode(file: File): Promise<ImageBitmap> {
|
|
||||||
const decoder = await new DecoderWorker();
|
const decoder = await new DecoderWorker();
|
||||||
const imageData = await decoder.decode(await blobToArrayBuffer(file));
|
const imageData = await decoder.decode(await blobToArrayBuffer(blob));
|
||||||
return imageDataToBitmap(imageData);
|
return imageDataToBitmap(imageData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -13,6 +12,7 @@ export async function isSupported(): Promise<boolean> {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const supportedMimeTypes = ['image/webp'];
|
||||||
export function canHandleMimeType(mimeType: string): boolean {
|
export function canHandleMimeType(mimeType: string): boolean {
|
||||||
return supportedMimeTypes.includes(mimeType);
|
return supportedMimeTypes.includes(mimeType);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ const magicNumberToMimeType = new Map<RegExp, string>([
|
|||||||
[/^RIFF....WEBPVP8 /, 'image/webp'],
|
[/^RIFF....WEBPVP8 /, 'image/webp'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
export async function sniffMimeType(blob: Blob): Promise<string | ''> {
|
export async function sniffMimeType(blob: Blob): Promise<string> {
|
||||||
const firstChunk = await blobToArrayBuffer(blob.slice(0, 16));
|
const firstChunk = await blobToArrayBuffer(blob.slice(0, 16));
|
||||||
const firstChunkString =
|
const firstChunkString =
|
||||||
Array.from(new Uint8Array(firstChunk))
|
Array.from(new Uint8Array(firstChunk))
|
||||||
|
|||||||
Reference in New Issue
Block a user