Skip to content

covenix / RangeFileResponse

Class: RangeFileResponse ​

Defined in: src/range-file-response.ts:64

A range-capable binary response. Where FileResponse sends a body whole, RangeFileResponse guarantees HTTP Range support: its body type is narrowed to sources covenix can serve a byte slice from, so a non-seekable stream simply isn't assignable. Returning one is the opt-in — covenix advertises Accept-Ranges: bytes and emits 206 Partial Content for a single satisfiable range, 416 Range Not Satisfiable for an unsatisfiable one, and a full 200 for a multi-range or malformed request.

  • Uint8Array — size is intrinsic; covenix slices the bytes.
  • { size, stream } — a range-aware source; covenix calls stream(range).
  • fromPath(path) — a disk file served via Express, which additionally honors conditional GET (ETag / If-Modified-Since / If-Range).

Shares the FileResponseOptions of FileResponse (contentType, filename, disposition, headers, status).

Example ​

ts
@Get('{id}/avatar/raw')
@ReturnsFile(200)
async avatar(@Param('id') id: string): Promise<RangeFileResponse> {
  const { bytes, contentType } = await store.get(id);
  return new RangeFileResponse(bytes, { contentType, disposition: 'inline' });
}

Extends ​

Constructors ​

Constructor ​

new RangeFileResponse(body, options?): RangeFileResponse

Defined in: src/range-file-response.ts:74

Parameters ​

body ​

Uint8Array<ArrayBufferLike> | RangeStreamBody

options? ​

FileResponseOptions = {}

Returns ​

RangeFileResponse

Overrides ​

ResponseBase.constructor

Properties ​

body ​

readonly body: RangeBody

Defined in: src/range-file-response.ts:66

The range-capable body (bytes, a stream source, or a disk path).


contentType ​

readonly contentType: string | undefined

Defined in: src/range-file-response.ts:68

Content-Type for the response, if set.


cookies ​

readonly cookies: ResponseCookie[] | undefined

Defined in: src/response.ts:63

Cookies to set (each its own Set-Cookie), if any.

Inherited from ​

ResponseBase.cookies


disposition ​

readonly disposition: "inline" | "attachment" | undefined

Defined in: src/range-file-response.ts:72

Content-Disposition type ('inline'/'attachment'), if set.


filename ​

readonly filename: string | undefined

Defined in: src/range-file-response.ts:70

Download filename for Content-Disposition, if set.


headers ​

readonly headers: Record<string, HeaderValue> | undefined

Defined in: src/response.ts:61

Extra response headers, if set.

Inherited from ​

ResponseBase.headers


status ​

readonly status: number | undefined

Defined in: src/response.ts:59

Explicit HTTP status, if set.

Inherited from ​

ResponseBase.status

Methods ​

fromPath() ​

static fromPath(path, options?): RangeFileResponse

Defined in: src/range-file-response.ts:90

Builds a range response backed by a file on disk, served via Express res.sendFile — so it honors Range and conditional GET (ETag / If-Modified-Since / If-Range) automatically.

Parameters ​

path ​

string

Path to the file (resolved to absolute before sending).

options? ​

FileResponseOptions = {}

Content type / disposition / headers / status overrides.

Returns ​

RangeFileResponse