Sends files from disk with ETags and byte ranges, streamed a chunk at a time. The files and thumbnails routes call it, and lib/upload.ts for the other uploads.
f
serveFile(): Promise<boolean>
ctx: Context,
path: string,
unnamed 2: ServeFileOptions
Sends a file from disk with an ETag, answering 304 when the client already
has it, and single byte ranges when ranges is set. It returns false, having
sent nothing, when the file doesn't exist, and leaves the 404 to the caller.
I
ServeFileOptions
Passed to serveFile by its caller, which knows the file's type and how long it may be cached.
- cacheControl: string
- mime: string
-
ranges: boolean
Answers a single
Range: bytes=…with a 206. The files route sets it, so that audio and video can seek.
Usage
import * as mod from "api/lib/serve-file.ts";