Commit e4816285 authored by nagayama15's avatar nagayama15

Stream wasm with watermarks

parent ae8f9d61
import * as util from "util";
import * as childProcess from "child_process";
import * as fs from "fs"; import * as fs from "fs";
import * as express from "express"; import * as express from "express";
const port = 3000; const port = 3000;
const watermarker = `${__dirname}/../../build/src/kyut`;
const app = express(); const app = express();
...@@ -9,11 +12,19 @@ const server = app.listen(port, () => { ...@@ -9,11 +12,19 @@ const server = app.listen(port, () => {
console.log(`server listening at port ${port}`); console.log(`server listening at port ${port}`);
}); });
app.get("/wasm/add.wasm", (req: express.Request, res: express.Response) => { app.get(
const binary = fs.readFileSync(`${__dirname}/../wasm/add.wasm`); "/wasm/add.wasm",
async (req: express.Request, res: express.Response) => {
const path = `${__dirname}/../wasm/add.wasm`;
const watermark = req.query.v || "";
res.writeHead(200, { "Content-Type": "application/wasm" }); res.writeHead(200, { "Content-Type": "application/wasm" });
res.end(binary);
}); console.time("kyut");
const process = childProcess.spawn(watermarker, [path, watermark, "-"]);
process.stdout.pipe(res);
res.on("finish", () => console.timeEnd("kyut"));
}
);
app.use(express.static(`${__dirname}/../static`)); app.use(express.static(`${__dirname}/../static`));
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment