import { type InclRange, type IntRange, type RangeSpec, RangesSpecifier, type SuffixRange } from "../deps.js"; import type { Range } from "../types.js"; import { RangeUnit, RequestedRangeNotSatisfiableResponse } from "../utils.js"; /** Context for bytes range. */ export interface BytesContext { /** Boundary delimiter computation function. */ readonly computeBoundary: ComputeBoundary; } /** Boundary delimiter computation API. */ export interface ComputeBoundary { (content: ArrayBuffer): string | Promise; } /** {@link Range} implementation for `bytes` range unit. * It support single and multiple range request. * @see https://www.rfc-editor.org/rfc/rfc9110#section-14.1.2 * * @example * ```ts * import { * BytesRange, * type IntRange, * type SuffixRange, * } from "https://deno.land/x/range_request_middleware@$VERSION/mod.ts"; * import { assertEquals } from "https://deno.land/std/testing/asserts.ts"; * * const bytesRange = new BytesRange(); * const rangeUnit = "bytes"; * declare const initResponse: Response; * declare const rangeSet: [IntRange, SuffixRange]; * * const response = await bytesRange.respond(initResponse, { * rangeUnit, * rangeSet, * }); * * assertEquals(bytesRange.rangeUnit, rangeUnit); * assertEquals(response.status, 206); * assertEquals( * response.headers.get("content-type"), * "multipart/byteranges; boundary=", * ); * ``` */ export declare class BytesRange implements Range { #private; constructor(options?: Partial); rangeUnit: RangeUnit; respond(response: Response, context: RangesSpecifier): Response | Promise; } /** Create partial response from response. */ export declare function createPartialResponse(response: Response, context: RangesSpecifier & BytesContext): Promise; /** Whether the range spec is satisfiable or not. */ export declare function isSatisfiable(rangeSpec: IntRange | SuffixRange, contentLength: number): boolean; export declare function isSupportedRanceSpec(rangeSpec: RangeSpec): rangeSpec is IntRange | SuffixRange; /** Convert {@link RangeSpec} into {@link InclRange}. */ export declare function rangeSpec2InclRange(rangeSpec: IntRange | SuffixRange, completeLength: number): InclRange; export declare function digestSha1(content: ArrayBuffer): Promise;