MCPcopy
hub / github.com/Effect-TS/effect / fileResponse

Function fileResponse

packages/platform/src/internal/httpPlatform.ts:45–72  ·  view source on GitHub ↗
(path, options)

Source from the content-addressed store, hash-verified

43 return tag.of({
44 [TypeId]: TypeId,
45 fileResponse(path, options) {
46 return pipe(
47 Effect.bindTo(fs.stat(path), "info"),
48 Effect.bind("etag", ({ info }) => etagGen.fromFileInfo(info)),
49 Effect.map(({ etag, info }) => {
50 const start = Number(options?.offset ?? 0)
51 const end = options?.bytesToRead !== undefined ? start + Number(options.bytesToRead) : undefined
52 const headers = Headers.set(
53 options?.headers ? Headers.fromInput(options.headers) : Headers.empty,
54 "etag",
55 Etag.toString(etag)
56 )
57 if (info.mtime._tag === "Some") {
58 ;(headers as any)["last-modified"] = info.mtime.value.toUTCString()
59 }
60 const contentLength = end !== undefined ? end - start : Number(info.size) - start
61 return impl.fileResponse(
62 path,
63 options?.status ?? 200,
64 options?.statusText,
65 headers,
66 start,
67 end,
68 contentLength
69 )
70 })
71 )
72 },
73 fileWebResponse(file, options) {
74 return Effect.map(etagGen.fromFileWeb(file), (etag) => {
75 const headers = Headers.merge(

Callers

nothing calls this directly

Calls 7

NumberInterface · 0.85
statMethod · 0.80
pipeFunction · 0.70
mapMethod · 0.65
setMethod · 0.65
toStringMethod · 0.65
streamMethod · 0.45

Tested by

no test coverage detected