| 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) |