Commit 4e9105a6 authored by nagayama15's avatar nagayama15

Merge branch 'watermark-server' into 'master'

Watermark server

See merge request !7
parents d0443f96 e4816285
/build/ /build/
/.vscode/ /.vscode/
node_modules/
dist/
/build/ /build/
/.vscode/ /.vscode/
node_modules/
dist/
This diff is collapsed.
{
"name": "wasm-watermark-server",
"version": "1.0.0",
"description": "A WebAssembly Watermarking Server",
"main": "index.js",
"scripts": {
"start": "node dist/index.js",
"dev": "ts-node src/index.ts",
"build": "tsc"
},
"repository": {
"type": "git",
"url": "git@github.com/NagayamaRyoga/wasm-watermark.git"
},
"keywords": [
"wasm"
],
"author": "NagayamaRyoga",
"license": "GPL-3.0",
"dependencies": {
"express": "^4.17.1"
},
"devDependencies": {
"@types/express": "^4.16.1",
"ts-node": "^8.2.0",
"typescript": "^3.4.5"
}
}
import * as util from "util";
import * as childProcess from "child_process";
import * as fs from "fs";
import * as express from "express";
const port = 3000;
const watermarker = `${__dirname}/../../build/src/kyut`;
const app = express();
const server = app.listen(port, () => {
console.log(`server listening at port ${port}`);
});
app.get(
"/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" });
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`));
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Watermark Server</title>
</head>
<body>
<div id="root">
<h1>Watermark Server</h1>
<p>add2(42, 88) = {{ result1 }}</p>
<p>add3(42, 88, 64) = {{ result2 }}</p>
</div>
<script src="https://unpkg.com/vue"></script>
<script>
(async () => {
// Import wasm module
const wasm = await WebAssembly.instantiateStreaming(
fetch("wasm/add.wasm")
);
const { add2, add3 } = wasm.instance.exports;
// Mount vue
const data = {
result1: add2(42, 88),
result2: add3(42, 88, 64)
};
const app = new Vue({
el: "#root",
data
});
})();
</script>
</body>
</html>
{
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"outDir": "dist",
"sourceMap": true
},
"include": ["src/**/*"],
"exclude": ["node_modules"]
}
...@@ -15,14 +15,22 @@ int main(int argc, char *argv[]) { ...@@ -15,14 +15,22 @@ int main(int argc, char *argv[]) {
return 1; return 1;
} }
const std::string inputFile = argv[1];
const std::string watermark = argv[2];
const std::string outputFile = argv[3];
wasm::Module module; wasm::Module module;
wasm::ModuleReader{}.read(argv[1], module); wasm::ModuleReader{}.read(inputFile, module);
const auto stream = kyut::CircularBitStream::from_string(argv[2]); const auto stream = kyut::CircularBitStream::from_string(watermark);
kyut::pass::embedWatermarkOperandSwapping(module, *stream); kyut::pass::embedWatermarkOperandSwapping(module, *stream);
wasm::ModuleWriter{}.write(module, argv[3]); if (outputFile == "-") {
wasm::ModuleWriter{}.writeBinary(module, "");
} else {
wasm::ModuleWriter{}.write(module, outputFile);
}
} catch (wasm::ParseException &e) { } catch (wasm::ParseException &e) {
fmt::print(std::cerr, "parse error\n"); fmt::print(std::cerr, "parse error\n");
e.dump(std::cerr); e.dump(std::cerr);
......
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