/** * Utilities for `fetch` when using range requests. * It also allows you to handle errors easier * Copyright (c) 2025 James Prevett */ import * as cache from './cache.js'; /** * @internal */ export declare const resourcesCache: Map | undefined>; export type Issue = { tag: 'status'; response: Response; } | { tag: 'buffer'; response: Response; message: string; } | { tag: 'fetch' | 'size'; message: string; } | Error; export interface Options extends cache.Options { /** Optionally provide a function for logging warnings */ warn?(message: string): unknown; } export interface GetOptions extends Options { /** * When using range requests, * a HEAD request must normally be used to determine the full size of the resource. * This allows that request to be skipped */ size?: number; /** The start of the range */ start?: number; /** The end of the range */ end?: number; } /** * Make a GET request without worrying about ranges * @throws RequestError */ export declare function get(url: string, options: GetOptions, init?: RequestInit): Promise; /** * Synchronously gets a cached resource * Assumes you pass valid start and end when using ranges */ export declare function getCached(url: string, options: GetOptions): { data?: Uint8Array; missing: cache.Range[]; }; interface SetOptions extends Options { /** The offset we are updating at */ offset?: number; /** If a cache for the resource doesn't exist, this will be used as the full size */ size?: number; /** The method to use for the request */ method?: 'POST' | 'PUT'; } /** * Make a POST request to set (or create) data on the server and update the cache. * @throws RequestError */ export declare function set(url: string, data: Uint8Array, options: SetOptions, init?: RequestInit): Promise; /** * Make a DELETE request to remove the resource from the server and clear it from the cache. * @throws RequestError */ export declare function remove(url: string, options?: Options, init?: RequestInit): Promise; export {};