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 callsstream(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
@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
Properties
body
readonlybody:RangeBody
Defined in: src/range-file-response.ts:66
The range-capable body (bytes, a stream source, or a disk path).
contentType
readonlycontentType:string|undefined
Defined in: src/range-file-response.ts:68
Content-Type for the response, if set.
cookies
readonlycookies:ResponseCookie[] |undefined
Defined in: src/response.ts:63
Cookies to set (each its own Set-Cookie), if any.
Inherited from
disposition
readonlydisposition:"inline"|"attachment"|undefined
Defined in: src/range-file-response.ts:72
Content-Disposition type ('inline'/'attachment'), if set.
filename
readonlyfilename:string|undefined
Defined in: src/range-file-response.ts:70
Download filename for Content-Disposition, if set.
headers
readonlyheaders:Record<string,HeaderValue> |undefined
Defined in: src/response.ts:61
Extra response headers, if set.
Inherited from
status
readonlystatus:number|undefined
Defined in: src/response.ts:59
Explicit HTTP status, if set.
Inherited from
Methods
fromPath()
staticfromPath(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
