// FIM - Fast Image Manipulation Library for Javascript // Copyright (c) Leo C. Singleton IV // See LICENSE in the project root for license information. import { FimError, FimErrorCode } from '@leosingleton/fim'; /** * Helper function to download a binary file * @param url URL of the file to download * @returns File contents, as a `Uint8Array` */ export async function fileReaderAsync(url: string): Promise { const fetchResponse = await fetch(url); if (!fetchResponse.ok) { throw new FimError(FimErrorCode.FetchError, `${url}: ${fetchResponse.status} ${fetchResponse.statusText}`); } const data = await fetchResponse.arrayBuffer(); return new Uint8Array(data); }