rsnext/packages/next/server/lib/squoosh/emscripten-utils.ts

35 lines
620 B
TypeScript
Raw Normal View History

import { fileURLToPath } from 'url'
export function pathify(path: string) {
if (path.startsWith('file://')) {
path = fileURLToPath(path)
}
return path
}
export function instantiateEmscriptenWasm(
factory: (args: {
locateFile: () => string
}) => {
decode?: (
buffer: Buffer | Uint8Array,
width: number,
height: number,
opts: any
) => Buffer
encode?: (
buffer: Buffer | Uint8Array,
width: number,
height: number,
opts: any
) => Buffer
},
path: string
) {
return factory({
locateFile() {
return pathify(path)
},
})
}