MCPcopy Create free account
hub / github.com/Effect-TS/effect / fileResponse

Function fileResponse

packages/platform/deno/src/DenoHttpPlatform.ts:45–69  ·  view source on GitHub ↗
(path, status, statusText, headers, start, end, contentLength)

Source from the content-addressed store, hash-verified

43 platform: "deno",
44 compression,
45 fileResponse(path, status, statusText, headers, start, end, contentLength) {
46 let body: ReadableStream<Uint8Array>
47 if (contentLength === 0) {
48 body = new ReadableStream<Uint8Array>({
49 start(controller) {
50 controller.close()
51 }
52 })
53 } else {
54 const file = Deno.openSync(path)
55 file.seekSync(start, Deno.SeekMode.Start)
56 body = end === undefined
57 ? file.readable
58 : file.readable.pipeThrough(new ByteSliceStream(0, contentLength - 1))
59 }
60 return Response.raw(body, {
61 headers: {
62 ...headers,
63 "content-type": headers["content-type"] ?? contentType(extname(path)) ?? "application/octet-stream",
64 "content-length": contentLength.toString()
65 },
66 status,
67 statusText
68 })
69 },
70 fileWebResponse(file, status, statusText, headers, options) {
71 const offset = Number(options?.offset ?? 0)
72 const available = Math.max(0, file.size - offset)

Callers

nothing calls this directly

Calls 3

extnameFunction · 0.85
rawMethod · 0.80
toStringMethod · 0.65

Tested by

no test coverage detected