[]previous and next page

file

A file answer: the bytes (or a Blob) with the headers a download needs, and the conditional and range requests answered from the request.

A file answer: the bytes (or a Blob) with the headers a download needs, and the conditional and range requests answered from the request. The file is read by the caller (a platform-neutral helper does not read paths); on Node the static file server already serves public/ with the same rules.

Import#

ts
import { file } from "@shadow-js/dusk/server";

Signature#

ts
function file(
  source: Uint8Array<ArrayBuffer> | ArrayBuffer | Blob,
  options: FileOptions = {},
): Response

Parameters#

Name Description
source The bytes or a Blob.
options The name, media type, validators and the request.

Returns#

The response: 200, 206, 304 or 416.

Throws#

  • TypeError when the filename holds CR or LF.

Examples#

ts
export const GET = async ({ request }) =>
  file(await readReport(), { request, filename: "report 2026.pdf", type: "application/pdf", etag: '"r1"' });