UNPKG

astro

Version:

Astro is a modern site builder with web best practices, performance, and DX front-of-mind.

23 lines (22 loc) • 665 B
import { typeHandlers } from "./types/index.js"; import { detector } from "./detector.js"; /** * Return size information based on an Uint8Array * * @param {Uint8Array} input * @returns {ISizeCalculationResult} */ export function lookup(input) { // detect the file type... don't rely on the extension const type = detector(input); if (typeof type !== "undefined") { // find an appropriate handler for this file type const size = typeHandlers.get(type).calculate(input); if (size !== undefined) { size.type = size.type ?? type; return size; } } // throw up, if we don't understand the file throw new TypeError("unsupported file type: " + type); }