Skip to content
Snippets Groups Projects
Commit 43b03e24 authored by Cheng Shao's avatar Cheng Shao :beach:
Browse files

wasm: add brotli compression for ghci browser mode

This commit adds brotli compression for wasm shared libraries for ghci
browser mode. With BROTLI_MIN_QUALITY, the overhead is negligible, and
it helps reducing amount of transferred data when the browser connects
to the server over a slow connection.

(cherry picked from commit 731217ce)
parent 4ea15010
No related branches found
No related tags found
No related merge requests found
......@@ -277,7 +277,7 @@ const isNode = Boolean(globalThis?.process?.versions?.node);
// factor out browser-only/node-only logic into different modules. For
// now, just make these global let bindings optionally initialized if
// isNode and be careful to not use them in browser-only logic.
let fs, http, path, require, stream, wasi, ws;
let fs, http, path, require, stream, util, wasi, ws, zlib;
if (isNode) {
require = (await import("node:module")).createRequire(import.meta.url);
......@@ -286,7 +286,9 @@ if (isNode) {
http = require("http");
path = require("path");
stream = require("stream");
util = require("util");
wasi = require("wasi");
zlib = require("zlib");
// Optional npm dependencies loaded via NODE_PATH
try {
......@@ -558,8 +560,17 @@ args.rpc.opened.then(() => main(args));
return;
}
res.setHeader("Content-Encoding", "br");
res.writeHead(200);
res.end(buf);
res.end(
await util.promisify(zlib.brotliCompress)(buf, {
params: {
[zlib.constants.BROTLI_PARAM_QUALITY]:
zlib.constants.BROTLI_MIN_QUALITY,
},
})
);
return;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment