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

Function fileWebResponse

packages/platform/deno/src/DenoHttpPlatform.ts:70–97  ·  view source on GitHub ↗
(file, status, statusText, headers, options)

Source from the content-addressed store, hash-verified

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)
73 const contentLength = options?.bytesToRead === undefined
74 ? available
75 : Math.min(available, Math.max(0, Number(options.bytesToRead)))
76 let body: typeof file | ReadableStream<Uint8Array> = file
77 if (contentLength === 0) {
78 body = new ReadableStream<Uint8Array>({
79 start(controller) {
80 controller.close()
81 }
82 })
83 } else if (offset > 0 || options?.bytesToRead !== undefined) {
84 body = (file.stream() as ReadableStream<Uint8Array>).pipeThrough(
85 new ByteSliceStream(offset, offset + contentLength - 1)
86 )
87 }
88 return Response.raw(body, {
89 headers: {
90 ...headers,
91 "content-type": file.type,
92 "content-length": contentLength.toString()
93 },
94 status,
95 statusText
96 })
97 }
98})
99
100/**

Callers

nothing calls this directly

Calls 4

rawMethod · 0.80
streamMethod · 0.65
toStringMethod · 0.65
NumberInterface · 0.50

Tested by

no test coverage detected